Skip to content

Commit

Permalink
Fix desynced video + overscan
Browse files Browse the repository at this point in the history
  • Loading branch information
legoandmars committed Oct 11, 2022
1 parent 05b1437 commit a2ed98a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
13 changes: 12 additions & 1 deletion Class Patches/BGControllerPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using HarmonyLib;
using TrombLoader.Helpers;
using UnityEngine;
using UnityEngine.Video;

namespace TrombLoader.Class_Patches
{
Expand Down Expand Up @@ -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<VideoPlayer>())
{
if (videoPlayer.playOnAwake && videoPlayer.gameObject.activeInHierarchy)
{
videoPlayer.enabled = true;
videoPlayer.playOnAwake = false;
videoPlayer.Pause();
videoPlayer.PlayVideoDelayed(2400);
}
}
}
else
{
Expand Down
23 changes: 19 additions & 4 deletions Class Patches/TromboneChampExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using UnityEngine;
using System;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Video;

Expand Down Expand Up @@ -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<VideoPlayer>() ?? planeObject.gameObject.AddComponent<VideoPlayer>();

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<Camera>();

videoPlayer.renderMode = VideoRenderMode.MaterialOverride;
videoPlayer.enabled = true;

DisableLayer(bgController.bgplane, true);
videoPlayer.Pause();
videoPlayer.PlayVideoDelayed();
}

public static void DisableLayer(GameObject obj, bool enable = false)
Expand Down

0 comments on commit a2ed98a

Please sign in to comment.