-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEventRelay.cs
82 lines (78 loc) · 2.56 KB
/
EventRelay.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using UdonSharp;
using UnityEngine;
using VRC.Udon;
namespace UwUtils
{
[AddComponentMenu("UwUtils/Event Relay")]
[UdonBehaviourSyncMode(BehaviourSyncMode.None)]
public class EventRelay : UdonSharpBehaviour
{
[Header("Send an event call to any behavior with conditions and/or delay")]
[SerializeField] private UdonBehaviour[] programRelay;
[SerializeField] private GameObject stateCheck;
private bool stateChecked;
[SerializeField] private string eventName = "_interact";
[SerializeField] private bool delayedAction;
[SerializeField] private float delay;
[Header("0 = Keep delay, 1 = No delay when object is off, 2 = No delay when object is on")]
[Range(0, 2)]
[SerializeField] private int function = 1;
private bool abort = false;
public void Start()
{
if (programRelay.Length == null)
{
abort = true;
SendCustomEventDelayedSeconds(nameof(_sendDebugError), 1f);
return;
}
}
public override void Interact()
{
if (abort) return;
stateChecked = stateCheck.activeSelf;
if (!delayedAction)
{
_relayAction();
}
else
{
if (function == 0)
{
SendCustomEventDelayedSeconds(nameof(_relayAction), delay);
}
else if (function == 1)
{
if (stateChecked)
{
SendCustomEventDelayedSeconds(nameof(_relayAction), delay);
}
else
{
_relayAction();
}
}
else if (function == 2)
{
if (!stateChecked)
{
SendCustomEventDelayedSeconds(nameof(_relayAction), delay);
}
else
{
_relayAction();
}
}
}
}
public void _relayAction()
{
if (abort) return;
foreach (UdonBehaviour program in programRelay)
{
program.SendCustomEvent(eventName);
}
}
public void _sendDebugError() => Debug.LogError("[Reava_/UwUtils/EventRelay.cs]::<color=red> No Target script found</color>. (" + gameObject + ")", gameObject);
}
}