mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
提交
This commit is contained in:
3
JNFrame2/Assets/Plugins/SHFrame/Runtime/Core/Event.meta
Normal file
3
JNFrame2/Assets/Plugins/SHFrame/Runtime/Core/Event.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1398040438c14d5283657f570b57a31e
|
||||
timeCreated: 1729011976
|
@@ -0,0 +1,25 @@
|
||||
namespace SHFrame
|
||||
{
|
||||
/// <summary> 事件参数
|
||||
/// <para>ZhangYu 2019-03-05</para>
|
||||
/// </summary>
|
||||
public class EventArgs
|
||||
{
|
||||
/// <summary> 事件类型 </summary>
|
||||
public readonly string type;
|
||||
|
||||
/// <summary> 事件参数 </summary>
|
||||
public readonly object[] args;
|
||||
|
||||
public EventArgs(string type)
|
||||
{
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public EventArgs(string type, params object[] args)
|
||||
{
|
||||
this.type = type;
|
||||
this.args = args;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b8bc2c30ad9668644ba298f980f2eda6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,74 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SHFrame
|
||||
{
|
||||
/// <summary>
|
||||
/// 事件派发器
|
||||
/// <para>ZhangYu 2019-03-05</para>
|
||||
/// </summary>
|
||||
public class EventDispatcher
|
||||
{
|
||||
/// <summary> 事件Map </summary>
|
||||
private Dictionary<string, EventListener> dic = new Dictionary<string, EventListener>();
|
||||
|
||||
/// <summary> 添加事件监听器 </summary>
|
||||
/// <param name="eventType">事件类型</param>
|
||||
/// <param name="eventHandler">事件处理器</param>
|
||||
public void AddListener(string eventType, EventListener.EventHandler eventHandler)
|
||||
{
|
||||
EventListener invoker;
|
||||
if (!dic.TryGetValue(eventType, out invoker))
|
||||
{
|
||||
invoker = new EventListener();
|
||||
dic.Add(eventType, invoker);
|
||||
}
|
||||
invoker.eventHandler += eventHandler;
|
||||
}
|
||||
|
||||
/// <summary> 移除事件监听器 </summary>
|
||||
/// <param name="eventType">事件类型</param>
|
||||
/// <param name="eventHandler">事件处理器</param>
|
||||
public void RemoveListener(string eventType, EventListener.EventHandler eventHandler)
|
||||
{
|
||||
EventListener invoker;
|
||||
if (dic.TryGetValue(eventType, out invoker)) invoker.eventHandler -= eventHandler;
|
||||
}
|
||||
|
||||
/// <summary> 是否已经拥有该类型的事件 </summary>
|
||||
/// <param name="eventType">事件类型</param>
|
||||
public bool HasListener(string eventType)
|
||||
{
|
||||
return dic.ContainsKey(eventType);
|
||||
}
|
||||
|
||||
/// <summary> 派发事件 </summary>
|
||||
/// <param name="eventType">事件类型</param>
|
||||
public void DispatchEvent(string eventType, params object[] args)
|
||||
{
|
||||
EventListener invoker;
|
||||
if (dic.TryGetValue(eventType, out invoker))
|
||||
{
|
||||
EventArgs evt;
|
||||
if (args == null || args.Length == 0)
|
||||
{
|
||||
evt = new EventArgs(eventType);
|
||||
}
|
||||
else
|
||||
{
|
||||
evt = new EventArgs(eventType, args);
|
||||
}
|
||||
invoker.Invoke(evt);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> 清理所有事件监听器 </summary>
|
||||
public void Clear()
|
||||
{
|
||||
foreach (EventListener value in dic.Values)
|
||||
{
|
||||
value.Clear();
|
||||
}
|
||||
dic.Clear();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1303100c362aa10459237b5ad8617f4b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,27 @@
|
||||
namespace SHFrame
|
||||
{
|
||||
/// <summary>
|
||||
/// 事件监听器
|
||||
/// <para>ZhangYu 2019-03-05</para>
|
||||
/// </summary>
|
||||
public class EventListener
|
||||
{
|
||||
/// <summary> 事件处理器委托 </summary>
|
||||
public delegate void EventHandler(EventArgs eventArgs);
|
||||
|
||||
/// <summary> 事件处理器集合 </summary>
|
||||
public EventHandler eventHandler;
|
||||
|
||||
/// <summary> 调用所有添加的事件 </summary>
|
||||
public void Invoke(EventArgs eventArgs)
|
||||
{
|
||||
if (eventHandler != null) eventHandler.Invoke(eventArgs);
|
||||
}
|
||||
|
||||
/// <summary> 清理所有事件委托 </summary>
|
||||
public void Clear()
|
||||
{
|
||||
eventHandler = null;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dae197cb1d1228547a2af3254650955a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,53 @@
|
||||
namespace SHFrame
|
||||
{
|
||||
/// <summary>
|
||||
/// 事件工具
|
||||
/// <para>ZhangYu 2019-03-04</para>
|
||||
/// </summary>
|
||||
public static class EventUtil
|
||||
{
|
||||
/// <summary> 事件派发器 </summary>
|
||||
private static EventDispatcher dispatcher = new EventDispatcher();
|
||||
|
||||
/// <summary> 添加事件监听器 </summary>
|
||||
/// <param name="eventType">事件类型</param>
|
||||
/// <param name="eventHandler">事件处理器</param>
|
||||
public static void AddListener(string eventType, EventListener.EventHandler eventHandler)
|
||||
{
|
||||
dispatcher.AddListener(eventType, eventHandler);
|
||||
}
|
||||
|
||||
/// <summary> 移除事件监听器 </summary>
|
||||
/// <param name="eventType">事件类型</param>
|
||||
/// <param name="eventHandler">事件处理器</param>
|
||||
public static void RemoveListener(string eventType, EventListener.EventHandler eventHandler)
|
||||
{
|
||||
dispatcher.RemoveListener(eventType, eventHandler);
|
||||
}
|
||||
|
||||
/// <summary> 是否已经拥有该类型的事件 </summary>
|
||||
/// <param name="eventType">事件类型</param>
|
||||
public static bool HasListener(string eventType)
|
||||
{
|
||||
return dispatcher.HasListener(eventType);
|
||||
}
|
||||
|
||||
/// <summary> 派发事件 </summary>
|
||||
/// <param name="eventType">事件类型</param>
|
||||
public static void DispatchEvent(string eventType, params object[] args)
|
||||
{
|
||||
dispatcher.DispatchEvent(eventType, args);
|
||||
}
|
||||
|
||||
/// <summary> 清理所有事件监听器 </summary>
|
||||
public static void Clear()
|
||||
{
|
||||
dispatcher.Clear();
|
||||
}
|
||||
|
||||
// public static void DispatchEvent(string updateItemOrCard, object updateExpCard)
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dd0630485bf39a24fb4fbf8a933447af
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user