using CameraSystem; using UdonSharp; using UnityEngine; using VRC.SDK3.UdonNetworkCalling; using VRC.SDKBase; using VRC.Udon; [UdonBehaviourSyncMode(BehaviourSyncMode.Manual)] public class CameraTimedSwitcher : UdonSharpBehaviour { [SerializeField] private CameraControllerBase _CameraController; [SerializeField] private string[] _SwitchFunctions; [Space] [SerializeField] private float _TimeBetweenCuts = 5.0f; [SerializeField, Tooltip("Loop to this point in the camera sequence. Default is index 0 (the beginning)")] private int _LoopPoint = 0; [Space] [SerializeField, Tooltip("Set this to call a function on an UdonSharpBehaviour instead of looping the camera sequence")] private UdonSharpBehaviour _FirstLoopCallbackObject = null; [SerializeField] private string _FirstLoopCallbackFunction = ""; [UdonSynced, FieldChangeCallback(nameof(Activate))] private bool _Active = false; private int _NextCameraIndex = 0; public void SwitchToNextCamera() { if (_Active) { _CameraController.SendCustomEvent(_SwitchFunctions[_NextCameraIndex]); _NextCameraIndex = (_NextCameraIndex + 1) % _SwitchFunctions.Length; if (_NextCameraIndex == 0) { if (_FirstLoopCallbackObject != null) { Activate = false; _FirstLoopCallbackObject.SendCustomEvent(_FirstLoopCallbackFunction); return; } else { _NextCameraIndex = _LoopPoint; } } SendCustomEventDelayedSeconds(nameof(SwitchToNextCamera), _TimeBetweenCuts); } } public bool Activate { set { if (_Active != value) { _Active = value; _NextCameraIndex = 0; SwitchToNextCamera(); RequestSerialization(); } } get => _Active; } }