浏览代码

Refactored names in Messager : Event > Message

/main
Thomas ICHÉ 6 年前
当前提交
3c2fdf9a
共有 2 个文件被更改,包括 22 次插入13 次删除
  1. 2
      Runtime/Hooks/OnMessageHook.cs
  2. 33
      Runtime/Messager/Messager.cs

2
Runtime/Hooks/OnMessageHook.cs


void OnEnable()
{
Messager.RegisterEvent(MessageName, Execute);
Messager.RegisterMessage(MessageName, Execute);
}
void OnDisable()

33
Runtime/Messager/Messager.cs


{
public static class Messager
{
private static Dictionary<string, Action> m_RegisteredEvents;
public delegate void Message();
private static Dictionary<string, Message> m_RegisteredMessages;
m_RegisteredEvents = new Dictionary<string, Action>();
m_RegisteredMessages = new Dictionary<string, Message>();
public static void RegisterEvent(string eventName, Action action)
public static void RegisterMessage(string eventName, Message message)
if (!m_RegisteredEvents.ContainsKey(eventName))
m_RegisteredEvents.Add(eventName, action);
if (!m_RegisteredMessages.ContainsKey(eventName))
m_RegisteredMessages.Add(eventName, message);
m_RegisteredEvents[eventName] += action;
m_RegisteredMessages[eventName] += message;
public static void UnregisterEvent(string eventName, Action action)
public static void UnregisterEvent(string eventName, Message message)
var currentEvent = m_RegisteredEvents[eventName];
currentEvent -= action;
var currentEvent = m_RegisteredMessages[eventName];
currentEvent -= message;
m_RegisteredEvents.Remove(eventName);
m_RegisteredMessages.Remove(eventName);
}
public static void Send(string eventName)

if (m_RegisteredEvents.ContainsKey(eventName))
if (m_RegisteredMessages.ContainsKey(eventName))
m_RegisteredEvents[eventName]();
var call = m_RegisteredMessages[eventName];
var list = call.GetInvocationList();
if (call != null)
call();
else
Debug.LogWarning(string.Format("Found null action while sending Message {0}", eventName));
}
catch (Exception e)
{

正在加载...
取消
保存