浏览代码

Fixed Messager when loading/unloading scenes

/main
Thomas ICHÉ 6 年前
当前提交
74a3d295
共有 1 个文件被更改,包括 22 次插入12 次删除
  1. 34
      Runtime/Messager/Messager.cs

34
Runtime/Messager/Messager.cs


{
public delegate void Message();
private static Dictionary<string, Message> m_RegisteredMessages;
private static Dictionary<string, List<Message>> m_RegisteredMessages;
m_RegisteredMessages = new Dictionary<string, Message>();
m_RegisteredMessages = new Dictionary<string, List<Message>>();
public static void RegisterMessage(string eventName, Message message)
public static void RegisterMessage(string messageName, Message message)
if (!m_RegisteredMessages.ContainsKey(eventName))
m_RegisteredMessages.Add(eventName, message);
if (!m_RegisteredMessages.ContainsKey(messageName))
m_RegisteredMessages.Add(messageName, new List<Message>());
if (!m_RegisteredMessages[messageName].Contains(message))
m_RegisteredMessages[messageName].Add(message);
m_RegisteredMessages[eventName] += message;
{
Debug.LogWarning(string.Format("Messager : {0} entry already contains reference to message.", messageName));
}
public static void RemoveMessage(string eventName, Message message)
public static void RemoveMessage(string messageName, Message message)
var currentEvent = m_RegisteredMessages[eventName];
currentEvent -= message;
if (currentEvent == null || currentEvent.GetInvocationList().Length == 0)
m_RegisteredMessages.Remove(eventName);
var currentEvent = m_RegisteredMessages[messageName];
if(currentEvent.Contains(message))
currentEvent.Remove(message);
if (currentEvent == null || currentEvent.Count == 0)
m_RegisteredMessages.Remove(messageName);
}
public static void Send(string eventName)

{
try
{
m_RegisteredMessages[eventName]();
foreach (var message in m_RegisteredMessages[eventName])
{
message.Invoke();
}
}
catch (Exception e)
{

正在加载...
取消
保存