using UnityEngine;
using System.Collections;
public class CharacterStateMachine
{
public virtual void Init(UnitStateIndex stateIndex, Character owner)
{ m_stateIndex = stateIndex;
m_owner = owner; }
public virtual void Enter()
{}
public virtual void Exit()
{}
public virtual void UpdateFrame()
{ }
public virtual void AfterUpdateFrame()
{}
public UnitStateIndex GetStateIndex()
{
return m_stateIndex;
}
public virtual void OccurEventActionMessage(EventMessage msg, params object[] paramList)
{
}
UnitStateIndex m_stateIndex;
protected Character m_owner;
protected float m_currTime;
}

이클래스를 상속 받아서


using UnityEngine;
using System.Collections;
public class DeadState : CharacterStateMachine
{
public override void Enter()
{
m_owner.SetAnimation("Dead", false);
}
public override void Exit()
{
}
public override void UpdateFrame()
{
if (m_owner.IsEndAnimation())
{
m_owner.SetState(UnitStateIndex.Idle);
}
}
}

이런식으로 짯으면 뭔 관계임?

그리고 관리자 클래스

public class CharacterStateMachineManager
{
public void Init(Character owner)
{
CharacterStateMachine state = null;
for (UnitStateIndex index = UnitStateIndex.Idle; index < UnitStateIndex.Max; ++index)
{
Util.CreateInstanceToString<CharacterStateMachine>(ref state, string.Format("{0}State", index.ToString()));
state.Init(index, owner);
m_states[(int)index] = state;
}
}