using System Collections using System Collections Generic using UnityE

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ResourceReserveView : MonoBehaviour {
public Text textValue;
public LocalGameModel gameModel;
public Config config;
public ResourceTypes.ResourceTypeId resourceType;
public Color normalColor;
public Color limitColor;
int oldValue = -1;
Vector3 oldScale;
IEnumerator restoreSizeCoroutine()
{
yield return new WaitForSeconds(0.2f);
textValue.transform.localScale = oldScale;
}
void updateValue() {
if (gameModel.resourceManager != null)
{
int amount = gameModel.resourceManager.getResource(resourceType).amount;
if (oldValue != amount && oldValue != -1)
{
StartCoroutine(restoreSizeCoroutine());
textValue.transform.localScale = textValue.transform.localScale * 1.2f;
}
oldValue = amount;
textValue.text = amount.ToString();
textValue.color = amount >= config.maxResourceAmount ? limitColor : normalColor;
}
}
void onPlayerRegistered() {
gameModel.resourceManager.resourceChangedEvent -= onResourceChanged;
gameModel.resourceManager.resourceChangedEvent += onResourceChanged;
updateValue();
}
void onResourceChanged() {
updateValue();
}
private void OnEnable()
{
oldScale = textValue.transform.localScale;
gameModel.playerRegisteredEvent -= onPlayerRegistered;
gameModel.playerRegisteredEvent += onPlayerRegistered;
if (gameModel.resourceManager != null) {
gameModel.resourceManager.resourceChangedEvent -= onResourceChanged;
gameModel.resourceManager.resourceChangedEvent += onResourceChanged;
}
}
private void OnDisable()
{
gameModel.playerRegisteredEvent -= onPlayerRegistered;
if (gameModel.resourceManager != null)
{
gameModel.resourceManager.resourceChangedEvent -= onResourceChanged;
}
}
}