Selaa lähdekoodia

Added string-float and string-string generic events

James Peret 2 vuotta sitten
vanhempi
commit
961b962029
1 muutettua tiedostoa jossa 78 lisäystä ja 0 poistoa
  1. 78 0
      Runtime/EventManager/GenericEvents.cs

+ 78 - 0
Runtime/EventManager/GenericEvents.cs

@@ -241,6 +241,84 @@ namespace KairoEngine.Core
         }
         #endregion
 
+        #region String_float_Event
+        
+        public static Dictionary<string, System.Action<string, float>> stringFloatList = new Dictionary<string, System.Action<string, float>>();
+        
+        public static void StartListening(string title, System.Action<string, float> listener)
+        {
+            System.Action<string, float> action = null;
+            if (stringFloatList.TryGetValue(title, out action))
+            {
+                action += listener;
+                stringFloatList[title] = action;
+            }
+            else
+            {
+                action += listener;
+                stringFloatList.Add(title, action);
+            }
+        }
+
+        public static void StopListening(string title, System.Action<string, float> listener)
+        {
+            System.Action<string, float> action = null;
+            if (stringFloatList.TryGetValue(title, out action))
+            {
+                action -= listener;
+                stringFloatList[title] = action;
+            }
+        }
+
+        public static void Trigger(string title, string text, float value)
+        {
+            System.Action<string, float> action = null;
+            if (stringFloatList.TryGetValue(title, out action))
+            {
+                if(action != null) action(text, value);
+            }
+        }
+        #endregion
+
+        #region String_string_Event
+        
+        public static Dictionary<string, System.Action<string, string>> stringStringList = new Dictionary<string, System.Action<string, string>>();
+        
+        public static void StartListening(string title, System.Action<string, string> listener)
+        {
+            System.Action<string, string> action = null;
+            if (stringStringList.TryGetValue(title, out action))
+            {
+                action += listener;
+                stringStringList[title] = action;
+            }
+            else
+            {
+                action += listener;
+                stringStringList.Add(title, action);
+            }
+        }
+
+        public static void StopListening(string title, System.Action<string, string> listener)
+        {
+            System.Action<string, string> action = null;
+            if (stringStringList.TryGetValue(title, out action))
+            {
+                action -= listener;
+                stringStringList[title] = action;
+            }
+        }
+
+        public static void Trigger(string title, string text, string value)
+        {
+            System.Action<string, string> action = null;
+            if (stringStringList.TryGetValue(title, out action))
+            {
+                if(action != null) action(text, value);
+            }
+        }
+        #endregion
+
         #region ScriptableObject_Event
         
         public static Dictionary<string, System.Action<ScriptableObject>> list6 = new Dictionary<string, System.Action<ScriptableObject>>();