-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TriggerZoneRelay.cs
69 lines (66 loc) · 2.43 KB
/
TriggerZoneRelay.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
using UnityEngine;
using VRC.SDKBase;
using UdonSharp;
using VRC.Udon;
namespace UwUtils
{
[AddComponentMenu("UwUtils/Trigger Zone Relay")]
[UdonBehaviourSyncMode(BehaviourSyncMode.None)]
public class TriggerZoneRelay : UdonSharpBehaviour
{
[Space]
[Header("Make your colliders Trigger & on the layer MirrorReflection")]
[SerializeField] private bool LocalPlayerOnly = true;
[Space]
[Header("Make sure your colliders are on the same gameObject as this script")]
[Space]
[SerializeField] private string eventNameOnExit = "_interact";
[SerializeField] private string eventNameOnEnter = "_interact";
[Space]
[Header("Event settings")]
[Space]
[SerializeField] private bool onEnter = true;
[SerializeField] private bool onExit = false;
[Space]
[SerializeField] private UdonSharpBehaviour[] eventTargets;
[Space]
[SerializeField] private bool enableLogging = true;
private bool valid = false;
void Start()
{
if (eventTargets != null)
{
valid = true;
}
else
{
valid = false;
Debug.LogError("[Reava_/UwUtils/TriggerZoneRelay.cs]: Setup is invalid, check your references for object '" + gameObject.name + "'", gameObject);
}
}
public override void OnPlayerTriggerExit(VRCPlayerApi player)
{
if (LocalPlayerOnly && player != Networking.LocalPlayer) return;
if (enableLogging) Debug.Log("[Reava_/UwUtils/TriggerZoneRelay.cs]: Player exit " + gameObject.name, gameObject);
if (valid && onExit)
{
foreach (UdonSharpBehaviour program in eventTargets)
{
program.SendCustomEvent(eventNameOnExit);
}
}
}
public override void OnPlayerTriggerEnter(VRCPlayerApi player)
{
if (LocalPlayerOnly && player != Networking.LocalPlayer) return;
if (enableLogging) Debug.Log("[Reava_/UwUtils/TriggerZoneRelay.cs]: Player entered " + gameObject.name, gameObject);
if (valid && onEnter)
{
foreach (UdonSharpBehaviour program in eventTargets)
{
program.SendCustomEvent(eventNameOnEnter);
}
}
}
}
}