diff --git a/ml_amt/AvatarParameter.cs b/ml_amt/AvatarParameter.cs new file mode 100644 index 0000000..3349104 --- /dev/null +++ b/ml_amt/AvatarParameter.cs @@ -0,0 +1,78 @@ +using ABI_RC.Core.Player; + +namespace ml_amt +{ + class AvatarParameter + { + public enum ParameterType + { + Upright, + GroundedRaw, + Moving + } + + public enum ParameterSyncType + { + Synced, + Local + } + + public readonly ParameterType m_type; + public readonly ParameterSyncType m_sync; + public readonly string m_name; + public readonly int m_hash; // For local only + + + public AvatarParameter(ParameterType p_type, string p_name, ParameterSyncType p_sync = ParameterSyncType.Synced, int p_hash = 0) + { + m_type = p_type; + m_sync = p_sync; + m_name = p_name; + m_hash = p_hash; + } + + public void Update(MotionTweaker p_tweaker) + { + switch(m_type) + { + case ParameterType.Upright: + SetFloat(p_tweaker.GetUpright()); + break; + + case ParameterType.GroundedRaw: + SetBoolean(p_tweaker.GetGroundedRaw()); + break; + + case ParameterType.Moving: + SetBoolean(p_tweaker.GetMoving()); + break; + } + } + + void SetFloat(float p_value) + { + switch(m_sync) + { + case ParameterSyncType.Local: + PlayerSetup.Instance._animator.SetFloat(m_hash, p_value); + break; + case ParameterSyncType.Synced: + PlayerSetup.Instance.animatorManager.SetAnimatorParameterFloat(m_name, p_value); + break; + } + } + + void SetBoolean(bool p_value) + { + switch(m_sync) + { + case ParameterSyncType.Local: + PlayerSetup.Instance._animator.SetBool(m_hash, p_value); + break; + case ParameterSyncType.Synced: + PlayerSetup.Instance.animatorManager.SetAnimatorParameterBool(m_name, p_value); + break; + } + } + } +} diff --git a/ml_amt/MotionTweaker.cs b/ml_amt/MotionTweaker.cs index 5947147..497694f 100644 --- a/ml_amt/MotionTweaker.cs +++ b/ml_amt/MotionTweaker.cs @@ -15,27 +15,6 @@ class MotionTweaker : MonoBehaviour static readonly FieldInfo ms_groundedRaw = typeof(MovementSystem).GetField("_isGroundedRaw", BindingFlags.NonPublic | BindingFlags.Instance); static readonly int ms_emoteHash = Animator.StringToHash("Emote"); - enum ParameterType - { - Upright, - GroundedRaw, - Moving - } - - enum ParameterSyncType - { - Local, - Synced - } - - struct AdditionalParameterInfo - { - public ParameterType m_type; - public ParameterSyncType m_sync; - public string m_name; - public int m_hash; // For local only - } - enum PoseState { Standing = 0, @@ -84,11 +63,11 @@ enum PoseState bool m_followHips = true; Vector3 m_hipsToPlayer = Vector3.zero; - readonly List m_parameters = null; + readonly List m_parameters = null; public MotionTweaker() { - m_parameters = new List(); + m_parameters = new List(); } void Start() @@ -173,53 +152,8 @@ void Update() if(m_parameters.Count > 0) { - foreach(AdditionalParameterInfo l_param in m_parameters) - { - switch(l_param.m_type) - { - case ParameterType.Upright: - { - switch(l_param.m_sync) - { - case ParameterSyncType.Local: - PlayerSetup.Instance._animator.SetFloat(l_param.m_hash, m_upright); - break; - case ParameterSyncType.Synced: - PlayerSetup.Instance.animatorManager.SetAnimatorParameterFloat(l_param.m_name, m_upright); - break; - } - } - break; - - case ParameterType.GroundedRaw: - { - switch(l_param.m_sync) - { - case ParameterSyncType.Local: - PlayerSetup.Instance._animator.SetBool(l_param.m_hash, m_groundedRaw); - break; - case ParameterSyncType.Synced: - PlayerSetup.Instance.animatorManager.SetAnimatorParameterBool(l_param.m_name, m_groundedRaw); - break; - } - } - break; - - case ParameterType.Moving: - { - switch(l_param.m_sync) - { - case ParameterSyncType.Local: - PlayerSetup.Instance._animator.SetBool(l_param.m_hash, m_moving); - break; - case ParameterSyncType.Synced: - PlayerSetup.Instance.animatorManager.SetAnimatorParameterBool(l_param.m_name, m_moving); - break; - } - } - break; - } - } + foreach(AvatarParameter l_param in m_parameters) + l_param.Update(this); } } } @@ -256,30 +190,27 @@ public void OnSetupAvatar() // Parse animator parameters AnimatorControllerParameter[] l_params = PlayerSetup.Instance._animator.parameters; - ParameterType[] l_enumParams = (ParameterType[])System.Enum.GetValues(typeof(ParameterType)); - foreach(var l_param in l_params) { - foreach(var l_enumParam in l_enumParams) + foreach(AvatarParameter.ParameterType l_enumParam in System.Enum.GetValues(typeof(AvatarParameter.ParameterType))) { if(l_param.name.Contains(l_enumParam.ToString()) && (m_parameters.FindIndex(p => p.m_type == l_enumParam) == -1)) { bool l_local = (l_param.name[0] == '#'); - m_parameters.Add(new AdditionalParameterInfo - { - m_type = l_enumParam, - m_sync = (l_local ? ParameterSyncType.Local : ParameterSyncType.Synced), - m_name = l_param.name, - m_hash = (l_local ? l_param.nameHash : 0) - }); + m_parameters.Add(new AvatarParameter( + l_enumParam, + l_param.name, + (l_local ? AvatarParameter.ParameterSyncType.Local : AvatarParameter.ParameterSyncType.Synced), + (l_local ? l_param.nameHash : 0) + )); break; } } } - m_compatibleAvatar = m_parameters.Exists(p => p.m_name.Contains("Upright")); + m_compatibleAvatar = m_parameters.Exists(p => p.m_type == AvatarParameter.ParameterType.Upright); m_avatarScale = Mathf.Abs(PlayerSetup.Instance._avatar.transform.localScale.y); Transform l_customTransform = PlayerSetup.Instance._avatar.transform.Find("CrouchLimit"); @@ -417,5 +348,9 @@ public void SetFollowHips(bool p_state) { m_followHips = p_state; } + + public float GetUpright() => m_upright; + public bool GetGroundedRaw() => m_groundedRaw; + public bool GetMoving() => m_moving; } } diff --git a/ml_amt/ml_amt.csproj b/ml_amt/ml_amt.csproj index 83cb6a1..bea6a67 100644 --- a/ml_amt/ml_amt.csproj +++ b/ml_amt/ml_amt.csproj @@ -75,6 +75,7 @@ +