using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace TFramework
{
///
/// 事件管理器
///
public class EventManager:BaseManager
{
private Dictionary _events = new Dictionary();
private Dictionary> events = new Dictionary>();
///
/// 注册事件
///
/// 事件类型
/// 事件
public void RegistEvent(Type type, TAction action)
{
if (events.ContainsKey(type))
events[type] += action;
else
events.Add(type, action);
}
///
/// 注册事件
///
/// 事件类型
/// 事件
public void RegistEvent(TAction action) => RegistEvent(typeof(T), action);
///
/// 派发事件
///
/// 事件数据
public void DispatchEvent(Type type, EventBase eventBase)=> events.TryGet(type)?.Invoke(eventBase);
///
/// 派发事件
///
/// 事件类型
public void DispatchEvent(EventBase eventBase) => events.TryGet(typeof(T))?.Invoke(eventBase);
///
/// 注销事件
///
/// 事件类型
/// 事件
public void UnRegist(Type type,TAction action)
{
if (events.ContainsKey(type))
events[type] -= action;
}
///
/// 注销事件
///
/// 事件类型
public void UnRegis(TAction action) => UnRegist(typeof(T), action);
}
}