100 lines
2.9 KiB
C#
100 lines
2.9 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using UnityEngine;
|
|
|
|
/*******************************************************************************
|
|
*Create By CG
|
|
*Function 事件中心管理
|
|
*******************************************************************************/
|
|
namespace CG.Framework
|
|
{
|
|
public class EventCenterManager : ClassSingleton<EventCenterManager>
|
|
{
|
|
//枚举-委托事件 可以通过找到订阅的事件
|
|
private Dictionary<EventEnum, EventHandler> _eventDic = new Dictionary<EventEnum, EventHandler>();
|
|
/// <summary>
|
|
/// 添加委托事件
|
|
/// </summary>
|
|
/// <param name="eventName"></param>
|
|
/// <param name="handler"></param>
|
|
public void AddEventListener(EventEnum eventName,EventHandler handler)
|
|
{
|
|
if (_eventDic.ContainsKey(eventName))
|
|
{
|
|
_eventDic[eventName] += handler;
|
|
}
|
|
else
|
|
{
|
|
_eventDic.Add(eventName, handler);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 发布者发布消息
|
|
/// </summary>
|
|
/// <param name="eventName">委托事件名字</param>
|
|
/// <param name="sander">发布者</param>
|
|
/// <param name="args">消息参数</param>
|
|
public void Dispatch(EventEnum eventName, object sander,EventArgs args)
|
|
{
|
|
if (_eventDic.ContainsKey(eventName))
|
|
{
|
|
_eventDic[eventName]?.Invoke(sander, args);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 移除委托内一个事件
|
|
/// </summary>
|
|
/// <param name="eventName"></param>
|
|
/// <param name="handler"></param>
|
|
public void RemoveListener(EventEnum eventName,EventHandler handler)
|
|
{
|
|
if (_eventDic.ContainsKey(eventName))
|
|
{
|
|
_eventDic[eventName] -= handler;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 移除委托事件
|
|
/// </summary>
|
|
/// <param name="eventName"></param>
|
|
public void RemoveEvent(EventEnum eventName)
|
|
{
|
|
if (_eventDic.ContainsKey(eventName))
|
|
{
|
|
_eventDic[eventName] = null;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 清除所有委托事件
|
|
/// </summary>
|
|
public void Clear()
|
|
{
|
|
foreach (var item in _eventDic.Keys)
|
|
{
|
|
_eventDic[item] = null;
|
|
}
|
|
_eventDic.Clear();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 鼠标双击空白处触发事件
|
|
/// </summary>
|
|
public class CameraDoubleClickNullArgs : EventArgs {
|
|
public string _groupShowName;
|
|
public string _onlyGeoName;
|
|
}
|
|
/// <summary>
|
|
/// 委托事件名字
|
|
/// </summary>
|
|
public enum EventEnum
|
|
{
|
|
/// <summary>
|
|
/// 鼠标双击空白处触发事件
|
|
/// </summary>
|
|
CameraDoubleClickNull
|
|
}
|
|
}
|
|
|