mirror of
https://github.com/hanetzer/sdraw_mods_cvr.git
synced 2025-09-05 03:19:23 +00:00
Animator parameters save and restore
This commit is contained in:
parent
c90119e20a
commit
3a6304e566
2 changed files with 78 additions and 6 deletions
71
ml_amt/AnimatorAnalyzer.cs
Normal file
71
ml_amt/AnimatorAnalyzer.cs
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
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,14 +256,15 @@ namespace ml_amt
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void OnOverride_Prefix(ref CVRAnimatorManager __instance, ref bool __state)
|
static void OnOverride_Prefix(ref CVRAnimatorManager __instance, out AnimatorAnalyzer __state)
|
||||||
{
|
{
|
||||||
|
__state = new AnimatorAnalyzer();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if(Settings.OverrideFix && (__instance.animator != null))
|
if(Settings.OverrideFix && (__instance.animator != null))
|
||||||
{
|
{
|
||||||
__state = __instance.animator.enabled;
|
__state.AnalyzeFrom(__instance.animator);
|
||||||
if(__state)
|
if(__state.IsEnabled())
|
||||||
__instance.animator.enabled = false;
|
__instance.animator.enabled = false;
|
||||||
__instance.animator.WriteDefaultValues();
|
__instance.animator.WriteDefaultValues();
|
||||||
}
|
}
|
||||||
|
@ -273,14 +274,14 @@ namespace ml_amt
|
||||||
MelonLoader.MelonLogger.Error(l_exception);
|
MelonLoader.MelonLogger.Error(l_exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static void OnOverride_Postfix(ref CVRAnimatorManager __instance, bool __state)
|
static void OnOverride_Postfix(ref CVRAnimatorManager __instance, AnimatorAnalyzer __state)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if(Settings.OverrideFix && (__instance.animator != null))
|
if(Settings.OverrideFix && (__instance.animator != null))
|
||||||
{
|
{
|
||||||
__instance.animator.enabled = __state;
|
__state.ApplyTo(__instance.animator);
|
||||||
if(__state)
|
if(__state.IsEnabled())
|
||||||
__instance.animator.Update(0f);
|
__instance.animator.Update(0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue