mirror of
https://github.com/hanetzer/sdraw_mods_cvr.git
synced 2025-09-03 18:39:23 +00:00
Animator parameters save and restore
This commit is contained in:
parent
da201e2135
commit
2c67f02f7e
4 changed files with 82 additions and 9 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;
|
||||
}
|
||||
|
||||
static void OnOverride_Prefix(ref CVRAnimatorManager __instance, ref bool __state)
|
||||
static void OnOverride_Prefix(ref CVRAnimatorManager __instance, out AnimatorAnalyzer __state)
|
||||
{
|
||||
__state = new AnimatorAnalyzer();
|
||||
try
|
||||
{
|
||||
if(Settings.OverrideFix && (__instance.animator != null))
|
||||
{
|
||||
__state = __instance.animator.enabled;
|
||||
if(__state)
|
||||
__state.AnalyzeFrom(__instance.animator);
|
||||
if(__state.IsEnabled())
|
||||
__instance.animator.enabled = false;
|
||||
__instance.animator.WriteDefaultValues();
|
||||
}
|
||||
|
@ -273,14 +274,14 @@ namespace ml_amt
|
|||
MelonLoader.MelonLogger.Error(l_exception);
|
||||
}
|
||||
}
|
||||
static void OnOverride_Postfix(ref CVRAnimatorManager __instance, bool __state)
|
||||
static void OnOverride_Postfix(ref CVRAnimatorManager __instance, AnimatorAnalyzer __state)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(Settings.OverrideFix && (__instance.animator != null))
|
||||
{
|
||||
__instance.animator.enabled = __state;
|
||||
if(__state)
|
||||
__state.ApplyTo(__instance.animator);
|
||||
if(__state.IsEnabled())
|
||||
__instance.animator.Update(0f);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
using System.Reflection;
|
||||
|
||||
[assembly: AssemblyTitle("AvatarMotionTweaker")]
|
||||
[assembly: AssemblyVersion("1.2.3")]
|
||||
[assembly: AssemblyFileVersion("1.2.3")]
|
||||
[assembly: AssemblyVersion("1.2.4")]
|
||||
[assembly: AssemblyFileVersion("1.2.4")]
|
||||
|
||||
[assembly: MelonLoader.MelonInfo(typeof(ml_amt.AvatarMotionTweaker), "AvatarMotionTweaker", "1.2.3", "SDraw", "https://github.com/SDraw/ml_mods_cvr")]
|
||||
[assembly: MelonLoader.MelonInfo(typeof(ml_amt.AvatarMotionTweaker), "AvatarMotionTweaker", "1.2.4", "SDraw", "https://github.com/SDraw/ml_mods_cvr")]
|
||||
[assembly: MelonLoader.MelonGame(null, "ChilloutVR")]
|
||||
[assembly: MelonLoader.MelonPlatform(MelonLoader.MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)]
|
||||
[assembly: MelonLoader.MelonPlatformDomain(MelonLoader.MelonPlatformDomainAttribute.CompatibleDomains.MONO)]
|
|
@ -75,6 +75,7 @@
|
|||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AnimatorAnalyzer.cs" />
|
||||
<Compile Include="AvatarParameter.cs" />
|
||||
<Compile Include="MotionTweaker.cs" />
|
||||
<Compile Include="Main.cs" />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue