我们创建了 Fontainebleau 演示来说明摄影photogrammetry流程和 LayeredLit 着色器的使用。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

68 行
2.3 KiB

using System;
using System.Collections.Generic;
using UnityEngine;
namespace GameplayIngredients
{
public static class Messager
{
public delegate void Message(GameObject instigator = null);
private static Dictionary<string, List<Message>> m_RegisteredMessages;
static Messager()
{
m_RegisteredMessages = new Dictionary<string, List<Message>>();
}
public static void RegisterMessage(string messageName, Message message)
{
if (!m_RegisteredMessages.ContainsKey(messageName))
m_RegisteredMessages.Add(messageName, new List<Message>());
if (!m_RegisteredMessages[messageName].Contains(message))
m_RegisteredMessages[messageName].Add(message);
else
{
Debug.LogWarning(string.Format("Messager : {0} entry already contains reference to message.", messageName));
}
}
public static void RemoveMessage(string messageName, Message message)
{
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, GameObject instigator = null)
{
if(GameplayIngredientsSettings.currentSettings.verboseCalls)
Debug.Log(string.Format("[MessageManager] Broadcast: {0}", eventName));
if (m_RegisteredMessages.ContainsKey(eventName))
{
try
{
foreach (var message in m_RegisteredMessages[eventName])
{
message.Invoke(instigator);
}
}
catch (Exception e)
{
Debug.LogError(string.Format("Messager : Caught {0} while sending Message {1}", e.GetType().Name, eventName));
Debug.LogException(e);
}
}
else
{
Debug.Log("[MessageManager] could not find any listeners for event : " + eventName);
}
}
}
}