You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.8 KiB

using System.Collections.Generic;
using UnityEngine;
using XWFramework.Tools;
namespace XWFramework.Events
{
public class EventManager : MonoSingleton<EventManager>
{
protected override void Awake()
{
base.Awake();
}
#region 有参数
public delegate void hasParamFun(params object[] args);
Dictionary<string, hasParamFun> hasParamEvents = new Dictionary<string, hasParamFun>();
public void register(string name, hasParamFun callback)
{
if (!hasParamEvents.ContainsKey(name))
{
hasParamEvents.Add(name, callback);
return;
}
hasParamEvents[name] += callback;
}
public void emit(string name, params object[] args)
{
if (hasParamEvents.ContainsKey(name))
{
hasParamEvents[name](args);
return;
}
Debug.Log("没有" + name + "事件");
}
#endregion
#region 无参数
public delegate void noParamFun();
Dictionary<string, noParamFun> noParamEvents = new Dictionary<string, noParamFun>();
public void register(string name, noParamFun callback)
{
if (!noParamEvents.ContainsKey(name))
{
noParamEvents.Add(name, callback);
return;
}
noParamEvents[name] = callback;
}
public void emit(string name)
{
if (noParamEvents.ContainsKey(name))
{
noParamEvents[name]();
}
//Debug.Log("没有" + name + "事件");
}
#endregion
public bool ContainKey(string value)
{
return hasParamEvents.ContainsKey(value) || noParamEvents.ContainsKey(value);
}
}
}