mirror of
https://github.com/hanetzer/sdraw_mods_cvr.git
synced 2025-09-03 10:29:22 +00:00
80 lines
2.3 KiB
C#
80 lines
2.3 KiB
C#
using ABI_RC.Core;
|
|
using System.Text.RegularExpressions;
|
|
using UnityEngine;
|
|
|
|
namespace ml_amt
|
|
{
|
|
class AvatarParameter
|
|
{
|
|
public enum ParameterType
|
|
{
|
|
GroundedRaw,
|
|
Moving
|
|
}
|
|
|
|
readonly ParameterType m_type;
|
|
readonly string m_name;
|
|
readonly int m_hash = 0;
|
|
readonly bool m_sync;
|
|
readonly AnimatorControllerParameterType m_innerType;
|
|
readonly CVRAnimatorManager m_manager = null;
|
|
|
|
public AvatarParameter(ParameterType p_type, CVRAnimatorManager p_manager)
|
|
{
|
|
m_type = p_type;
|
|
m_name = p_type.ToString();
|
|
m_manager = p_manager;
|
|
|
|
Regex l_regex = new Regex("^#?" + m_name + '$');
|
|
foreach(var l_param in m_manager.animator.parameters)
|
|
{
|
|
if(l_regex.IsMatch(l_param.name))
|
|
{
|
|
m_hash = l_param.nameHash;
|
|
m_sync = !l_param.name.StartsWith('#');
|
|
m_innerType = l_param.type;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Update(MotionTweaker p_tweaker)
|
|
{
|
|
switch(m_type)
|
|
{
|
|
case ParameterType.GroundedRaw:
|
|
SetBoolean(p_tweaker.GetGroundedRaw());
|
|
break;
|
|
|
|
case ParameterType.Moving:
|
|
SetBoolean(p_tweaker.GetMoving());
|
|
break;
|
|
}
|
|
}
|
|
|
|
public bool IsValid() => (m_hash != 0);
|
|
public ParameterType GetParameterType() => m_type;
|
|
|
|
void SetFloat(float p_value)
|
|
{
|
|
if(m_innerType == AnimatorControllerParameterType.Float)
|
|
{
|
|
if(m_sync)
|
|
m_manager.SetAnimatorParameterFloat(m_name, p_value);
|
|
else
|
|
m_manager.animator.SetFloat(m_hash, p_value);
|
|
}
|
|
}
|
|
|
|
void SetBoolean(bool p_value)
|
|
{
|
|
if(m_innerType == AnimatorControllerParameterType.Bool)
|
|
{
|
|
if(m_sync)
|
|
m_manager.SetAnimatorParameterBool(m_name, p_value);
|
|
else
|
|
m_manager.animator.SetBool(m_hash, p_value);
|
|
}
|
|
}
|
|
}
|
|
}
|