SwitchButtonCollor.cs
1.25 KB
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
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class SwitchButtonCollor : MonoBehaviour {
public Button thisButton;
public GameObject reference;
private Graphic thisButtonGraphic;
public bool isEnabled;
private static Color enabledColor = new Color(0.356F, 0.78F, 0.815F, 1F);
private static Color disabledColor = new Color(1F, 1F, 1F, 1F);
void Start ()
{
if (thisButton == null)
thisButton = (Button) gameObject.GetComponent<Button>();
thisButtonGraphic = thisButton.GetComponent<Graphic>();
if (reference == null)
updateColor();
else
switchColorByReference();
}
void OnEnable ()
{
if (thisButtonGraphic != null && reference != null)
switchColorByReference();
}
public void updateColor()
{
thisButtonGraphic.color = isEnabled ? enabledColor : disabledColor;
}
public void switchColor(bool isEnabled)
{
this.isEnabled = isEnabled;
updateColor();
}
public void switchCollor() {
switchColor( ! isEnabled);
}
public void switchColorByReference()
{
switchColorByReference(reference);
}
public void switchColorByReference(GameObject reference)
{
ColorChangeState state = reference.GetComponent<ColorChangeState>();
if (state != null) switchColor(state.getColorChangeState());
}
}