- CameraTimedSwitcher now supports single-loop camera switches.

- CameraTimedSwitcher now supports unique timings for each cut.
- CameraTimedSwitcher now executes callbacks correctly and consistently.
This commit is contained in:
2025-12-23 14:54:00 -05:00
parent 27abad7657
commit e035f26d8d
7 changed files with 558 additions and 224 deletions
@@ -44,7 +44,7 @@ MonoBehaviour:
Data:
- Name:
Entry: 12
Data: 8
Data: 10
- Name:
Entry: 7
Data:
@@ -188,7 +188,7 @@ MonoBehaviour:
Data: 12|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Single, mscorlib
Data: System.Single[], mscorlib
- Name:
Entry: 8
Data:
@@ -210,12 +210,72 @@ MonoBehaviour:
- Name: _fieldAttributes
Entry: 7
Data: 13|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 1
- Name:
Entry: 7
Data: 14|UnityEngine.SerializeField, UnityEngine.CoreModule
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: _Loop
- Name: $v
Entry: 7
Data: 15|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: _Loop
- Name: <UserType>k__BackingField
Entry: 7
Data: 16|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Boolean, mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 16
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: true
- Name: _fieldAttributes
Entry: 7
Data: 17|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 2
- Name:
Entry: 7
Data: 14|UnityEngine.SpaceAttribute, UnityEngine.CoreModule
Data: 18|UnityEngine.SpaceAttribute, UnityEngine.CoreModule
- Name: height
Entry: 4
Data: 8
@@ -224,7 +284,7 @@ MonoBehaviour:
Data:
- Name:
Entry: 7
Data: 15|UnityEngine.SerializeField, UnityEngine.CoreModule
Data: 19|UnityEngine.SerializeField, UnityEngine.CoreModule
- Name:
Entry: 8
Data:
@@ -248,13 +308,13 @@ MonoBehaviour:
Data: _LoopPoint
- Name: $v
Entry: 7
Data: 16|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 20|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: _LoopPoint
- Name: <UserType>k__BackingField
Entry: 7
Data: 17|System.RuntimeType, mscorlib
Data: 21|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Int32, mscorlib
@@ -263,7 +323,7 @@ MonoBehaviour:
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 17
Data: 21
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -278,19 +338,19 @@ MonoBehaviour:
Data: true
- Name: _fieldAttributes
Entry: 7
Data: 18|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 22|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 2
- Name:
Entry: 7
Data: 19|UnityEngine.SerializeField, UnityEngine.CoreModule
Data: 23|UnityEngine.SerializeField, UnityEngine.CoreModule
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data: 20|UnityEngine.TooltipAttribute, UnityEngine.CoreModule
Data: 24|UnityEngine.TooltipAttribute, UnityEngine.CoreModule
- Name: tooltip
Entry: 1
Data: Loop to this point in the camera sequence. Default is index 0 (the beginning)
@@ -317,13 +377,13 @@ MonoBehaviour:
Data: _FirstLoopCallbackObject
- Name: $v
Entry: 7
Data: 21|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 25|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: _FirstLoopCallbackObject
- Name: <UserType>k__BackingField
Entry: 7
Data: 22|System.RuntimeType, mscorlib
Data: 26|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: UdonSharp.UdonSharpBehaviour, UdonSharp.Runtime
@@ -347,13 +407,13 @@ MonoBehaviour:
Data: true
- Name: _fieldAttributes
Entry: 7
Data: 23|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 27|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 3
- Name:
Entry: 7
Data: 24|UnityEngine.SpaceAttribute, UnityEngine.CoreModule
Data: 28|UnityEngine.SpaceAttribute, UnityEngine.CoreModule
- Name: height
Entry: 4
Data: 8
@@ -362,13 +422,13 @@ MonoBehaviour:
Data:
- Name:
Entry: 7
Data: 25|UnityEngine.SerializeField, UnityEngine.CoreModule
Data: 29|UnityEngine.SerializeField, UnityEngine.CoreModule
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data: 26|UnityEngine.TooltipAttribute, UnityEngine.CoreModule
Data: 30|UnityEngine.TooltipAttribute, UnityEngine.CoreModule
- Name: tooltip
Entry: 1
Data: Set this to call a function on an UdonSharpBehaviour instead of looping
@@ -396,13 +456,13 @@ MonoBehaviour:
Data: _FirstLoopCallbackFunction
- Name: $v
Entry: 7
Data: 27|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 31|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: _FirstLoopCallbackFunction
- Name: <UserType>k__BackingField
Entry: 7
Data: 28|System.RuntimeType, mscorlib
Data: 32|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.String, mscorlib
@@ -411,7 +471,7 @@ MonoBehaviour:
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 28
Data: 32
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -426,13 +486,13 @@ MonoBehaviour:
Data: true
- Name: _fieldAttributes
Entry: 7
Data: 29|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 33|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 1
- Name:
Entry: 7
Data: 30|UnityEngine.SerializeField, UnityEngine.CoreModule
Data: 34|UnityEngine.SerializeField, UnityEngine.CoreModule
- Name:
Entry: 8
Data:
@@ -456,22 +516,16 @@ MonoBehaviour:
Data: _Active
- Name: $v
Entry: 7
Data: 31|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 35|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: _Active
- Name: <UserType>k__BackingField
Entry: 7
Data: 32|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Boolean, mscorlib
- Name:
Entry: 8
Data:
Entry: 9
Data: 16
- Name: <SystemType>k__BackingField
Entry: 9
Data: 32
Data: 16
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -486,19 +540,19 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 33|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 36|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 2
- Name:
Entry: 7
Data: 34|UdonSharp.UdonSyncedAttribute, UdonSharp.Runtime
Data: 37|UdonSharp.UdonSyncedAttribute, UdonSharp.Runtime
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data: 35|UdonSharp.FieldChangeCallbackAttribute, UdonSharp.Runtime
Data: 38|UdonSharp.FieldChangeCallbackAttribute, UdonSharp.Runtime
- Name:
Entry: 8
Data:
@@ -522,16 +576,16 @@ MonoBehaviour:
Data: _NextCameraIndex
- Name: $v
Entry: 7
Data: 36|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 39|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: _NextCameraIndex
- Name: <UserType>k__BackingField
Entry: 9
Data: 17
Data: 21
- Name: <SystemType>k__BackingField
Entry: 9
Data: 17
Data: 21
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -546,7 +600,55 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 37|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 40|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: _LoopedOnce
- Name: $v
Entry: 7
Data: 41|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: _LoopedOnce
- Name: <UserType>k__BackingField
Entry: 9
Data: 16
- Name: <SystemType>k__BackingField
Entry: 9
Data: 16
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 42|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -1,10 +1,6 @@
using CameraSystem;
using UdonSharp;
using UnityEngine;
using VRC.SDK3.UdonNetworkCalling;
using VRC.SDKBase;
using VRC.Udon;
[UdonBehaviourSyncMode(BehaviourSyncMode.Manual)]
@@ -12,8 +8,9 @@ public class CameraTimedSwitcher : UdonSharpBehaviour
{
[SerializeField] private CameraControllerBase _CameraController;
[SerializeField] private string[] _SwitchFunctions;
[SerializeField] private float[] _TimeBetweenCuts = { 5.0f };
[Space]
[SerializeField] private float _TimeBetweenCuts = 5.0f;
[SerializeField] private bool _Loop = true;
[SerializeField, Tooltip("Loop to this point in the camera sequence. Default is index 0 (the beginning)")]
private int _LoopPoint = 0;
[Space]
@@ -24,29 +21,46 @@ public class CameraTimedSwitcher : UdonSharpBehaviour
[UdonSynced, FieldChangeCallback(nameof(Activate))] private bool _Active = false;
private int _NextCameraIndex = 0;
private bool _LoopedOnce = false;
public void SwitchToNextCamera()
{
if (_Active)
{
_CameraController.SendCustomEvent(_SwitchFunctions[_NextCameraIndex]);
_NextCameraIndex = (_NextCameraIndex + 1) % _SwitchFunctions.Length;
if (_NextCameraIndex == 0)
int CurrentCameraIndex = _NextCameraIndex;
if (CurrentCameraIndex == _LoopPoint && _LoopedOnce)
{
if (_FirstLoopCallbackObject != null)
{
Activate = false;
_FirstLoopCallbackObject.SendCustomEvent(_FirstLoopCallbackFunction);
Activate = false;
return;
}
else
if (!_Loop)
{
_NextCameraIndex = _LoopPoint;
Activate = false;
return;
}
}
SendCustomEventDelayedSeconds(nameof(SwitchToNextCamera), _TimeBetweenCuts);
string Function = _SwitchFunctions[_NextCameraIndex];
if (Function != "")
{
_CameraController.SendCustomEvent(Function);
}
_NextCameraIndex = (_NextCameraIndex + 1) % _SwitchFunctions.Length;
if (_NextCameraIndex == 0)
{
_LoopedOnce = true;
_NextCameraIndex = _LoopPoint;
}
SendCustomEventDelayedSeconds(nameof(SwitchToNextCamera),
_TimeBetweenCuts[Mathf.Min(CurrentCameraIndex, _TimeBetweenCuts.Length - 1)]);
}
}
@@ -59,6 +73,7 @@ public class CameraTimedSwitcher : UdonSharpBehaviour
{
_Active = value;
_NextCameraIndex = 0;
_LoopedOnce = false;
SwitchToNextCamera();
RequestSerialization();