Created
September 3, 2015 03:56
-
-
Save arun02139/d34e70e3b4ac9441a8af 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
using UnityEngine; | |
// interface and base state class | |
////////////////// | |
public interface IBaseState | |
{ | |
void Enter(object o); | |
void Exit(object o); | |
} | |
// the public enum triggers of one machine | |
////////////////// | |
public enum BattleTrigger | |
{ | |
StartIdle, | |
StartUnitAction, | |
StartChargedAction, | |
StartSkit, | |
EndBattle, | |
} | |
// base state class | |
////////////////// | |
public abstract class BattleState : IBaseState | |
{ | |
public virtual void Enter(object o) | |
{ | |
// Debug.Log("battle state entry (" + GetType() + ")"); | |
} | |
public virtual void Exit(object o) | |
{ | |
// Debug.Log("battle state exit (" + GetType() + ")"); | |
} | |
} | |
// example state | |
////////////////// | |
public class BattleIdle : BattleState | |
{ | |
public override void Enter(object o) | |
{ | |
// check to see if the battle is over! | |
var battle = (Battle)o; | |
if(BattleUtil.IsBattleOver(battle)) | |
{ | |
battle.TriggerQueue.Enqueue(BattleTrigger.EndBattle); | |
} | |
base.Enter(o); | |
} | |
public override void Exit(object o) | |
{ | |
base.Exit(o); | |
} | |
} | |
// added to StateMachine.cs | |
///////////////////////////// | |
public bool IsInState(Type type) | |
{ | |
return CurrentRepresentation.IsIncludedInType(type); | |
} | |
// example call from outside: | |
if(Machine.IsInState(typeof(BattleIdle))) | |
.. do somthing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment