/// <summary> /// Checks the transitions, swaps the current state if any return true. /// Then updates the current state if we have one /// </summary> public void DoState(ref T obj) { //Don't do anything if we don't have a reference to the controller if (EqualityComparer <T> .Default.Equals(obj, default)) { return; } //Represents the start function if (_current == null && _target != null) { _current = _target; _current.State_Start(ref obj); } //Make sure we have a state we can call if (_current != null) { //Do we need to make a global transition //Do we need to make a transition out of the current state if (CheckTransitions(ref obj, ref globalTransitions, null) || CheckTransitions(ref obj, ref _current.transitions, _current.ignoreTransition)) { //Swap the states SwapStates(ref obj); } //Call update on our current state _current.State_Update(ref obj); } }
/// <summary> /// Swaps target state to current state /// </summary> /// <param name="obj">A reference to the object</param> void SwapStates(ref T obj) { //Make sure we have a valid controller if (EqualityComparer <T> .Default.Equals(obj, default) || _target == _current || _target == null) { return; } //Call end on our current state _current.State_End(ref obj); //Swap our states around #if PREVIOUS_STATE_MACHINE _previous = _current; #endif _current = _target; _target = null; //call state on our new state _current.State_Start(ref obj); }