diff --git a/Class Patches/BGControllerPatch.cs b/Class Patches/BGControllerPatch.cs index db45e77..30f6604 100644 --- a/Class Patches/BGControllerPatch.cs +++ b/Class Patches/BGControllerPatch.cs @@ -2,6 +2,7 @@ using HarmonyLib; using TrombLoader.Helpers; using UnityEngine; +using UnityEngine.Video; namespace TrombLoader.Class_Patches { @@ -32,8 +33,18 @@ static void Postfix(BGController __instance) { if (File.Exists(backgroundPath)) { - // do nothing // probably change the above to have a proper confirmation it worked at some point + + foreach (var videoPlayer in __instance.bgplane.transform.parent.parent.GetComponentsInChildren()) + { + if (videoPlayer.playOnAwake && videoPlayer.gameObject.activeInHierarchy) + { + videoPlayer.enabled = true; + videoPlayer.playOnAwake = false; + videoPlayer.Pause(); + videoPlayer.PlayVideoDelayed(2400); + } + } } else { diff --git a/Class Patches/TromboneChampExtensions.cs b/Class Patches/TromboneChampExtensions.cs index 1bc2fdf..e4736ec 100644 --- a/Class Patches/TromboneChampExtensions.cs +++ b/Class Patches/TromboneChampExtensions.cs @@ -1,4 +1,6 @@ -using UnityEngine; +using System; +using System.Threading.Tasks; +using UnityEngine; using UnityEngine.UI; using UnityEngine.Video; @@ -40,18 +42,31 @@ public static void SetBasicBackground(this BGController bgController, Sprite bg) } + public static async void PlayVideoDelayed(this VideoPlayer videoPlayer, int delay = 2500) + { + await Task.Delay(delay); + + videoPlayer?.Play(); + } + public static void SetVideoBackground(this BGController bgController, string url) { + DisableLayer(bgController.bgplane, true); + var planeObject = bgController.bgplane.transform.GetChild(0); var videoPlayer = planeObject.GetComponent() ?? planeObject.gameObject.AddComponent(); videoPlayer.url = url; videoPlayer.isLooping = true; - videoPlayer.playOnAwake = true; + videoPlayer.playOnAwake = false; + videoPlayer.skipOnDrop = true; + videoPlayer.renderMode = VideoRenderMode.CameraNearPlane; + videoPlayer.targetCamera = bgController.transform.parent.GetChild(1).GetComponent(); - videoPlayer.renderMode = VideoRenderMode.MaterialOverride; + videoPlayer.enabled = true; - DisableLayer(bgController.bgplane, true); + videoPlayer.Pause(); + videoPlayer.PlayVideoDelayed(); } public static void DisableLayer(GameObject obj, bool enable = false)