// Author: whc // Desc: 通知模型 // Discript: // Inform 不带参数 // Inform 带一个参数 using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public enum eInformId { None = 0, SenceChange, TipDialog, TipHint, TipChoice, TipWait, TipWaitClose, // 关闭提示框 TipChoiceClose, // 关闭选择框 NetErrorCode, // 通用服务器协议错误码返回 UpdateingRefresh, //更新界面 BattleMonsterAttrUpdate, // 战斗 怪物属性更新 BattlePlayerAttrUpdate, // 战斗 玩家属性更新 //BattleMonsterMoving, // 战斗 怪物移动 //BattlePlayerMoving, // 战斗 玩家移动 BattleRoleMoving, // 战斗 角色移动 } public class Inform { private static Dictionary m_Maps = new Dictionary(); // 监听某个事件 public static void Listen(eInformId _informId, Action _Func) { if (!m_Maps.ContainsKey(_informId)) m_Maps.Add(_informId, _Func); else m_Maps[_informId] += _Func; } // 取消监听某个事件 public static void Cancel(eInformId _informId, Action _Func) { if (!m_Maps.ContainsKey(_informId)) return; m_Maps[_informId] -= _Func; if (m_Maps[_informId] == null) m_Maps.Remove(_informId); } // 通知某个事件被触发 public static void Dispatch(eInformId _informId) { if (!m_Maps.ContainsKey(_informId)) return; m_Maps[_informId](); } } public class Inform { private static Dictionary> m_Maps = new Dictionary>(); public static void Listen(eInformId _informId, Action _Func) { if (!m_Maps.ContainsKey(_informId)) m_Maps.Add(_informId, _Func); else m_Maps[_informId] += _Func; } public static void Cancel(eInformId _informId, Action _Func) { if (!m_Maps.ContainsKey(_informId)) return; m_Maps[_informId] -= _Func; if (m_Maps[_informId] == null) m_Maps.Remove(_informId); } public static void Dispatch(eInformId _informId, T param1) { if (!m_Maps.ContainsKey(_informId)) return; m_Maps[_informId](param1); } } public class Inform { private static Dictionary> m_Maps = new Dictionary>(); public static void Listen(eInformId _informId, Action _Func) { if (!m_Maps.ContainsKey(_informId)) m_Maps.Add(_informId, _Func); else m_Maps[_informId] += _Func; } public static void Cancel(eInformId _informId, Action _Func) { if (!m_Maps.ContainsKey(_informId)) return; m_Maps[_informId] -= _Func; if (m_Maps[_informId] == null) m_Maps.Remove(_informId); } public static void Dispatch(eInformId _informId, T1 param1, T2 param2) { if (!m_Maps.ContainsKey(_informId)) return; m_Maps[_informId](param1, param2); } } public class Inform { private static Dictionary> m_Maps = new Dictionary>(); public static void Listen(eInformId _informId, Action _Func) { if (!m_Maps.ContainsKey(_informId)) m_Maps.Add(_informId, _Func); else m_Maps[_informId] += _Func; } public static void Cancel(eInformId _informId, Action _Func) { if (!m_Maps.ContainsKey(_informId)) return; m_Maps[_informId] -= _Func; if (m_Maps[_informId] == null) m_Maps.Remove(_informId); } public static void Dispatch(eInformId _informId, T1 param1, T2 param2, T3 param3) { if (!m_Maps.ContainsKey(_informId)) return; m_Maps[_informId](param1, param2, param3); } } public class Inform { private static Dictionary> m_Maps = new Dictionary>(); public static void Listen(eInformId _informId, Action _Func) { if (!m_Maps.ContainsKey(_informId)) m_Maps.Add(_informId, _Func); else m_Maps[_informId] += _Func; } public static void Cancel(eInformId _informId, Action _Func) { if (!m_Maps.ContainsKey(_informId)) return; m_Maps[_informId] -= _Func; if (m_Maps[_informId] == null) m_Maps.Remove(_informId); } public static void Dispatch(eInformId _informId, T1 param1, T2 param2, T3 param3, T4 param4) { if (!m_Maps.ContainsKey(_informId)) return; m_Maps[_informId](param1, param2, param3, param4); } }