mirror of
https://github.com/hanetzer/sdraw_mods_cvr.git
synced 2025-09-05 03:19:23 +00:00
Animator parameters save and restore (reverted from commit 3a6304e566
)
This commit is contained in:
parent
3a6304e566
commit
b3a65f3124
2 changed files with 6 additions and 78 deletions
|
@ -1,71 +0,0 @@
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace ml_amt
|
|
||||||
{
|
|
||||||
class AnimatorAnalyzer
|
|
||||||
{
|
|
||||||
bool m_enabled = true;
|
|
||||||
List<AnimatorControllerParameter> m_parameters = null;
|
|
||||||
|
|
||||||
public void AnalyzeFrom(Animator p_animator)
|
|
||||||
{
|
|
||||||
m_enabled = p_animator.enabled;
|
|
||||||
m_parameters = p_animator.parameters?.ToList();
|
|
||||||
|
|
||||||
if(m_parameters != null)
|
|
||||||
{
|
|
||||||
foreach(var l_param in m_parameters)
|
|
||||||
{
|
|
||||||
switch(l_param.type)
|
|
||||||
{
|
|
||||||
case AnimatorControllerParameterType.Bool:
|
|
||||||
case AnimatorControllerParameterType.Trigger:
|
|
||||||
l_param.defaultBool = p_animator.GetBool(l_param.nameHash);
|
|
||||||
break;
|
|
||||||
case AnimatorControllerParameterType.Float:
|
|
||||||
l_param.defaultFloat = p_animator.GetFloat(l_param.nameHash);
|
|
||||||
break;
|
|
||||||
case AnimatorControllerParameterType.Int:
|
|
||||||
l_param.defaultInt = p_animator.GetInteger(l_param.nameHash);
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ApplyTo(Animator p_animator)
|
|
||||||
{
|
|
||||||
p_animator.enabled = m_enabled;
|
|
||||||
|
|
||||||
if(m_parameters != null)
|
|
||||||
{
|
|
||||||
foreach(var l_param in m_parameters)
|
|
||||||
{
|
|
||||||
switch(l_param.type)
|
|
||||||
{
|
|
||||||
case AnimatorControllerParameterType.Bool:
|
|
||||||
p_animator.SetBool(l_param.nameHash, l_param.defaultBool);
|
|
||||||
break;
|
|
||||||
case AnimatorControllerParameterType.Float:
|
|
||||||
p_animator.SetFloat(l_param.nameHash, l_param.defaultFloat);
|
|
||||||
break;
|
|
||||||
case AnimatorControllerParameterType.Int:
|
|
||||||
p_animator.SetInteger(l_param.nameHash, l_param.defaultInt);
|
|
||||||
break;
|
|
||||||
case AnimatorControllerParameterType.Trigger:
|
|
||||||
{
|
|
||||||
if(l_param.defaultBool)
|
|
||||||
p_animator.SetTrigger(l_param.nameHash);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsEnabled() => m_enabled;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -256,15 +256,14 @@ namespace ml_amt
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void OnOverride_Prefix(ref CVRAnimatorManager __instance, out AnimatorAnalyzer __state)
|
static void OnOverride_Prefix(ref CVRAnimatorManager __instance, ref bool __state)
|
||||||
{
|
{
|
||||||
__state = new AnimatorAnalyzer();
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if(Settings.OverrideFix && (__instance.animator != null))
|
if(Settings.OverrideFix && (__instance.animator != null))
|
||||||
{
|
{
|
||||||
__state.AnalyzeFrom(__instance.animator);
|
__state = __instance.animator.enabled;
|
||||||
if(__state.IsEnabled())
|
if(__state)
|
||||||
__instance.animator.enabled = false;
|
__instance.animator.enabled = false;
|
||||||
__instance.animator.WriteDefaultValues();
|
__instance.animator.WriteDefaultValues();
|
||||||
}
|
}
|
||||||
|
@ -274,14 +273,14 @@ namespace ml_amt
|
||||||
MelonLoader.MelonLogger.Error(l_exception);
|
MelonLoader.MelonLogger.Error(l_exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static void OnOverride_Postfix(ref CVRAnimatorManager __instance, AnimatorAnalyzer __state)
|
static void OnOverride_Postfix(ref CVRAnimatorManager __instance, bool __state)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if(Settings.OverrideFix && (__instance.animator != null))
|
if(Settings.OverrideFix && (__instance.animator != null))
|
||||||
{
|
{
|
||||||
__state.ApplyTo(__instance.animator);
|
__instance.animator.enabled = __state;
|
||||||
if(__state.IsEnabled())
|
if(__state)
|
||||||
__instance.animator.Update(0f);
|
__instance.animator.Update(0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue