2025-12-20 23:19:19 -05:00

51 lines
1.0 KiB
C#

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;
[SerializeField] private float _TimeBetweenCuts = 5.0f;
[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;
SendCustomEventDelayedSeconds(nameof(SwitchToNextCamera), _TimeBetweenCuts);
}
}
public bool Activate
{
set
{
if (_Active != value)
{
_Active = value;
_NextCameraIndex = 0;
SwitchToNextCamera();
RequestSerialization();
}
}
get => _Active;
}
}