public static ICodeBehaviour AddBehaviour(this GameObject gameObject, StateMachine stateMachine) { ICodeBehaviour behaviour = gameObject.AddComponent <ICodeBehaviour> (); behaviour.stateMachine = stateMachine; behaviour.EnableStateMachine(); return(behaviour); }
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { if (behaviour == null) { behaviour = animator.gameObject.AddBehaviour(stateMachine); } else { behaviour.EnableStateMachine(); (behaviour.ActiveNode as State).Restart(); } }
public static ICodeBehaviour AddBehaviour(this GameObject gameObject, StateMachine stateMachine, int group, bool replaceIfExists) { ICodeBehaviour behaviour = gameObject.GetBehaviour(group); if (behaviour != null && replaceIfExists) { behaviour.stateMachine = stateMachine; behaviour.EnableStateMachine(); } else { behaviour = gameObject.AddBehaviour(stateMachine); behaviour.group = group; } return(behaviour); }
private void Start() { if (behaviour.stateMachine != null) { if (!behaviour.stateMachine.IsInitialized) { bool isEnabled = behaviour.enabled; behaviour.EnableStateMachine(); behaviour.enabled = isEnabled; } for (int i = 0; i < setVariables.Count; i++) { FsmVariable variable = behaviour.stateMachine.GetVariable(setVariables[i].name); if (variable != null) { variable.SetValue(setVariables[i].GetValue()); } } } }