-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathUIToggledObjects.cs
66 lines (59 loc) · 1.08 KB
/
UIToggledObjects.cs
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
using System.Collections.Generic;
using UnityEngine;
[AddComponentMenu("NGUI/Interaction/Toggled Objects")]
public class UIToggledObjects : MonoBehaviour
{
public List<GameObject> activate;
public List<GameObject> deactivate;
[HideInInspector]
[SerializeField]
private GameObject target;
[HideInInspector]
[SerializeField]
private bool inverse;
private void Awake()
{
if (target != null)
{
if (activate.Count == 0 && deactivate.Count == 0)
{
if (inverse)
{
deactivate.Add(target);
}
else
{
activate.Add(target);
}
}
else
{
target = null;
}
}
UIToggle component = GetComponent<UIToggle>();
EventDelegate.Add(component.onChange, Toggle);
}
public void Toggle()
{
bool value = UIToggle.current.value;
if (base.enabled)
{
for (int i = 0; i < activate.Count; i++)
{
Set(activate[i], value);
}
for (int j = 0; j < deactivate.Count; j++)
{
Set(deactivate[j], !value);
}
}
}
private void Set(GameObject go, bool state)
{
if (go != null)
{
NGUITools.SetActive(go, state);
}
}
}