From 3b5b57414c0eb980a75132434b39931855772a54 Mon Sep 17 00:00:00 2001 From: ManlyMarco Date: Thu, 7 Jan 2021 15:35:01 +0100 Subject: [PATCH] Fix not working after reentering a h scene --- src/RealPOV.Koikatu/RealPOV.cs | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/RealPOV.Koikatu/RealPOV.cs b/src/RealPOV.Koikatu/RealPOV.cs index 6f32fe5..910a922 100644 --- a/src/RealPOV.Koikatu/RealPOV.cs +++ b/src/RealPOV.Koikatu/RealPOV.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using UnityEngine; +using UnityEngine.SceneManagement; [assembly: System.Reflection.AssemblyFileVersion(RealPOV.Koikatu.RealPOV.Version)] @@ -24,10 +25,13 @@ protected override void Awake() { base.Awake(); Harmony.CreateAndPatchAll(GetType()); + + SceneManager.activeSceneChanged += (arg0, scene) => charaQueue = null; } internal override void EnablePOV() { + if(isStudio) { var selectedCharas = GuideObjectManager.Instance.selectObjectKey.Select(x => Studio.Studio.GetCtrlInfo(x) as OCIChar).Where(x => x != null).ToList(); @@ -38,18 +42,31 @@ internal override void EnablePOV() } else { - if(charaQueue == null) + void CreateQueue() { charaQueue = new Queue(); foreach (ChaControl chara in FindObjectsOfType()) charaQueue.Enqueue(chara); - currentChara = charaQueue.Dequeue(); - charaQueue.Enqueue(currentChara); + if (charaQueue.Count > 0) + { + currentChara = charaQueue.Dequeue(); + charaQueue.Enqueue(currentChara); + } + } + + currentChara = null; + if(charaQueue == null) + { + CreateQueue(); } else { - currentChara = charaQueue.Dequeue(); - charaQueue.Enqueue(currentChara); + while (charaQueue.Count > 0 && (currentChara = charaQueue.Dequeue()) == null) {} + + if (currentChara != null) + charaQueue.Enqueue(currentChara); + else + CreateQueue(); } }