200 lines
5.0 KiB
C#
200 lines
5.0 KiB
C#
// Author: whc
|
|
// Desc: 通知模型
|
|
// Discript:
|
|
// Inform 不带参数
|
|
// Inform<T> 带一个参数
|
|
|
|
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<eInformId, Action> m_Maps = new Dictionary<eInformId, Action>();
|
|
|
|
|
|
// 监听某个事件
|
|
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<T>
|
|
{
|
|
private static Dictionary<eInformId, Action<T>> m_Maps = new Dictionary<eInformId, Action<T>>();
|
|
|
|
public static void Listen(eInformId _informId, Action<T> _Func)
|
|
{
|
|
if (!m_Maps.ContainsKey(_informId))
|
|
m_Maps.Add(_informId, _Func);
|
|
else
|
|
m_Maps[_informId] += _Func;
|
|
}
|
|
|
|
public static void Cancel(eInformId _informId, Action<T> _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<T1, T2>
|
|
{
|
|
private static Dictionary<eInformId, Action<T1, T2>> m_Maps = new Dictionary<eInformId, Action<T1, T2>>();
|
|
|
|
public static void Listen(eInformId _informId, Action<T1, T2> _Func)
|
|
{
|
|
if (!m_Maps.ContainsKey(_informId))
|
|
m_Maps.Add(_informId, _Func);
|
|
else
|
|
m_Maps[_informId] += _Func;
|
|
}
|
|
|
|
public static void Cancel(eInformId _informId, Action<T1, T2> _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<T1, T2, T3>
|
|
{
|
|
private static Dictionary<eInformId, Action<T1, T2, T3>> m_Maps = new Dictionary<eInformId, Action<T1, T2, T3>>();
|
|
|
|
public static void Listen(eInformId _informId, Action<T1, T2, T3> _Func)
|
|
{
|
|
if (!m_Maps.ContainsKey(_informId))
|
|
m_Maps.Add(_informId, _Func);
|
|
else
|
|
m_Maps[_informId] += _Func;
|
|
}
|
|
|
|
public static void Cancel(eInformId _informId, Action<T1, T2, T3> _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<T1, T2, T3, T4>
|
|
{
|
|
private static Dictionary<eInformId, Action<T1, T2, T3, T4>> m_Maps = new Dictionary<eInformId, Action<T1, T2, T3, T4>>();
|
|
|
|
public static void Listen(eInformId _informId, Action<T1, T2, T3, T4> _Func)
|
|
{
|
|
if (!m_Maps.ContainsKey(_informId))
|
|
m_Maps.Add(_informId, _Func);
|
|
else
|
|
m_Maps[_informId] += _Func;
|
|
}
|
|
|
|
public static void Cancel(eInformId _informId, Action<T1, T2, T3, T4> _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);
|
|
}
|
|
}
|
|
|