87 lines
2.1 KiB
C#
87 lines
2.1 KiB
C#
// ***********************************************************************
|
|
// Assembly : Unity
|
|
// Author : Kimch
|
|
// Created : 2018-03-28
|
|
//
|
|
// Last Modified By : Kimch
|
|
// Last Modified On :
|
|
// ***********************************************************************
|
|
// <copyright file= "GlobalEvent" company="DefaultCompany"></copyright>
|
|
// <summary></summary>
|
|
// ***********************************************************************
|
|
namespace G
|
|
{
|
|
using F.Events;
|
|
|
|
/// <summary>
|
|
/// 全局事件(不要使用匿名函数)
|
|
/// </summary>
|
|
public class GlobalEvent : EventBase
|
|
{
|
|
/// <summary>
|
|
/// 发送事件 投放到队列
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="id"></param>
|
|
/// <param name="args"></param>
|
|
public static void Send(object sender, int id, object args)
|
|
{
|
|
new GlobalEvent(id, args).Send(sender);
|
|
}
|
|
/// <summary>
|
|
/// 发送事件 立即执行
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="id"></param>
|
|
/// <param name="args"></param>
|
|
public static void SendImmediate(object sender, int id, object args)
|
|
{
|
|
new GlobalEvent(id, args).SendImmediate(sender);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 订阅事件
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="handler"></param>
|
|
public static void Subscribe(int id, System.EventHandler<EventBase> handler)
|
|
{
|
|
KFramework.EventManager.Subscribe(id, handler);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 取消订阅事件
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="handler"></param>
|
|
public static void Unsubscribe(int id, System.EventHandler<EventBase> handler)
|
|
{
|
|
KFramework.EventManager.Unsubscribe(id, handler);
|
|
}
|
|
|
|
public static void Unsubscribe(int id)
|
|
{
|
|
KFramework.EventManager.Unsubscribe(id);
|
|
}
|
|
|
|
private readonly int _eventId;
|
|
private readonly object _eventArgs;
|
|
|
|
private GlobalEvent(int id, object args)
|
|
{
|
|
_eventId = id;
|
|
_eventArgs = args;
|
|
}
|
|
|
|
public override int eventId
|
|
{
|
|
get { return _eventId; }
|
|
}
|
|
|
|
public override object eventArgs
|
|
{
|
|
get { return _eventArgs; }
|
|
}
|
|
}
|
|
}
|