Very effective way to manager game event. Like take damage and shoot etc..
- Trigger Event simple
- Configure Event Listener simple
- Support config by Attribute
- Support filter if you want modify event args.
Few simple step
EventDispatcher events; void Start() { events = GetComponent<EventDispatcher>() }
[EventListener(name = "DAMAGE")] void DamageHealth(int dmg) { health -= dmg; }
events.Trigger("DAMAGE", 10);
[EventFilter(name = "DAMAGE")] void DoubleDamage(object[] objs) { objs[0] = (int)objs[0] * 2; }
you can return a bool. Break call chain if you return false.
Same manager your game object state.
- Change state simple, use enum
- Support multi-state, like “GameState” “Health” etc
- Support config state event by Attribute
- Support inject state machine by Attribute
- Config unity behaviour callback easy, Like Update, FixUpdate
[RequireComponent(typeof(StateManager))]
class YourBehaviour : Monobehaviour
public enum GameState {
Play, Success, Failure
}
[StateMachineInject]
public StateMachine<GameState> _gameStateMachie;
_gameStateMachine.Init(Play);
_gameStateMachine.Change(GameState.Success);
stateManager.CurrentState; // if not init, it will return null
[StateEvent(state = GameObject.Play, on = StateEvent.Enter)] // The Enter support coroutine
void Play() {
}
Proxy MonoBehaviour event Callback
[StateListener(state = "GameState", when = "Play", on = "Update")]
void PlayUpdate()
{
// Do Update in Play;
}
void Update() {
stateManager.Update;
}
When yout change “GameState” to Success or Play, it will auto proxy to the true Update callback.
StateMachine sm = stateManager.GetStateMachine<GameState>();