Skip to content

Commit

Permalink
Avatar parameters changes
Browse files Browse the repository at this point in the history
  • Loading branch information
SDraw committed Dec 30, 2022
1 parent b1b1a32 commit b6bf52b
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 81 deletions.
78 changes: 78 additions & 0 deletions ml_amt/AvatarParameter.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
}
97 changes: 16 additions & 81 deletions ml_amt/MotionTweaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -84,11 +63,11 @@ enum PoseState
bool m_followHips = true;
Vector3 m_hipsToPlayer = Vector3.zero;

readonly List<AdditionalParameterInfo> m_parameters = null;
readonly List<AvatarParameter> m_parameters = null;

public MotionTweaker()
{
m_parameters = new List<AdditionalParameterInfo>();
m_parameters = new List<AvatarParameter>();
}

void Start()
Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
}
}
1 change: 1 addition & 0 deletions ml_amt/ml_amt.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="AvatarParameter.cs" />
<Compile Include="MotionTweaker.cs" />
<Compile Include="Main.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down

0 comments on commit b6bf52b

Please sign in to comment.