Created
July 7, 2016 07:34
-
-
Save YutaKaseda/ec74e89d9f146dd88d1959f3538fc2de to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
public class EventManager{ | |
static Dictionary<string,Action> evtHandler = new Dictionary<string, Action>(); | |
//keyだけを登録->(key,null) | |
//keyに対応したActionを登録->(key,Action) | |
public static void AddEvent(string key,Action action){ | |
if (evtHandler.ContainsKey(key)) | |
evtHandler [key] += action; | |
else | |
evtHandler.Add (key, action); | |
} | |
public static void RemoveEvent(string key,Action action){ | |
if (evtHandler.ContainsKey(key)) | |
evtHandler [key] -= action; | |
} | |
public static void InvokeEvent(string key){ | |
if(evtHandler.ContainsKey(key) && evtHandler[key] != null) | |
evtHandler [key] (); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment