131 lines
3.6 KiB
C#
131 lines
3.6 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.ComponentModel;
|
|||
|
|
using UnityEngine;
|
|||
|
|
|
|||
|
|
/*******************************************************************************
|
|||
|
|
*Create By CG
|
|||
|
|
*Function 事件中心管理
|
|||
|
|
*******************************************************************************/
|
|||
|
|
namespace ZXK.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 ChangeModelArgs : EventArgs {
|
|||
|
|
public UTility.EnumCtrl.Model _Model;
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 使用工具组装相关参数
|
|||
|
|
/// </summary>
|
|||
|
|
public class ToolArgs : EventArgs
|
|||
|
|
{
|
|||
|
|
public string _ToolName;
|
|||
|
|
public Sprite _ToolImg;
|
|||
|
|
}
|
|||
|
|
public class ClickEquipmentArgs : EventArgs
|
|||
|
|
{
|
|||
|
|
public BYSS.EquipmentInfo info;
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 委托事件名字
|
|||
|
|
/// </summary>
|
|||
|
|
public enum EventEnum
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// 采集工具
|
|||
|
|
/// </summary>
|
|||
|
|
PickTool,
|
|||
|
|
/// <summary>
|
|||
|
|
/// 点击设备
|
|||
|
|
/// </summary>
|
|||
|
|
ClickEquipment,
|
|||
|
|
/// <summary>
|
|||
|
|
/// 拆卸设备
|
|||
|
|
/// </summary>
|
|||
|
|
SplitEquipment,
|
|||
|
|
/// <summary>
|
|||
|
|
/// 合成设备
|
|||
|
|
/// </summary>
|
|||
|
|
CombineEquipment,
|
|||
|
|
/// <summary>
|
|||
|
|
/// 跟进组装操作步骤
|
|||
|
|
/// </summary>
|
|||
|
|
ChangeProcess,
|
|||
|
|
/// <summary>
|
|||
|
|
/// 自动接线
|
|||
|
|
/// </summary>
|
|||
|
|
AutoConnect
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|