not really sure

This commit is contained in:
NotAKidoS 2023-03-24 18:33:36 -05:00
parent 1acf58d161
commit 38445efae3
5 changed files with 77 additions and 83 deletions

View file

@ -1,50 +1,58 @@
using ABI_RC.Core.IO;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace NAK.Melons.BadAnimatorFix;
public static class BadAnimatorFixManager
{
public static List<BadAnimatorFix> badAnimatorFixes = new List<BadAnimatorFix>();
private static List<BadAnimatorFix> badAnimatorFixes = new List<BadAnimatorFix>();
private static int currentIndex = 0;
private static float checkInterval = 5f;
public static void Add(BadAnimatorFix bad)
{
if (!badAnimatorFixes.Contains(bad))
{
badAnimatorFixes.Add(bad);
}
}
public static void Remove(BadAnimatorFix bad)
{
if (badAnimatorFixes.Contains(bad))
{
badAnimatorFixes.Remove(bad);
}
public static void OnSceneInitialized(string sceneName)
{
// Get all the animators in the loaded world
var allAnimators = SceneManager.GetSceneByName(sceneName).GetRootGameObjects()
.SelectMany(x => x.GetComponentsInChildren<Animator>(true));
foreach (var animator in allAnimators)
{
// Ignore objects that have our "fix", this shouldn't be needed but eh
if (!animator.TryGetComponent<BadAnimatorFix>(out _))
{
animator.gameObject.AddComponent<BadAnimatorFix>();
}
}
}
// Runs every 5 seconds to see if an animator has played longer than PlayableTimeLimit
public static void CheckNextAnimator()
private static void CheckNextAnimator()
{
if (badAnimatorFixes.Count == 0) return;
if (currentIndex >= badAnimatorFixes.Count) currentIndex = 0;
currentIndex = (currentIndex + 1) % badAnimatorFixes.Count;
BadAnimatorFix currentAnimatorFix = badAnimatorFixes[currentIndex];
if (currentAnimatorFix.GetTime() > BadAnimatorFixMod.EntryPlayableTimeLimit.Value)
{
currentAnimatorFix.AttemptRewindAnimator();
}
currentIndex++;
}
currentAnimatorFix.AttemptRewindAnimator();
}
public static void ToggleJob(bool enable)
{
var job = SchedulerSystem.Instance.activeJobs.FirstOrDefault(pair => pair.Job.Method.Name == "CheckNextAnimator").Job;
if (enable && job == null)
{
SchedulerSystem.AddJob(new SchedulerSystem.Job(BadAnimatorFixManager.CheckNextAnimator), 0f, 5f, -1);
SchedulerSystem.AddJob(new SchedulerSystem.Job(CheckNextAnimator), 0f, checkInterval, -1);
}
else if (!enable && job != null)
{