-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMultiUISliderManager.cs
67 lines (63 loc) · 2.14 KB
/
MultiUISliderManager.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
using UdonSharp;
using UnityEngine;
using UnityEngine.UI;
using VRC.SDKBase;
using VRC.Udon;
using UwUtils;
namespace UwUtils
{
[AddComponentMenu("UwUtils/Multi UI Slider Manager")]
[UdonBehaviourSyncMode(BehaviourSyncMode.None)]
public class MultiUISliderManager : UdonSharpBehaviour
{
[Space]
public float DefaultSliderValue = 0.6f;
[Space]
[SerializeField] private Slider[] TargetSliders;
[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 (TargetSliders == null) return;
foreach (Slider s in TargetSliders)
{
if (!s) continue;
s.SetValueWithoutNotify(DefaultSliderValue);
}
}
public override void Interact() => _SliderChange();
private void _SliderChange()
{
if (enableLogging) Debug.Log("[Reava_/UwUtils/SliderHub.cs]: Change detected, updating values from: " + gameObject.name + "", gameObject);
if (TargetSliders == null) return;
bool found = false;
Slider tempSlider = null;
foreach (Slider s in TargetSliders)
{
if (!s) continue;
if (found) s.SetValueWithoutNotify(DefaultSliderValue);
if (s.value != DefaultSliderValue)
{
DefaultSliderValue = s.value;
tempSlider = s;
found = true;
}
}
foreach (Slider s in TargetSliders)
{
if (!s) continue;
s.SetValueWithoutNotify(DefaultSliderValue);
if (s == tempSlider) break;
}
foreach(UdonBehaviour target in TargetBehaviorUpdate)
{
if (!target) continue;
target.SendCustomEvent(eventName);
}
}
}
}