|
|
@@ -1,6 +1,9 @@
|
|
|
using UdonSharp;
|
|
|
using UnityEngine;
|
|
|
+using VRC.SDK3.Components;
|
|
|
using VRC.SDKBase;
|
|
|
+using VRC.Udon;
|
|
|
+using VRC.Udon.Common.Interfaces;
|
|
|
|
|
|
[UdonBehaviourSyncMode(BehaviourSyncMode.Manual)]
|
|
|
[DisallowMultipleComponent]
|
|
|
@@ -28,6 +31,21 @@ public class LinkedObjectSystem : UdonSharpBehaviour
|
|
|
public GameObject audioObjectTrue;
|
|
|
public GameObject audioObjectFalse;
|
|
|
|
|
|
+ [Header("Script Links\n")]
|
|
|
+ [Tooltip("Udon scripts told when the output turns on or off")]
|
|
|
+ public UdonBehaviour[] outputBehaviours;
|
|
|
+ [Tooltip("For each script, the event called when the output turns on. Leave an entry empty for none")]
|
|
|
+ public string[] onEventNames;
|
|
|
+ [Tooltip("For each script, the event called when the output turns off. Leave an entry empty for none")]
|
|
|
+ public string[] offEventNames;
|
|
|
+ [Tooltip("Off: every player's client calls the events itself. On: only this object's owner calls them, as network " +
|
|
|
+ "events to everyone (players who join later don't get them, and event names can't start with _)")]
|
|
|
+ public bool networkEvents;
|
|
|
+
|
|
|
+ [Header("Station\n")]
|
|
|
+ [Tooltip("The player who turns this on by interacting, or who walks into the trigger, is seated here. They leave it themselves")]
|
|
|
+ public VRCStation station;
|
|
|
+
|
|
|
// PRIVATE VARS
|
|
|
|
|
|
// Interactions only happen on the interacting player's client, so their result is synced.
|
|
|
@@ -60,16 +78,20 @@ public class LinkedObjectSystem : UdonSharpBehaviour
|
|
|
{
|
|
|
if (interactionType == InteractionType.Permanent)
|
|
|
{
|
|
|
- if (!interactState) SetInteractState(true);
|
|
|
+ if (interactState) return;
|
|
|
+ SetInteractState(true);
|
|
|
+ SeatLocalPlayer();
|
|
|
}
|
|
|
else if (interactionType == InteractionType.Toggle)
|
|
|
{
|
|
|
SetInteractState(!interactState);
|
|
|
+ if (interactState) SeatLocalPlayer();
|
|
|
}
|
|
|
else if (interactionType == InteractionType.Temporary)
|
|
|
{
|
|
|
if (interactState) return;
|
|
|
SetInteractState(true);
|
|
|
+ SeatLocalPlayer();
|
|
|
SendCustomEventDelayedSeconds(nameof(DisableTemp), delayedInteractTime);
|
|
|
}
|
|
|
}
|
|
|
@@ -121,6 +143,7 @@ public class LinkedObjectSystem : UdonSharpBehaviour
|
|
|
playerCount++;
|
|
|
if (debugMode) Debug.Log("Linked Object System: players inside: " + playerCount.ToString());
|
|
|
UpdateOutput();
|
|
|
+ if (player.isLocal) SeatLocalPlayer();
|
|
|
}
|
|
|
|
|
|
public override void OnPlayerTriggerExit(VRCPlayerApi player)
|
|
|
@@ -245,6 +268,31 @@ public class LinkedObjectSystem : UdonSharpBehaviour
|
|
|
if (debugMode) Debug.Log("Linked Object System: GameObject set audio to " + state.ToString());
|
|
|
if (audioObjectTrue != null) audioObjectTrue.SetActive(state);
|
|
|
if (audioObjectFalse != null) audioObjectFalse.SetActive(!state);
|
|
|
+
|
|
|
+ SendEvents(state);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void SendEvents(bool state)
|
|
|
+ {
|
|
|
+ // Networked: the owner tells everyone, so the others mustn't send it again
|
|
|
+ if (networkEvents && !Networking.IsOwner(gameObject)) return;
|
|
|
+ string[] names = state ? onEventNames : offEventNames;
|
|
|
+ int count = Mathf.Min(outputBehaviours.Length, names.Length);
|
|
|
+ for (int i = 0; i < count; i++)
|
|
|
+ {
|
|
|
+ if (outputBehaviours[i] == null || string.IsNullOrEmpty(names[i])) continue;
|
|
|
+ if (debugMode) Debug.Log("Linked Object System: sending " + names[i] + (networkEvents ? " to everyone" : ""));
|
|
|
+ if (networkEvents) outputBehaviours[i].SendCustomNetworkEvent(NetworkEventTarget.All, names[i]);
|
|
|
+ else outputBehaviours[i].SendCustomEvent(names[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>Seats the local player in the station, if there is one: they turned this on, or walked into the trigger.</summary>
|
|
|
+ private void SeatLocalPlayer()
|
|
|
+ {
|
|
|
+ if (station == null) return;
|
|
|
+ if (debugMode) Debug.Log("Linked Object System: seating the local player");
|
|
|
+ station.UseStation(Networking.LocalPlayer);
|
|
|
}
|
|
|
}
|
|
|
|