本文整理汇总了C#中StateMachine.GetState方法的典型用法代码示例。如果您正苦于以下问题:C# StateMachine.GetState方法的具体用法?C# StateMachine.GetState怎么用?C# StateMachine.GetState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StateMachine
的用法示例。
在下文中一共展示了StateMachine.GetState方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AssignAnimationToCharacter
/// <summary>
/// Assigns the animation to the character.
/// </summary>
static void AssignAnimationToCharacter(AnimationClip clip, GameObject character)
{
//create a new controller
UnityEditorInternal.AnimatorController my_controller = new UnityEditorInternal.AnimatorController();
my_controller.name = "generic_controller";
//check if the animator component is already attached to the character
if (character.GetComponent<Animator>() == null)
character.AddComponent<Animator>();
//create the state machine with the animation clip
StateMachine sm = new StateMachine();
sm.AddState("default_state");
sm.GetState(0).SetMotion(0, clip);
//check if the controller already has a based layer
if (my_controller.GetLayerCount() == 0)
my_controller.AddLayer("Base Layer");
//set the state machine
my_controller.SetLayerStateMachine(0, sm);
//assign the controller
Animator animator = (Animator)character.GetComponent<Animator>();
UnityEditorInternal.AnimatorController.SetAnimatorController(animator,my_controller);
}
示例2: GetTransitionNamesFromStateMachine
private static string[] GetTransitionNamesFromStateMachine(StateMachine sm)
{
List<string> transitionNames = new List<string>();
List<Transition> transitions = new List<Transition>();
for (int i = 0; i < sm.stateCount; ++i)
{
transitions.AddRange(sm.GetTransitionsFromState(sm.GetState(i)));
}
foreach (Transition transition in transitions)
transitionNames.Add(transition.uniqueName);
for (int i = 0; i < sm.stateMachineCount; ++i)
{
transitionNames.AddRange(GetTransitionNamesFromStateMachine(sm.GetStateMachine(i)));
}
return transitionNames.ToArray();
}
示例3: GetTransitionsCountFromStateMachine
private static int GetTransitionsCountFromStateMachine(StateMachine sm)
{
int total = 0;
List<Transition> transitions = new List<Transition>();
for (int i = 0; i < sm.stateCount; ++i)
{
transitions.AddRange(sm.GetTransitionsFromState(sm.GetState(i)));
}
total = transitions.Count;
for (int i = 0; i < sm.stateMachineCount; ++i)
{
total += GetTransitionsCountFromStateMachine(sm.GetStateMachine(i));
}
return total;
}
示例4: GetStateNamesFromStateMachine
private static string[] GetStateNamesFromStateMachine(StateMachine sm)
{
List<string> stateNames = new List<string>();
for (int i = 0; i < sm.stateCount; ++i)
{
stateNames.Add(sm.GetState(i).uniqueName);
}
for (int i = 0; i < sm.stateMachineCount; ++i)
{
stateNames.AddRange(GetStateNamesFromStateMachine(sm.GetStateMachine(i)));
}
return stateNames.ToArray();
}
示例5: GetTransitionKeysFromStateMachine
private static int[] GetTransitionKeysFromStateMachine(StateMachine sm)
{
List<int> transitionKeys = new List<int>();
List<Transition> transitions = new List<Transition>();
for (int i = 0; i < sm.stateCount; ++i)
{
transitions.AddRange(sm.GetTransitionsFromState(sm.GetState(i)));
}
foreach (Transition transition in transitions)
transitionKeys.Add(transition.uniqueNameHash);
for (int i = 0; i < sm.stateMachineCount; ++i)
{
transitionKeys.AddRange(GetTransitionKeysFromStateMachine(sm.GetStateMachine(i)));
}
return transitionKeys.ToArray();
}
示例6: GetStateKeysFromStateMachine
private static int[] GetStateKeysFromStateMachine(StateMachine sm)
{
List<int> stateKeys = new List<int>();
for (int i = 0; i < sm.stateCount; ++i)
{
stateKeys.Add(sm.GetState(i).uniqueNameHash);
}
for (int i = 0; i < sm.stateMachineCount; ++i)
{
stateKeys.AddRange(GetStateKeysFromStateMachine(sm.GetStateMachine(i)));
}
return stateKeys.ToArray();
}
示例7: FromStateMachineToTransitionName
private static void FromStateMachineToTransitionName(StateMachine stateMachine, List<string> transitionNames)
{
for (int i = 0; i < stateMachine.stateCount; i++) {
Transition[] trans = stateMachine.GetTransitionsFromState(stateMachine.GetState(i));
foreach(Transition tran in trans) {
transitionNames.Add(tran.uniqueName);
}
}
for (int i = 0; i < stateMachine.stateMachineCount; i++) {
FromStateMachineToTransitionName(stateMachine.GetStateMachine(i), transitionNames);
}
}
示例8: FromStateMachineToStateName
private static void FromStateMachineToStateName(StateMachine stateMachine, List<string> stateNames)
{
for (int i = 0; i < stateMachine.stateCount; i++) {
stateNames.Add(stateMachine.GetState(i).uniqueName);
}
for (int i = 0; i < stateMachine.stateMachineCount; i++) {
FromStateMachineToStateName(stateMachine.GetStateMachine(i), stateNames);
}
}
示例9: FromStateMachineToStateKey
private static void FromStateMachineToStateKey(StateMachine stateMachine, List<int> stateKeys)
{
for (int i = 0; i < stateMachine.stateCount; i++) {
stateKeys.Add(stateMachine.GetState(i).uniqueNameHash);
}
for (int i = 0; i < stateMachine.stateMachineCount; i++) {
FromStateMachineToStateKey(stateMachine.GetStateMachine(i), stateKeys);
}
}
示例10: SetAnimator
// Create and assign controller and animation
void SetAnimator()
{
// Add the component if it's not already there
if (gameObject.GetComponent<Animator>() == null)
gameObject.AddComponent<Animator>();
charAnimator = (Animator)gameObject.GetComponent<Animator>();
// Set speed to 0 so no real animation takes place
charAnimator.speed = 0.0f;
UnityEditorInternal.AnimatorController aController = new UnityEditorInternal.AnimatorController();
aController.name = "animation_controller";
if (aController.GetLayerCount() == 0)
aController.AddLayer("Base");
StateMachine sm = new StateMachine();
sm.AddState("default");
// Add clip
sm.GetState(0).SetMotion(0, (AnimationClip)animations[animCount]);
animCount++;
aController.SetLayerStateMachine(0, sm);
UnityEditorInternal.AnimatorController.SetAnimatorController(charAnimator, aController);
// Set time
currTime = charAnimator.GetCurrentAnimatorStateInfo(0).normalizedTime;
}