-
Notifications
You must be signed in to change notification settings - Fork 560
事件系统
框架提供了GlobalEvent类派发事件
以枚举为Key
static void AddEvent(Enum type, EventHandle handle, bool isUseOnce = false) 注册一个事件监听
static void RemoveEvent(Enum type, EventHandle handle) 移除一个事件监听
static void RemoveEvent(Enum type) 移除某类事件监听
static void DispatchEvent(Enum type, params object[] args) 派发事件
以String为Key
static void AddEvent(string eventKey, EventHandle handle, bool isUseOnce = false) 注册一个事件监听
static void RemoveEvent(string eventKey, EventHandle handle) 移除一个事件监听
static void RemoveEvent(string eventKey) 移除某类事件监听
static void DispatchEvent(string eventKey, params object[] args) 派发事件
泛型方法
static void AddTypeEvent<T>( EventHandle<T> handle, bool isUseOnce = false) 注册一个事件监听
static void RemoveTypeEvent<T>(EventHandle<T> handle, bool isUseOnce = false) 移除一个事件监听
static void RemoveTypeEvent<T>(bool isUseOnce = false) 移除某类事件监听
static void DispatchTypeEvent<T>(T e, params object[] args) 派发事件
static void RemoveAllEvent() 移除所有事件监听
GlobalEvent.AddEvent(MemoryEvent.FreeHeapMemory, CleanCache);
GlobalEvent.DispatchEvent(MemoryEvent.FreeHeapMemory);
GlobalEvent.RemoveEvent(MemoryEvent.FreeHeapMemory, CleanCache); GlobalEvent.AddEvent("GameStart", ReceviceGameStart);
GlobalEvent.DispatchEvent("GameStart");
GlobalEvent.RemoveEvent("GameStart", ReceviceGameStart); GlobalEvent.AddTypeEvent<SyncEntityMsg>(ReceviceSyncEntity);
GlobalEvent.DispatchTypeEvent(new SyncEntityMsg());
GlobalEvent.RemoveTypeEvent<SyncEntityMsg>(ReceviceSyncEntity);