Skip to content

Instantly share code, notes, and snippets.

@arun02139
Created September 3, 2015 03:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arun02139/d34e70e3b4ac9441a8af to your computer and use it in GitHub Desktop.
Save arun02139/d34e70e3b4ac9441a8af to your computer and use it in GitHub Desktop.
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