-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMultiUIToggleManager.cs
68 lines (64 loc) · 2.34 KB
/
MultiUIToggleManager.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
67
68
using UdonSharp;
using UnityEngine;
using UnityEngine.UI;
using VRC.Udon;
namespace UwUtils
{
namespace UwUtils
{
[AddComponentMenu("UwUtils/Multi UI Toggle Manager")]
[UdonBehaviourSyncMode(BehaviourSyncMode.None)]
public class MultiUIToggleManager : UdonSharpBehaviour
{
[Space]
public bool DefaultToggleValue = true;
[Space]
[SerializeField] private Toggle[] TargetToggles;
[Header("Target behaviors to send an event on value change to")]
[Space]
[SerializeField] private UdonBehaviour[] TargetBehaviorUpdate;
[SerializeField] private string eventName = "_interact";
[Space]
[SerializeField] private bool enableLogging = true;
void Start()
{
if (TargetToggles == null) return;
foreach (Toggle s in TargetToggles)
{
if (!s) continue;
s.SetIsOnWithoutNotify(DefaultToggleValue);
}
}
public override void Interact() => _ToggleChange();
private void _ToggleChange()
{
if (enableLogging) Debug.Log("[Reava_/UwUtils/ToggleHub.cs]: Change detected, updating values from: " + gameObject.name + "", gameObject);
if (TargetToggles == null) return;
bool found = false;
Toggle tempToggle = null;
foreach (Toggle s in TargetToggles)
{
if (!s) continue;
if (found) s.SetIsOnWithoutNotify(DefaultToggleValue);
if (s.isOn != DefaultToggleValue)
{
DefaultToggleValue = s.isOn;
tempToggle = s;
found = true;
}
}
foreach (Toggle s in TargetToggles)
{
if (!s) continue;
s.SetIsOnWithoutNotify(DefaultToggleValue);
if (s == tempToggle) break;
}
foreach (UdonBehaviour target in TargetBehaviorUpdate)
{
if (!target) continue;
target.SendCustomEvent(eventName);
}
}
}
}
}