using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class NotificationServer : MonoBehaviour { static Dictionary> notifications = new Dictionary>(); static Dictionary>> notificationsWithArgument = new Dictionary>>(); static public void register(string key, Action action) { if (!notifications.ContainsKey(key)) notifications[key] = new List(); if (!notifications[key].Contains(action)) notifications[key].Add(action); } static public void unregister(string key, Action action) { if (!notifications.ContainsKey(key)) return; if (!notifications[key].Contains(action)) return; notifications[key].Remove(action); } static public void notify(string key) { if (!notifications.ContainsKey(key)) return; for (int i=0; i action) { if (!notificationsWithArgument.ContainsKey(key)) notificationsWithArgument[key] = new List>(); if (!notificationsWithArgument[key].Contains(action)) notificationsWithArgument[key].Add(action); } static public void unregister(string key, Action action) { if (!notificationsWithArgument.ContainsKey(key)) return; if (!notificationsWithArgument[key].Contains(action)) return; notificationsWithArgument[key].Remove(action); } static public void notify(string key, object argument) { if (!notificationsWithArgument.ContainsKey(key)) return; for (int i=0; i