Last active
June 2, 2020 02:23
-
-
Save SiunCyclone/90dc36f8760e8f1f3c82df91b575a417 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Assets/Scripts/Game/Modules/Character/Animation/CharacterAnimatorController.cs | |
public class CharacterAnimatorController { | |
public CharacterAnimatorController(PlayableGraph graph, RuntimeAnimatorController animatorController) { | |
m_animatorController = AnimatorControllerPlayable.Create(graph, animatorController); | |
// Find valid parameters in animatorcontroller | |
var animStateParams = new List<AnimStateParams>(); | |
var actionStateParams = new List<ActionStateParams>(); | |
m_supportedActionTriggers = new int[(int) CharacterPredictedData.Action.NumActions]; | |
for (int i = 0; i < m_animatorController.GetParameterCount(); i++) { | |
AnimatorControllerParameter param = m_animatorController.GetParameter(i); | |
switch (param.type) { | |
case AnimatorControllerParameterType.Bool: | |
{ | |
CharacterPredictedData.LocoState animState; | |
if (s_charLocoStateHashes.TryGetValue(param.nameHash, out animState)) { | |
var p = new AnimStateParams(); | |
p.state = animState; | |
p.hash = param.nameHash; | |
animStateParams.Add(p); | |
continue; | |
} | |
CharacterPredictedData.Action action; | |
if (s_actionStateHashes.TryGetValue(param.nameHash, out action)) { | |
var p = new ActionStateParams(); | |
p.action = action; | |
p.hash = param.nameHash; | |
actionStateParams.Add(p); | |
continue; | |
} | |
break; | |
} | |
case AnimatorControllerParameterType.Trigger: | |
{ | |
CharacterPredictedData.Action action; | |
if (s_actionTriggerHashes.TryGetValue(param.nameHash, out action)) { | |
m_supportedActionTriggers[(int) action] = param.nameHash; | |
continue; | |
} | |
if (param.nameHash == s_resetHash) { | |
m_resetSupported = true; | |
continue; | |
} | |
} | |
break; | |
} | |
} | |
m_supportedAnimStates = animStateParams.ToArray(); | |
m_supportedActionStates = actionStateParams.ToArray(); | |
} | |
struct AnimStateParams { | |
public CharacterPredictedData.LocoState state; | |
public int hash; | |
} | |
struct ActionStateParams { | |
public CharacterPredictedData.Action action; | |
public int hash; | |
} | |
readonly static Dictionary<int, CharacterPredictedData.LocoState> s_charLocoStateHashes = new Dictionary<int, CharacterPredictedData.LocoState>() { | |
{ Animator.StringToHash("AnimState_Stand"), CharacterPredictedData.LocoState.Stand }, | |
{ Animator.StringToHash("AnimState_Run"), CharacterPredictedData.LocoState.GroundMove }, | |
{ Animator.StringToHash("AnimState_Jump"), CharacterPredictedData.LocoState.Jump }, | |
// 略 | |
}; | |
readonly static Dictionary<int, CharacterPredictedData.Action> s_actionStateHashes = new Dictionary<int, CharacterPredictedData.Action>() { | |
// 略 | |
}; | |
readonly static Dictionary<int, CharacterPredictedData.Action> s_actionTriggerHashes = new Dictionary<int, CharacterPredictedData.Action>() { | |
// 略 | |
}; | |
AnimatorControllerPlayable m_animatorController; | |
AnimStateParams[] m_supportedAnimStates; | |
ActionStateParams[] m_supportedActionStates; | |
int[] m_supportedActionTriggers; | |
bool m_resetSupported; | |
} | |
// Assets/Scripts/Game/Modules/Character/Components/CharacterPredicted.cs | |
public struct CharacterPredictedData : IComponentData, IPredictedComponent<CharacterPredictedData> { | |
public enum LocoState { | |
Stand, | |
GroundMove, | |
Jump, | |
DoubleJump, | |
InAir, | |
MaxValue | |
} | |
public enum Action { | |
None, | |
PrimaryFire, | |
SecondaryFire, | |
Reloading, | |
Melee, | |
NumActions, | |
} | |
// 略 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment