Skip to content

Instantly share code, notes, and snippets.

@YutaKaseda
Created July 7, 2016 07:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YutaKaseda/ec74e89d9f146dd88d1959f3538fc2de to your computer and use it in GitHub Desktop.
Save YutaKaseda/ec74e89d9f146dd88d1959f3538fc2de to your computer and use it in GitHub Desktop.
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