-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathUIToggledComponents.cs
61 lines (55 loc) · 1.14 KB
/
UIToggledComponents.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
using System.Collections.Generic;
using UnityEngine;
[AddComponentMenu("NGUI/Interaction/Toggled Components")]
[ExecuteInEditMode]
[RequireComponent(typeof(UIToggle))]
public class UIToggledComponents : MonoBehaviour
{
public List<MonoBehaviour> activate;
public List<MonoBehaviour> deactivate;
[HideInInspector]
[SerializeField]
private MonoBehaviour 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()
{
if (base.enabled)
{
for (int i = 0; i < activate.Count; i++)
{
MonoBehaviour monoBehaviour = activate[i];
monoBehaviour.enabled = UIToggle.current.value;
}
for (int j = 0; j < deactivate.Count; j++)
{
MonoBehaviour monoBehaviour2 = deactivate[j];
monoBehaviour2.enabled = !UIToggle.current.value;
}
}
}
}