public State(uint stateID, Animation animation) { StateID = stateID; Animation = animation; IsGlobal = animation.IsGlobal; Transitions = new List<Transition>(); }
/// <summary> /// Adds a state to this state machine. This function takes care of global states and ID checks. /// Should not really be used - instead use Character function 'CreateState' - it is much nicer and tidier. /// </summary> /// <param name="state"></param> public void CreateState(uint id, Animation animation) { // This is a check to make sure that we are adding the states in the order they are declared in the enum. // If this doesn't occur, the states will be mixed up and all hell will break loose. Debug.Assert(id == currentAddedStates); State state = new State(id, animation); States[currentAddedStates] = state; currentAddedStates++; // If our state is global, add it to our list if (state.IsGlobal) { GlobalStates.Add(state); } }
/// <summary> /// Sets up all the states and transitions. /// </summary> protected virtual void SetUpAnimations() { DebugUtils.AssertNotNull(Data); CharacterData data = Data.As<CharacterData>(); DebugUtils.AssertNotNull(data); // Checks that we have declared at most the same number of enum behaviours as we have animations. // If NumAnimations is larger than data.AnimationInfo.Count, it means we have not loaded enough animations for all our behaviours. Debug.Assert(data.AnimationInfo.Count >= NumBehaviours); StateMachine = new StateMachine(this, NumBehaviours); foreach (string animationDataAsset in data.AnimationInfo) { Animation animation = new Animation(data.FolderPath + animationDataAsset + ".xml"); animation.LoadContent(); Debug.Assert(!Animations.ContainsKey(animationDataAsset)); Animations.Add(animationDataAsset, animation); } CreateState("Idle", (uint)CharacterBehaviours.kIdle); CreateState("Death", (uint)CharacterBehaviours.kDeath); StateMachine.StartingState = (uint)CharacterBehaviours.kIdle; }