84 lines
2.1 KiB
C#
84 lines
2.1 KiB
C#
|
|
using UdonSharp;
|
|
using UnityEngine;
|
|
using VRC.SDK3.UdonNetworkCalling;
|
|
using VRC.SDKBase;
|
|
using VRC.Udon.Common.Interfaces;
|
|
|
|
|
|
public enum IndicationStatus
|
|
{
|
|
Idle,
|
|
Loading,
|
|
LoadSuccess,
|
|
LoadFailure,
|
|
Playing
|
|
}
|
|
|
|
[UdonBehaviourSyncMode(BehaviourSyncMode.Manual)]
|
|
public class VideoLoadIndicator : UdonSharpBehaviour
|
|
{
|
|
[UdonSynced, FieldChangeCallback(nameof(Owner))] private string _Owner = null;
|
|
[UdonSynced, FieldChangeCallback(nameof(IndicateStatus))] private IndicationStatus _IndicateStatus = IndicationStatus.Idle;
|
|
|
|
[SerializeField] private MeshRenderer _IndicatorMesh;
|
|
|
|
private readonly Color _IdleColour = Color.black;
|
|
private readonly Color _LoadingColour = new Color(0.784313725f, 0.784313725f, 0.0f);
|
|
private readonly Color _LoadSuccessColour = new Color(0.0f, 0.784313725f, 0.0f);
|
|
private readonly Color _LoadFailureColour = new Color(0.784313725f, 0.0f, 0.0f);
|
|
private readonly Color _PlayingColour = new Color(0.0f, 0.784313725f, 0.784313725f);
|
|
|
|
|
|
void Start()
|
|
{
|
|
Owner = Networking.LocalPlayer.displayName;
|
|
}
|
|
|
|
public override void OnOwnershipTransferred(VRCPlayerApi Player)
|
|
{
|
|
Owner = Player.displayName;
|
|
base.OnOwnershipTransferred(Player);
|
|
}
|
|
|
|
public string GetOwner()
|
|
{
|
|
return Owner;
|
|
}
|
|
|
|
|
|
private void SwapIndicatorStatusColour(IndicationStatus NewStatus)
|
|
{
|
|
switch (NewStatus)
|
|
{
|
|
case IndicationStatus.Idle: _IndicatorMesh.material.SetColor("_Color", _IdleColour); break;
|
|
case IndicationStatus.Loading: _IndicatorMesh.material.SetColor("_Color", _LoadingColour); break;
|
|
case IndicationStatus.LoadSuccess: _IndicatorMesh.material.SetColor("_Color", _LoadSuccessColour); break;
|
|
case IndicationStatus.LoadFailure: _IndicatorMesh.material.SetColor("_Color", _LoadFailureColour); break;
|
|
case IndicationStatus.Playing: _IndicatorMesh.material.SetColor("_Color", _PlayingColour); break;
|
|
}
|
|
RequestSerialization();
|
|
}
|
|
|
|
private string Owner
|
|
{
|
|
set
|
|
{
|
|
_Owner = value;
|
|
SwapIndicatorStatusColour(IndicationStatus.Idle);
|
|
}
|
|
get => _Owner;
|
|
}
|
|
|
|
|
|
public IndicationStatus IndicateStatus
|
|
{
|
|
set
|
|
{
|
|
_IndicateStatus = value;
|
|
SwapIndicatorStatusColour(_IndicateStatus);
|
|
}
|
|
get => _IndicateStatus;
|
|
}
|
|
}
|