Updating and loading videos on new case loads should now be much more reliable.

This commit is contained in:
2025-12-07 18:56:59 -05:00
parent 9feccb75c6
commit be83f3a0b2
5 changed files with 593 additions and 361 deletions
File diff suppressed because it is too large Load Diff
@@ -1,4 +1,5 @@
using Newtonsoft.Json.Linq;
using UdonSharp;
using UnityEngine;
using VRC.SDK3.Components.Video;
@@ -21,10 +22,10 @@ public enum ClueScreenType
[UdonBehaviourSyncMode(BehaviourSyncMode.Manual)]
public class CaseVideoSyncPlayer : UdonSharpBehaviour
{
[SerializeField] private CaseManager _CaseManager;
[SerializeField] private GameManagerRound1 _GameManager;
[SerializeField] private BaseVRCVideoPlayer _VideoPlayer;
/*[SerializeField]*/ private float _SyncFrequency = 5.0f;
//[SerializeField] private float _SyncFrequency = 5.0f;
[Header("Meshes")]
[SerializeField] private MeshRenderer _BlankScreenMesh;
@@ -47,9 +48,15 @@ public class CaseVideoSyncPlayer : UdonSharpBehaviour
[UdonSynced, FieldChangeCallback(nameof(PlayVideo))] private bool _VideoIsPlaying;
[UdonSynced] private VRCUrl[] _CaseMapsList = new VRCUrl[0];
private VRCUrl[] _CaseMapsListCache = new VRCUrl[0];
[UdonSynced] private int[] _CachedMapIndices = new int[0];
private int[] _LoadedMaps = new int[0];
[UdonSynced] private VRCUrl[] _CaseVideoList = new VRCUrl[0];
private VRCUrl[] _CaseVideoListCache = new VRCUrl[0];
private VRCImageDownloader _MapDownloader;
private Texture2D[] _MapImages = new Texture2D[0];
private IUdonEventReceiver _UdonEventReceiverThis;
@@ -80,37 +87,73 @@ public class CaseVideoSyncPlayer : UdonSharpBehaviour
public override void OnDeserialization(DeserializationResult Result)
{
if (_MapDownloadsInProgress)
{
return;
}
{ // Map syncing and redownloading
_ReloadMapList();
bool MapsNeedLoading = false;
if (_LoadedMaps.Length == _CachedMapIndices.Length)
{
for(int i = 0; i < _CachedMapIndices.Length; i++)
if (_MapDownloadsInProgress)
{
if (_CachedMapIndices[i] != _LoadedMaps[i])
return;
}
bool MapsNeedLoading = false;
if (_LoadedMaps.Length == _CachedMapIndices.Length)
{
for (int i = 0; i < _CachedMapIndices.Length; i++)
{
MapsNeedLoading = true;
break;
if (_CachedMapIndices[i] != _LoadedMaps[i])
{
MapsNeedLoading = true;
break;
}
}
}
}
else
{
MapsNeedLoading = true;
else
{
MapsNeedLoading = true;
}
if (MapsNeedLoading)
{
Debug.Log("[CaseVideoSyncPlayer] Redownloading old maps...");
QueueMapDownloads(_CachedMapIndices);
}
}
if (MapsNeedLoading)
{
Debug.Log("[CaseVideoSyncPlayer] Redownloading old maps...");
QueueMapDownloads(_CachedMapIndices);
{ // Video syncing and redownloading
_ReloadVideoList();
}
base.OnDeserialization(Result);
}
public void SetNewLists(VRCUrl[] Maps, VRCUrl[] Videos)
{
_CaseMapsList = Maps;
_ReloadMapList();
_CaseVideoList = Videos;
_ReloadVideoList();
RequestSerialization();
}
private void _ReloadMapList()
{
if (_IsUrlListDifferent(_CaseMapsList, _CaseMapsListCache))
{
_CaseMapsListCache = (VRCUrl[])_CaseMapsList.Clone();
}
}
private void _ReloadVideoList()
{
if (_IsUrlListDifferent(_CaseVideoList, _CaseVideoListCache))
{
_CaseVideoListCache = (VRCUrl[])_CaseVideoList.Clone();
_GameManager.TryIntroVideoLoad();
}
}
[NetworkCallable]
public void QueueMapDownloads(int[] MapIndices)
@@ -148,11 +191,11 @@ public class CaseVideoSyncPlayer : UdonSharpBehaviour
_MapDownloadIndex = 0;
LoadMapFromIndex(_CachedMapIndices[_MapDownloadIndex]);
}
_LoadedMaps = _CachedMapIndices;
_LoadedMaps = (int[])_CachedMapIndices.Clone();
}
private void LoadMapFromIndex(int MapIndex)
{
VRCUrl MapURL = _CaseManager.GetMap(MapIndex);
VRCUrl MapURL = _CaseMapsList[MapIndex];
TextureInfo AdditionalTextureInfo = new TextureInfo();
AdditionalTextureInfo.WrapModeU = TextureWrapMode.Clamp;
@@ -235,15 +278,26 @@ public class CaseVideoSyncPlayer : UdonSharpBehaviour
}
public void SetVideoIndexLocal(int Index)
{
_VideoIndex = Index;
_VideoLoadAttemptCounter = 0;
if (_VideoIndex >= 0)
{
_UseFallback = false;
_LoadVideo_Private();
}
}
private void _LoadVideo_Private()
{
TryLoadURL();
}
public void TryLoadURL()
{
if (VideoIndex >= 0 && VideoIndex < _CaseManager.GetVideoCount())
if (VideoIndex >= 0 && VideoIndex < _CaseVideoList.Length)
{
_VideoPlayer.LoadURL(_CaseManager.GetVideo(VideoIndex, _UseFallback));
_VideoPlayer.LoadURL(_CaseVideoList[VideoIndex]);
SetVideoLoadStatus(IndicationStatus.Loading);
}
else
@@ -280,8 +334,6 @@ public class CaseVideoSyncPlayer : UdonSharpBehaviour
public override void OnVideoReady()
{
Debug.Log("[CaseVideoSyncPlayer] Video is ready.");
if (_VideoIsPlaying)
{
_PlayVideo_Private();
@@ -309,8 +361,9 @@ public class CaseVideoSyncPlayer : UdonSharpBehaviour
Debug.LogError("[CaseVideoSyncPlayer] Error with video player.");
break;
case VideoError.RateLimited:
Debug.LogError("[CaseVideoSyncPlayer] Rate limited.");
break;
Debug.LogError("[CaseVideoSyncPlayer] Rate limited. Attempting another reload in 2 seconds...");
SendCustomEventDelayedSeconds(nameof(TryLoadURL), 2.1f);
return;
}
//if (_UseFallback)
@@ -371,39 +424,39 @@ public class CaseVideoSyncPlayer : UdonSharpBehaviour
public void SetVideoLoadStatus(IndicationStatus Status)
{
Debug.Log("[CaseVideoSyncPlayer] Checking video load indicators for " + Networking.LocalPlayer.displayName + "...");
//Debug.Log("[CaseVideoSyncPlayer] Checking video load indicators for " + Networking.LocalPlayer.displayName + "...");
foreach (VideoLoadIndicator Indicator in _VideoLoadIndicators)
{
if (Indicator.GetOwner() == Networking.LocalPlayer.displayName)
{
Debug.Log("[CaseVideoSyncPlayer] " + Indicator.GetOwner() + "'s video load indicator was found. Setting status to " + Status + "...");
//Debug.Log("[CaseVideoSyncPlayer] " + Indicator.GetOwner() + "'s video load indicator was found. Setting status to " + Status + "...");
Indicator.IndicateStatus = Status;
}
else
{
Debug.Log("[CaseVideoSyncPlayer] This one is owned by " + Indicator.GetOwner() + ". Not what we want.");
}
//else
//{
// Debug.Log("[CaseVideoSyncPlayer] This one is owned by " + Indicator.GetOwner() + ". Not what we want.");
//}
}
}
private void UpdateTimeAndOffset()
{
if (Networking.IsOwner(gameObject))
{
TimeAndOffset = new Vector2(_VideoPlayer.GetTime(), (float)Networking.GetServerTimeInSeconds());
//private void UpdateTimeAndOffset()
//{
// if (Networking.IsOwner(gameObject))
// {
// TimeAndOffset = new Vector2(_VideoPlayer.GetTime(), (float)Networking.GetServerTimeInSeconds());
if (_SyncFrequency > 0.0f)
{
SendCustomEventDelayedSeconds(nameof(UpdateTimeAndOffset), _SyncFrequency);
}
}
else
{
Resync();
}
// if (_SyncFrequency > 0.0f)
// {
// SendCustomEventDelayedSeconds(nameof(UpdateTimeAndOffset), _SyncFrequency);
// }
// }
// else
// {
// Resync();
// }
RequestSerialization();
}
// RequestSerialization();
//}
public void Resync()
{
@@ -419,7 +472,7 @@ public class CaseVideoSyncPlayer : UdonSharpBehaviour
}
private void SwapToScreen(ClueScreenType Screen)
private void _SwapToScreen(ClueScreenType Screen)
{
if (ShowScreen == Screen) return;
@@ -455,6 +508,26 @@ public class CaseVideoSyncPlayer : UdonSharpBehaviour
RequestSerialization();
}
private bool _IsUrlListDifferent(VRCUrl[] New, VRCUrl[] Cached)
{
if (New.Length == Cached.Length)
{
for (int i = 0; i < New.Length; i++)
{
if (New[i].ToString() != Cached[i].ToString())
{
return true;
}
}
}
else
{
return true;
}
return false;
}
public int SubMapIndex
{
@@ -470,7 +543,7 @@ public class CaseVideoSyncPlayer : UdonSharpBehaviour
{
set
{
SwapToScreen(value);
_SwapToScreen(value);
_ShowScreen = value;
}
get => _ShowScreen;
@@ -491,14 +564,11 @@ public class CaseVideoSyncPlayer : UdonSharpBehaviour
{
set
{
_VideoIndex = value;
_VideoLoadAttemptCounter = 0;
if (_VideoIndex >= 0)
if (_VideoIndex != value)
{
_UseFallback = false;
_LoadVideo_Private();
SetVideoIndexLocal(value);
RequestSerialization();
}
RequestSerialization();
}
get => _VideoIndex;
}
@@ -116,6 +116,8 @@ public class CaseManager : UdonSharpBehaviour
_CaseFileVideosFallback = CaseFile.FallbackVideoFiles;
_CaseFileClueImages = CaseFile.ClueImages;
_Round1Manager.SetNewVideoPlayerLists(_CaseFileMaps, _CaseFileVideos);
VRCStringDownloader.LoadUrl(_CaseFileCluesURL, (IUdonEventReceiver)this);
}
@@ -139,16 +139,20 @@ public class GameManagerRound1 : GameManagerBase
Interface.HeaderUI.text = _CaseManager.GetCaseTitle() + " has been loaded.";
Interface.CommentUI.text = _CaseManager.GetCaseDescription();
TryIntroVideoLoad();
_GameHasBegun = false;
}
public void SetNewVideoPlayerLists(VRCUrl[] Maps, VRCUrl[] Videos)
{
_VideoPlayer.SetNewLists(Maps, Videos);
}
public void TryIntroVideoLoad()
{
int IntroVideoIndex = _CaseManager.GetIntroVideo();
if (IntroVideoIndex >= 0)
{
_VideoPlayer.VideoIndex = IntroVideoIndex;
_VideoPlayer.SetVideoIndexLocal(IntroVideoIndex);
}
else
{