From 336373169a79e7ebc7a37561a204ba77b44c9ba6 Mon Sep 17 00:00:00 2001 From: originalnicodr Date: Tue, 13 Feb 2024 23:38:13 -0300 Subject: [PATCH] Refactored the Animator pause to use start and stop playback (since disabling the whole animator could cause problems in some games). I am still disabling the animator as a fallback if the described method doesn't work. --- src/Cinematic/Cells/AnimatorCell.cs | 15 ++++++++++++++- src/UI/Panels/AnimatorPanel.cs | 15 ++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/Cinematic/Cells/AnimatorCell.cs b/src/Cinematic/Cells/AnimatorCell.cs index e06b1d2..09674a7 100644 --- a/src/Cinematic/Cells/AnimatorCell.cs +++ b/src/Cinematic/Cells/AnimatorCell.cs @@ -116,7 +116,20 @@ namespace UnityExplorer.UI.Panels AnimatorToggle.isOn = true; AnimatorToggle.onValueChanged.AddListener(value => { //ExplorerCore.LogWarning($"Animator toggled: {animator} to {animator.enabled}"); - animator.enabled = value; + try { + Type animatorClass = ReflectionUtility.GetTypeByName("UnityEngine.Animator"); + if (value) { + MethodInfo stopPlayBack = animatorClass.GetMethod("StopPlayback"); + stopPlayBack.Invoke(animator.TryCast(), null); + } else { + MethodInfo startPlayBack = animatorClass.GetMethod("StartPlayback"); + startPlayBack.Invoke(animator.TryCast(), null); + } + } + catch { + // Fallback in case reflection isn't working + animator.enabled = value; + } // If we play an animation and we disable the animator then don't stop the animation when it finishes after we enable the animator again if (!value && stopAfterAnimationFinishes) stopAfterAnimationFinishes = false; } diff --git a/src/UI/Panels/AnimatorPanel.cs b/src/UI/Panels/AnimatorPanel.cs index 8aee48c..1627440 100644 --- a/src/UI/Panels/AnimatorPanel.cs +++ b/src/UI/Panels/AnimatorPanel.cs @@ -103,7 +103,20 @@ namespace UnityExplorer.UI.Panels // We gotta do this for the animators which cell are not being currently rendered. foreach (Animator animator in animators){ if (!shouldIgnoreMasterToggle[animator]){ - animator.enabled = enable; + try { + Type animatorClass = ReflectionUtility.GetTypeByName("UnityEngine.Animator"); + if (enable) { + MethodInfo stopPlayBack = animatorClass.GetMethod("StopPlayback"); + stopPlayBack.Invoke(animator.TryCast(), null); + } else { + MethodInfo startPlayBack = animatorClass.GetMethod("StartPlayback"); + startPlayBack.Invoke(animator.TryCast(), null); + } + } + catch { + // Fallback in case reflection isn't working + animator.enabled = enable; + } } } }