事件系统优化更新

事件系统优化更新
1.使用静态代替单例,静态方法调用时候内存地址无需二次偏移定位
2.UI事件在关闭UI时自动反监听
This commit is contained in:
ALEXTANG
2022-10-26 15:14:04 +08:00
parent 2e175fbcac
commit 74092e6399
37 changed files with 905 additions and 1187 deletions

View File

@@ -7,17 +7,19 @@ namespace TEngine.Runtime
/// </summary> /// </summary>
public class ProcedureResourcesInit : ProcedureBase public class ProcedureResourcesInit : ProcedureBase
{ {
public static int OnInitResourceCompleteEvent = StringId.StringToHash("OnInitResourceComplete");
private bool m_initResourceComplete = false; private bool m_initResourceComplete = false;
protected override void OnEnter(IFsm<IProcedureManager> procedureOwner) protected override void OnEnter(IFsm<IProcedureManager> procedureOwner)
{ {
base.OnEnter(procedureOwner); base.OnEnter(procedureOwner);
GameEventMgr.Instance.AddEventListener("OnInitResourceComplete", OnInitResourceComplete); GameEvent.AddEventListener(OnInitResourceCompleteEvent, OnInitResourceComplete);
m_initResourceComplete = false; m_initResourceComplete = false;
LoaderUtilities.DelayFun((() => LoaderUtilities.DelayFun((() =>
{ {
GameEventMgr.Instance.Send("OnInitResourceComplete"); GameEvent.Send(OnInitResourceCompleteEvent);
}),new WaitForSeconds(1f)); }),new WaitForSeconds(1f));
} }
@@ -35,7 +37,7 @@ namespace TEngine.Runtime
protected override void OnLeave(IFsm<IProcedureManager> procedureOwner, bool isShutdown) protected override void OnLeave(IFsm<IProcedureManager> procedureOwner, bool isShutdown)
{ {
base.OnLeave(procedureOwner, isShutdown); base.OnLeave(procedureOwner, isShutdown);
GameEventMgr.Instance.RemoveEventListener("OnInitResourceComplete", OnInitResourceComplete); GameEvent.RemoveEventListener(OnInitResourceCompleteEvent, OnInitResourceComplete);
} }
private void OnInitResourceComplete() private void OnInitResourceComplete()

View File

@@ -18,7 +18,7 @@ namespace TEngine.Runtime
{ {
base.OnEnter(procedureOwner); base.OnEnter(procedureOwner);
GameEventMgr.Instance.AddEventListener<bool>("DownLoadResult.AllDownLoaded",AllDownLoaded); GameEvent.AddEventListener<bool>(LoadMgr.DownLoadFinish,AllDownLoaded);
_procedureOwner = procedureOwner; _procedureOwner = procedureOwner;

View File

@@ -13,7 +13,7 @@
protected override void OnEnter(IFsm<IProcedureManager> procedureOwner) protected override void OnEnter(IFsm<IProcedureManager> procedureOwner)
{ {
base.OnEnter(procedureOwner); base.OnEnter(procedureOwner);
GameEventMgr.Instance.Send(TEngineEvent.OnStartGame); GameEvent.Send(TEngineEvent.OnStartGame);
} }
} }
} }

View File

@@ -11,7 +11,7 @@ public class DemoMain : MonoBehaviour
{ {
//Demo示例监听TEngine流程加载器OnStartGame事件 //Demo示例监听TEngine流程加载器OnStartGame事件
//抛出这个事件说明框架流程加载完成(热更新,初始化等) //抛出这个事件说明框架流程加载完成(热更新,初始化等)
GameEventMgr.Instance.AddEventListener(TEngineEvent.OnStartGame,OnStartGame); GameEvent.AddEventListener(TEngineEvent.OnStartGame,OnStartGame);
} }
private void OnStartGame() private void OnStartGame()

View File

@@ -11,7 +11,7 @@ public class ActorTestMain : MonoBehaviour
{ {
//Demo示例监听TEngine流程加载器OnStartGame事件 //Demo示例监听TEngine流程加载器OnStartGame事件
//抛出这个事件说明框架流程加载完成(热更新,初始化等) //抛出这个事件说明框架流程加载完成(热更新,初始化等)
GameEventMgr.Instance.AddEventListener(TEngineEvent.OnStartGame,OnStartGame); GameEvent.AddEventListener(TEngineEvent.OnStartGame,OnStartGame);
} }
private void OnStartGame() private void OnStartGame()

View File

@@ -17,9 +17,9 @@ namespace TEngine.Runtime.Actor
/// </summary> /// </summary>
void RegisterEvent() void RegisterEvent()
{ {
GameEventMgr.Instance.AddEventListener<IEntity, float, object>(EntityEvent.ShowEntitySuccess, OnShowEntitySuccess); GameEvent.AddEventListener<IEntity, float, object>(EntityEvent.ShowEntitySuccess, OnShowEntitySuccess);
GameEventMgr.Instance.AddEventListener<int, string, string, string, object>(EntityEvent.ShowEntityFailure, OnShowEntityFailure); GameEvent.AddEventListener<int, string, string, string, object>(EntityEvent.ShowEntityFailure, OnShowEntityFailure);
GameEventMgr.Instance.AddEventListener<int, string, IEntityGroup, object>(EntityEvent.HideEntityComplete, OnHideEntityComplete); GameEvent.AddEventListener<int, string, IEntityGroup, object>(EntityEvent.HideEntityComplete, OnHideEntityComplete);
} }
/// <summary> /// <summary>

View File

@@ -11,7 +11,7 @@ public class EntityTestMain : MonoBehaviour
{ {
//Demo示例监听TEngine流程加载器OnStartGame事件 //Demo示例监听TEngine流程加载器OnStartGame事件
//抛出这个事件说明框架流程加载完成(热更新,初始化等) //抛出这个事件说明框架流程加载完成(热更新,初始化等)
GameEventMgr.Instance.AddEventListener(TEngineEvent.OnStartGame,OnStartGame); GameEvent.AddEventListener(TEngineEvent.OnStartGame,OnStartGame);
} }
private void OnStartGame() private void OnStartGame()

View File

@@ -40,9 +40,9 @@ namespace TEngine.Demo.TEngine.EntityDemo
/// </summary> /// </summary>
void RegisterEvent() void RegisterEvent()
{ {
GameEventMgr.Instance.AddEventListener<IEntity, float, object>(EntityEvent.ShowEntitySuccess, OnShowEntitySuccess); GameEvent.AddEventListener<IEntity, float, object>(EntityEvent.ShowEntitySuccess, OnShowEntitySuccess);
GameEventMgr.Instance.AddEventListener<int, string, string, string, object>(EntityEvent.ShowEntityFailure, OnShowEntityFailure); GameEvent.AddEventListener<int, string, string, string, object>(EntityEvent.ShowEntityFailure, OnShowEntityFailure);
GameEventMgr.Instance.AddEventListener<int, string, IEntityGroup, object>(EntityEvent.HideEntityComplete, OnHideEntityComplete); GameEvent.AddEventListener<int, string, IEntityGroup, object>(EntityEvent.HideEntityComplete, OnHideEntityComplete);
} }
/// <summary> /// <summary>

View File

@@ -16,7 +16,7 @@ public class NetTestMain : MonoBehaviour
{ {
//Demo示例监听TEngine流程加载器OnStartGame事件 //Demo示例监听TEngine流程加载器OnStartGame事件
//抛出这个事件说明框架流程加载完成(热更新,初始化等) //抛出这个事件说明框架流程加载完成(热更新,初始化等)
GameEventMgr.Instance.AddEventListener(TEngineEvent.OnStartGame,OnStartGame); GameEvent.AddEventListener(TEngineEvent.OnStartGame,OnStartGame);
} }

View File

@@ -0,0 +1,181 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &6402266109080598536
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 4817885892919467575}
- component: {fileID: 7802103059775820765}
- component: {fileID: 7249197984681057450}
m_Layer: 5
m_Name: m_text233
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &4817885892919467575
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6402266109080598536}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 3174286174385965140}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 160, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &7802103059775820765
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6402266109080598536}
m_CullTransparentMesh: 1
--- !u!114 &7249197984681057450
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6402266109080598536}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 14
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 10
m_MaxSize: 40
m_Alignment: 0
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: New Text
--- !u!1 &8235976447969581174
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 3174286174385965140}
- component: {fileID: 1003415184935212904}
- component: {fileID: 1919534446368215616}
- component: {fileID: 4766758077184901772}
m_Layer: 5
m_Name: TestUI
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &3174286174385965140
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8235976447969581174}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0, y: 0, z: 0}
m_Children:
- {fileID: 4817885892919467575}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 0}
--- !u!223 &1003415184935212904
Canvas:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8235976447969581174}
m_Enabled: 1
serializedVersion: 3
m_RenderMode: 0
m_Camera: {fileID: 0}
m_PlaneDistance: 100
m_PixelPerfect: 0
m_ReceivesEvents: 1
m_OverrideSorting: 0
m_OverridePixelPerfect: 0
m_SortingBucketNormalizedSize: 0
m_AdditionalShaderChannelsFlag: 0
m_SortingLayerID: 0
m_SortingOrder: 0
m_TargetDisplay: 0
--- !u!114 &1919534446368215616
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8235976447969581174}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3}
m_Name:
m_EditorClassIdentifier:
m_UiScaleMode: 0
m_ReferencePixelsPerUnit: 100
m_ScaleFactor: 1
m_ReferenceResolution: {x: 800, y: 600}
m_ScreenMatchMode: 0
m_MatchWidthOrHeight: 0
m_PhysicalUnit: 3
m_FallbackScreenDPI: 96
m_DefaultSpriteDPI: 96
m_DynamicPixelsPerUnit: 1
m_PresetInfoIsWorld: 0
--- !u!114 &4766758077184901772
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8235976447969581174}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: dc42784cf147c0c48a680349fa168899, type: 3}
m_Name:
m_EditorClassIdentifier:
m_IgnoreReversedGraphics: 1
m_BlockingObjects: 0
m_BlockingMask:
serializedVersion: 2
m_Bits: 4294967295

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 8da8ae71cd1ab564fb2735b351ee48a0
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,34 @@
using TEngine;
using TEngine.Runtime;
using UnityEngine;
using UnityEngine.UI;
using TEngine.Runtime.UIModule;
class TestUI : UIWindow
{
public static int TestEvent = StringId.StringToHash("TestEvent");
#region
private Text m_text233;
protected override void ScriptGenerator()
{
m_text233 = FindChildComponent<Text>("m_text233");
}
#endregion
protected override void RegisterEvent()
{
base.RegisterEvent();
AddUIEvent(TestEvent,Test);
}
private void Test()
{
Log.Fatal("Test Trigger");
}
#region
#endregion
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0ec109ee7f6e49e796052056bacefbcf
timeCreated: 1666767723

View File

@@ -38,12 +38,12 @@ RenderSettings:
m_ReflectionIntensity: 1 m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0} m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0} m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1} m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1}
m_UseRadianceAmbientProbe: 0 m_UseRadianceAmbientProbe: 0
--- !u!157 &3 --- !u!157 &3
LightmapSettings: LightmapSettings:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
serializedVersion: 11 serializedVersion: 12
m_GIWorkflowMode: 1 m_GIWorkflowMode: 1
m_GISettings: m_GISettings:
serializedVersion: 2 serializedVersion: 2
@@ -98,7 +98,7 @@ LightmapSettings:
m_TrainingDataDestination: TrainingData m_TrainingDataDestination: TrainingData
m_LightProbeSampleCountMultiplier: 4 m_LightProbeSampleCountMultiplier: 4
m_LightingDataAsset: {fileID: 0} m_LightingDataAsset: {fileID: 0}
m_UseShadowmask: 1 m_LightingSettings: {fileID: 0}
--- !u!196 &4 --- !u!196 &4
NavMeshSettings: NavMeshSettings:
serializedVersion: 2 serializedVersion: 2
@@ -118,6 +118,8 @@ NavMeshSettings:
manualTileSize: 0 manualTileSize: 0
tileSize: 256 tileSize: 256
accuratePlacement: 0 accuratePlacement: 0
maxJobWorkers: 0
preserveTilesOutsideBounds: 0
debug: debug:
m_Flags: 0 m_Flags: 0
m_NavMeshData: {fileID: 0} m_NavMeshData: {fileID: 0}
@@ -240,6 +242,7 @@ Light:
m_UseColorTemperature: 0 m_UseColorTemperature: 0
m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0} m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
m_UseBoundingSphereOverride: 0 m_UseBoundingSphereOverride: 0
m_UseViewFrustumForShadowCasterCull: 1
m_ShadowRadius: 0 m_ShadowRadius: 0
m_ShadowAngle: 0 m_ShadowAngle: 0
--- !u!4 &1274323984 --- !u!4 &1274323984
@@ -356,13 +359,13 @@ PrefabInstance:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3463045026010536330, guid: 161ff7c8132079c4a95e2e4e70ddd41b, - target: {fileID: 3463045026010536330, guid: 161ff7c8132079c4a95e2e4e70ddd41b,
type: 3} type: 3}
propertyPath: m_ResourceHelperTypeName propertyPath: ResourceMode
value: TEngine.Runtime.UnityResourceHelper value: 1
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3463045026010536330, guid: 161ff7c8132079c4a95e2e4e70ddd41b, - target: {fileID: 3463045026010536330, guid: 161ff7c8132079c4a95e2e4e70ddd41b,
type: 3} type: 3}
propertyPath: ResourceMode propertyPath: m_ResourceHelperTypeName
value: 3 value: TEngine.Runtime.UnityResourceHelper
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3463045026180535776, guid: 161ff7c8132079c4a95e2e4e70ddd41b, - target: {fileID: 3463045026180535776, guid: 161ff7c8132079c4a95e2e4e70ddd41b,
type: 3} type: 3}
@@ -427,7 +430,7 @@ PrefabInstance:
- target: {fileID: 3463045026377943191, guid: 161ff7c8132079c4a95e2e4e70ddd41b, - target: {fileID: 3463045026377943191, guid: 161ff7c8132079c4a95e2e4e70ddd41b,
type: 3} type: 3}
propertyPath: m_EntranceProcedureTypeName propertyPath: m_EntranceProcedureTypeName
value: TEngine.Runtime.ProcedureCodeInit value: TEngine.Runtime.ProcedureLaunch
objectReference: {fileID: 0} objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 161ff7c8132079c4a95e2e4e70ddd41b, type: 3} m_SourcePrefab: {fileID: 100100000, guid: 161ff7c8132079c4a95e2e4e70ddd41b, type: 3}

View File

@@ -10,9 +10,10 @@ public class UITestMain : MonoBehaviour
{ {
//Demo示例监听TEngine流程加载器OnStartGame事件 //Demo示例监听TEngine流程加载器OnStartGame事件
//抛出这个事件说明框架流程加载完成(热更新,初始化等) //抛出这个事件说明框架流程加载完成(热更新,初始化等)
GameEventMgr.Instance.AddEventListener(TEngineEvent.OnStartGame,OnStartGame); GameEvent.AddEventListener(TEngineEvent.OnStartGame,OnStartGame);
} }
private int _loopTime = 0;
/// <summary> /// <summary>
/// OnStartGame /// OnStartGame
/// </summary> /// </summary>
@@ -20,5 +21,17 @@ public class UITestMain : MonoBehaviour
{ {
// 激活UI系统 // 激活UI系统
UISys.Instance.Active(); UISys.Instance.Active();
UISys.Mgr.ShowWindow<TestUI>();
TimerMgr.Instance.AddTimer((args =>
{
_loopTime++;
GameEvent.Send(TestUI.TestEvent);
if (_loopTime > 7)
{
UISys.Mgr.CloseWindow<TestUI>();
}
}), 1f, true);
} }
} }

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a7f4494cbe10422e98e459dcf2af76a8
timeCreated: 1666765074

View File

@@ -0,0 +1,265 @@
using System;
using System.Collections.Generic;
namespace TEngine.Runtime
{
class DEventDelegateData
{
private int m_eventType = 0;
public List<Delegate> m_listExist = new List<Delegate>();
private List<Delegate> m_addList = new List<Delegate>();
private List<Delegate> m_deleteList = new List<Delegate>();
private bool m_isExcute = false;
private bool m_dirty = false;
public DEventDelegateData(int evnetType)
{
m_eventType = evnetType;
}
public bool AddHandler(Delegate handler)
{
if (m_listExist.Contains(handler))
{
Log.Fatal("Repeated Add Handler");
return false;
}
if (m_isExcute)
{
m_dirty = true;
m_addList.Add(handler);
}
else
{
m_listExist.Add(handler);
}
return true;
}
public void RmvHandler(Delegate hander)
{
if (m_isExcute)
{
m_dirty = true;
m_deleteList.Add(hander);
}
else
{
if (!m_listExist.Remove(hander))
{
Log.Fatal("Delete handle failed, not exist, EventId: {0}", StringId.HashToString(m_eventType));
}
}
}
private void CheckModify()
{
m_isExcute = false;
if (m_dirty)
{
for (int i = 0; i < m_addList.Count; i++)
{
m_listExist.Add(m_addList[i]);
}
m_addList.Clear();
for (int i = 0; i < m_deleteList.Count; i++)
{
m_listExist.Remove(m_deleteList[i]);
}
m_deleteList.Clear();
}
}
public void Callback()
{
m_isExcute = true;
for (var i = 0; i < m_listExist.Count; i++)
{
var d = m_listExist[i];
Action action = d as Action;
if (action != null)
{
action();
}
}
CheckModify();
}
public void Callback<T>(T arg1)
{
m_isExcute = true;
for (var i = 0; i < m_listExist.Count; i++)
{
var d = m_listExist[i];
var action = d as Action<T>;
if (action != null)
{
action(arg1);
}
}
CheckModify();
}
public void Callback<T, U>(T arg1, U arg2)
{
m_isExcute = true;
for (var i = 0; i < m_listExist.Count; i++)
{
var d = m_listExist[i];
var action = d as Action<T, U>;
if (action != null)
{
action(arg1, arg2);
}
}
CheckModify();
}
public void Callback<T, U, V>(T arg1, U arg2, V arg3)
{
m_isExcute = true;
for (var i = 0; i < m_listExist.Count; i++)
{
var d = m_listExist[i];
var action = d as Action<T, U, V>;
if (action != null)
{
action(arg1, arg2, arg3);
}
}
CheckModify();
}
public void Callback<T, U, V, W>(T arg1, U arg2, V arg3, W arg4)
{
m_isExcute = true;
for (var i = 0; i < m_listExist.Count; i++)
{
var d = m_listExist[i];
var action = d as Action<T, U, V, W>;
if (action != null)
{
action(arg1, arg2, arg3, arg4);
}
}
CheckModify();
}
public void Callback<T, U, V, W, X>(T arg1, U arg2, V arg3, W arg4, X arg5)
{
m_isExcute = true;
for (var i = 0; i < m_listExist.Count; i++)
{
var d = m_listExist[i];
var action = d as Action<T, U, V, W, X>;
if (action != null)
{
action(arg1, arg2, arg3, arg4, arg5);
}
}
CheckModify();
}
}
/// <summary>
/// 封装消息的底层分发和注册
/// </summary>
class DEventDispatcher
{
static Dictionary<int, DEventDelegateData> m_eventTable = new Dictionary<int, DEventDelegateData>();
#region
public bool AddEventListener(int eventType, Delegate handler)
{
DEventDelegateData data;
if (!m_eventTable.TryGetValue(eventType, out data))
{
data = new DEventDelegateData(eventType);
m_eventTable.Add(eventType, data);
}
return data.AddHandler(handler);
}
public void RemoveEventListener(int eventType, Delegate handler)
{
DEventDelegateData data;
if (m_eventTable.TryGetValue(eventType, out data))
{
data.RmvHandler(handler);
}
}
#endregion
#region
public void Send(int eventType)
{
DEventDelegateData d;
if (m_eventTable.TryGetValue(eventType, out d))
{
d.Callback();
}
}
public void Send<T>(int eventType, T arg1)
{
DEventDelegateData d;
if (m_eventTable.TryGetValue(eventType, out d))
{
d.Callback(arg1);
}
}
public void Send<T, U>(int eventType, T arg1, U arg2)
{
DEventDelegateData d;
if (m_eventTable.TryGetValue(eventType, out d))
{
d.Callback(arg1, arg2);
}
}
public void Send<T, U, V>(int eventType, T arg1, U arg2, V arg3)
{
DEventDelegateData d;
if (m_eventTable.TryGetValue(eventType, out d))
{
d.Callback(arg1, arg2, arg3);
}
}
public void Send<T, U, V, W>(int eventType, T arg1, U arg2, V arg3, W arg4)
{
DEventDelegateData d;
if (m_eventTable.TryGetValue(eventType, out d))
{
d.Callback(arg1, arg2, arg3, arg4);
}
}
public void Send<T, U, V, W, X>(int eventType, T arg1, U arg2, V arg3, W arg4, X arg5)
{
DEventDelegateData d;
if (m_eventTable.TryGetValue(eventType, out d))
{
d.Callback(arg1, arg2, arg3, arg4, arg5);
}
}
#endregion
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ff8f95404d2a458682f4eca4cdbc93f0
timeCreated: 1666765082

View File

@@ -0,0 +1,27 @@
using System;
namespace TEngine.Runtime
{
public enum DEventGroup
{
/// <summary>
/// UI相关的交互
/// </summary>
GroupUI,
/// <summary>
/// 逻辑层内部相关的交互
/// </summary>
GroupLogic,
}
[System.AttributeUsage(System.AttributeTargets.Interface)]
public class DEventInterface : Attribute
{
public DEventGroup m_group;
public DEventInterface(DEventGroup group)
{
m_group = group;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a1bd30ea28cb457ea60b77c28fad0a2b
timeCreated: 1666765181

View File

@@ -0,0 +1,51 @@
using System.Collections.Generic;
namespace TEngine.Runtime
{
internal class DEventEntryData
{
public object m_interfaceWrap;
};
class DEventMgr
{
private DEventDispatcher m_dispatcher = new DEventDispatcher();
/// <summary>
/// 封装了调用的代理函数
/// </summary>
private Dictionary<string, DEventEntryData> m_entry = new Dictionary<string, DEventEntryData>();
public T GetInterface<T>()
{
string typeName = typeof(T).FullName;
DEventEntryData entry;
if (m_entry.TryGetValue(typeName, out entry))
{
return (T)entry.m_interfaceWrap;
}
return default(T);
}
/// <summary>
/// 注册wrap的函数
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="callerWrap"></param>
public void RegWrapInterface<T>(T callerWrap)
{
string typeName = typeof(T).FullName;
Log.Assert(!m_entry.ContainsKey(typeName));
var entry = new DEventEntryData();
entry.m_interfaceWrap = callerWrap;
m_entry.Add(typeName, entry);
}
public DEventDispatcher GetDispatcher()
{
return m_dispatcher;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5313d1a916d548028065c2de344836f3
timeCreated: 1666765217

View File

@@ -0,0 +1,128 @@
using System;
namespace TEngine.Runtime
{
public class GameEvent
{
private static DEventMgr m_mgr = new DEventMgr();
public static void Init()
{
// RegisterEventInterface_Logic.Register(m_mgr);
// RegisterEventInterface_UI.Register(m_mgr);
}
#region
public static bool AddEventListener(int eventType, Action handler)
{
return m_mgr.GetDispatcher().AddEventListener(eventType, handler);
}
public static bool AddEventListener<T>(int eventType, Action<T> handler)
{
return m_mgr.GetDispatcher().AddEventListener(eventType, handler);
}
public static bool AddEventListener<T, U>(int eventType, Action<T, U> handler)
{
return m_mgr.GetDispatcher().AddEventListener(eventType, handler);
}
public static bool AddEventListener<T, U, V>(int eventType, Action<T, U, V> handler)
{
return m_mgr.GetDispatcher().AddEventListener(eventType, handler);
}
public static bool AddEventListener<T, U, V, W>(int eventType, Action<T, U, V, W> handler)
{
return m_mgr.GetDispatcher().AddEventListener(eventType, handler);
}
public static bool AddEventListener<T, U, V, W, X>(int eventType, Action<T, U, V, W, X> handler)
{
return m_mgr.GetDispatcher().AddEventListener(eventType, handler);
}
public static void RemoveEventListener(int eventType, Action handler)
{
m_mgr.GetDispatcher().RemoveEventListener(eventType, handler);
}
public static void RemoveEventListener<T>(int eventType, Action<T> handler)
{
m_mgr.GetDispatcher().RemoveEventListener(eventType, handler);
}
public static void RemoveEventListener<T, U>(int eventType, Action<T, U> handler)
{
m_mgr.GetDispatcher().RemoveEventListener(eventType, handler);
}
public static void RemoveEventListener<T, U, V>(int eventType, Action<T, U, V> handler)
{
m_mgr.GetDispatcher().RemoveEventListener(eventType, handler);
}
public static void RemoveEventListener<T, U, V, W>(int eventType, Action<T, U, V, W> handler)
{
m_mgr.GetDispatcher().RemoveEventListener(eventType, handler);
}
public static void RemoveEventListener<T, U, V, W, X>(int eventType, Action<T, U, V, W, X> handler)
{
m_mgr.GetDispatcher().RemoveEventListener(eventType, handler);
}
public static void RemoveEventListener(int eventType, Delegate handler)
{
m_mgr.GetDispatcher().RemoveEventListener(eventType, handler);
}
#endregion
#region
public static T Get<T>()
{
return m_mgr.GetInterface<T>();
}
public static void Send(int eventType)
{
m_mgr.GetDispatcher().Send(eventType);
}
public static void Send<T>(int eventType, T arg1)
{
m_mgr.GetDispatcher().Send(eventType, arg1);
}
public static void Send<T, U>(int eventType, T arg1, U arg2)
{
m_mgr.GetDispatcher().Send(eventType, arg1, arg2);
}
public static void Send<T, U, V>(int eventType, T arg1, U arg2, V arg3)
{
m_mgr.GetDispatcher().Send(eventType, arg1, arg2, arg3);
}
public static void Send<T, U, V, W>(int eventType, T arg1, U arg2, V arg3, W arg4)
{
m_mgr.GetDispatcher().Send(eventType, arg1, arg2, arg3);
}
public static void Send<T, U, V, W, X>(int eventType, T arg1, U arg2, V arg3, W arg4, X arg5)
{
m_mgr.GetDispatcher().Send(eventType, arg1, arg2, arg3, arg4, arg5);
}
public static void Send(int eventType, Delegate handler)
{
m_mgr.GetDispatcher().Send(eventType, handler);
}
#endregion
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ce11e95182ff4ac8928b21c833fe1d0b
timeCreated: 1666765360

View File

@@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
namespace TEngine.Runtime
{
public class GameEventMgr : IMemory
{
private List<int> m_listEventTypes;
private List<Delegate> m_listHandles;
private bool m_isInit = false;
public GameEventMgr()
{
if (m_isInit)
{
return;
}
m_isInit = true;
m_listEventTypes = new List<int>();
m_listHandles = new List<Delegate>();
}
public void Clear()
{
if (!m_isInit)
{
return;
}
for (int i = 0; i < m_listEventTypes.Count; ++i)
{
var eventType = m_listEventTypes[i];
var handle = m_listHandles[i];
GameEvent.RemoveEventListener(eventType, handle);
}
m_listEventTypes.Clear();
m_listHandles.Clear();
}
private void AddEvent(int eventType, Delegate handler)
{
m_listEventTypes.Add(eventType);
m_listHandles.Add(handler);
}
public void AddUIEvent(int eventType, Action handler)
{
if (GameEvent.AddEventListener(eventType, handler))
{
AddEvent(eventType, handler);
}
}
public void AddUIEvent<T>(int eventType, Action<T> handler)
{
if (GameEvent.AddEventListener(eventType, handler))
{
AddEvent(eventType, handler);
}
}
public void AddUIEvent<T, U>(int eventType, Action<T, U> handler)
{
if (GameEvent.AddEventListener(eventType, handler))
{
AddEvent(eventType, handler);
}
}
public void AddUIEvent<T, U, V>(int eventType, Action<T, U, V> handler)
{
if (GameEvent.AddEventListener(eventType, handler))
{
AddEvent(eventType, handler);
}
}
public void AddUIEvent<T, U, V, W>(int eventType, Action<T, U, V, W> handler)
{
if (GameEvent.AddEventListener(eventType, handler))
{
AddEvent(eventType, handler);
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: dbfc91838eab49f6a9c8e0cd222e5f16
timeCreated: 1666765305

View File

@@ -1,880 +0,0 @@
using System;
using System.Collections.Generic;
namespace TEngine.Runtime
{
#region EventInfo
internal interface IEventInfo
{
void Free();
}
public class EventInfo : IEventInfo, IMemory
{
private Action _actions;
public Action Actions => _actions;
public int EventCount { set; get; }
public void AddAction(Action action)
{
_actions += action;
EventCount++;
}
public void RmvAction(Action action)
{
_actions -= action;
EventCount--;
}
public void Clear()
{
EventCount = 0;
_actions = null;
}
public void Free()
{
MemoryPool.Release(this);
}
}
public class EventInfo<T> : IEventInfo, IMemory
{
private Action<T> _actions;
public Action<T> Actions => _actions;
public int EventCount { set; get; }
public void AddAction(Action<T> action)
{
_actions += action;
EventCount++;
}
public void RmvAction(Action<T> action)
{
_actions -= action;
EventCount--;
}
public void Clear()
{
EventCount = 0;
_actions = null;
}
public void Free()
{
MemoryPool.Release(this);
}
}
public class EventInfo<T, U> : IEventInfo, IMemory
{
private Action<T, U> _actions;
public Action<T, U> Actions => _actions;
public int EventCount { set; get; }
public void AddAction(Action<T, U> action)
{
_actions += action;
EventCount++;
}
public void RmvAction(Action<T, U> action)
{
_actions -= action;
EventCount--;
}
public void Clear()
{
EventCount = 0;
_actions = null;
}
public void Free()
{
MemoryPool.Release(this);
}
}
public class EventInfo<T, U, W> : IEventInfo, IMemory
{
private Action<T, U, W> _actions;
public Action<T, U, W> Actions => _actions;
public int EventCount { set; get; }
public void AddAction(Action<T, U, W> action)
{
_actions += action;
EventCount++;
}
public void RmvAction(Action<T, U, W> action)
{
_actions -= action;
EventCount--;
}
public void Clear()
{
EventCount = 0;
_actions = null;
}
public void Free()
{
MemoryPool.Release(this);
}
}
public class EventInfo<T, U, W, X> : IEventInfo, IMemory
{
private Action<T, U, W, X> _actions;
public Action<T, U, W, X> Actions => _actions;
public int EventCount { set; get; }
public void AddAction(Action<T, U, W, X> action)
{
_actions += action;
EventCount++;
}
public void RmvAction(Action<T, U, W, X> action)
{
_actions -= action;
EventCount--;
}
public void Clear()
{
EventCount = 0;
_actions = null;
}
public void Free()
{
MemoryPool.Release(this);
}
}
public class EventInfo<T, U, W, X, Y> : IEventInfo, IMemory
{
private Action<T, U, W, X, Y> _actions;
public Action<T, U, W, X, Y> Actions => _actions;
public int EventCount { set; get; }
public void AddAction(Action<T, U, W, X, Y> action)
{
_actions += action;
EventCount++;
}
public void RmvAction(Action<T, U, W, X, Y> action)
{
_actions -= action;
EventCount--;
}
public void Clear()
{
EventCount = 0;
_actions = null;
}
public void Free()
{
MemoryPool.Release(this);
}
}
#endregion
public class GameEvent : IMemory
{
public void Destroy()
{
Clear();
}
/// <summary>
/// Dictionary Key->Int.32 Value->EventInfo,调用频率高建议使用int事件减少字典内String的哈希碰撞
/// </summary>
private Dictionary<int, IEventInfo> _eventDic = new Dictionary<int, IEventInfo>();
/// <summary>
/// Dictionary Key->string Value->EventInfo,调用频率不高的时候可以使用
/// </summary>
private Dictionary<string, IEventInfo> m_eventStrDic = new Dictionary<string, IEventInfo>();
#region AddEventListener
public void AddEventListener<T>(int eventId, Action<T> action)
{
if (_eventDic.ContainsKey(eventId))
{
var eventInfo = _eventDic[eventId] as EventInfo<T>;
if (eventInfo != null)
{
eventInfo.AddAction(action);
}
else
{
throw new Exception("The Same GameEventId AddEventListener Need Same Args");
}
}
else
{
var eventInfo = MemoryPool.Acquire<EventInfo<T>>();
eventInfo.AddAction(action);
_eventDic.Add(eventId, eventInfo);
}
}
public void AddEventListener<T, U>(int eventId, Action<T, U> action)
{
if (_eventDic.ContainsKey(eventId))
{
var eventInfo = _eventDic[eventId] as EventInfo<T, U>;
if (eventInfo != null)
{
eventInfo.AddAction(action);
}
else
{
throw new Exception("The Same GameEventId AddEventListener Need Same Args");
}
}
else
{
var eventInfo = MemoryPool.Acquire<EventInfo<T, U>>();
eventInfo.AddAction(action);
_eventDic.Add(eventId, eventInfo);
}
}
public void AddEventListener<T, U, W>(int eventId, Action<T, U, W> action)
{
if (_eventDic.ContainsKey(eventId))
{
var eventInfo = _eventDic[eventId] as EventInfo<T, U, W>;
if (eventInfo != null)
{
eventInfo.AddAction(action);
}
else
{
throw new Exception("The Same GameEventId AddEventListener Need Same Args");
}
}
else
{
var eventInfo = MemoryPool.Acquire<EventInfo<T, U, W>>();
eventInfo.AddAction(action);
_eventDic.Add(eventId, eventInfo);
}
}
public void AddEventListener<T, U, W, X>(int eventId, Action<T, U, W, X> action)
{
if (_eventDic.ContainsKey(eventId))
{
var eventInfo = _eventDic[eventId] as EventInfo<T, U, W, X>;
if (eventInfo != null)
{
eventInfo.AddAction(action);
}
else
{
throw new Exception("The Same GameEventId AddEventListener Need Same Args");
}
}
else
{
var eventInfo = MemoryPool.Acquire<EventInfo<T, U, W, X>>();
eventInfo.AddAction(action);
_eventDic.Add(eventId, eventInfo);
}
}
public void AddEventListener<T, U, W, X, Y>(int eventId, Action<T, U, W, X, Y> action)
{
if (_eventDic.ContainsKey(eventId))
{
var eventInfo = _eventDic[eventId] as EventInfo<T, U, W, X, Y>;
if (eventInfo != null)
{
eventInfo.AddAction(action);
}
else
{
throw new Exception("The Same GameEventId AddEventListener Need Same Args");
}
}
else
{
var eventInfo = MemoryPool.Acquire<EventInfo<T, U, W, X, Y>>();
eventInfo.AddAction(action);
_eventDic.Add(eventId, eventInfo);
}
}
public void AddEventListener(int eventId, Action action)
{
if (_eventDic.ContainsKey(eventId))
{
var eventInfo = _eventDic[eventId] as EventInfo;
if (eventInfo != null)
{
eventInfo.AddAction(action);
}
else
{
throw new Exception("The Same GameEventId AddEventListener Need Same Args");
}
}
else
{
var eventInfo = MemoryPool.Acquire<EventInfo>();
eventInfo.AddAction(action);
_eventDic.Add(eventId, eventInfo);
}
}
#endregion
#region RemoveEventListener
public void RemoveEventListener<T>(int eventId, Action<T> action)
{
if (action == null)
{
return;
}
if (_eventDic.ContainsKey(eventId))
{
var eventInfo = _eventDic[eventId] as EventInfo<T>;
if (eventInfo != null)
{
eventInfo.RmvAction(action);
if (eventInfo.EventCount <= 0)
{
_eventDic.Remove(eventId);
MemoryPool.Release(eventInfo);
}
}
else
{
throw new Exception("The Same GameEventId RemoveEventListener Need Same Args");
}
}
}
public void RemoveEventListener<T, U>(int eventId, Action<T, U> action)
{
if (action == null)
{
return;
}
if (_eventDic.ContainsKey(eventId))
{
var eventInfo = _eventDic[eventId] as EventInfo<T, U>;
if (eventInfo != null)
{
eventInfo.RmvAction(action);
if (eventInfo.EventCount <= 0)
{
_eventDic.Remove(eventId);
MemoryPool.Release(eventInfo);
}
}
else
{
throw new Exception("The Same GameEventId RemoveEventListener Need Same Args");
}
}
}
public void RemoveEventListener<T, U, W>(int eventId, Action<T, U, W> action)
{
if (action == null)
{
return;
}
if (_eventDic.ContainsKey(eventId))
{
var eventInfo = _eventDic[eventId] as EventInfo<T, U, W>;
if (eventInfo != null)
{
eventInfo.RmvAction(action);
if (eventInfo.EventCount <= 0)
{
_eventDic.Remove(eventId);
MemoryPool.Release(eventInfo);
}
}
else
{
throw new Exception("The Same GameEventId RemoveEventListener Need Same Args");
}
}
}
public void RemoveEventListener<T, U, W, X>(int eventId, Action<T, U, W, X> action)
{
if (action == null)
{
return;
}
if (_eventDic.ContainsKey(eventId))
{
var eventInfo = _eventDic[eventId] as EventInfo<T, U, W, X>;
if (eventInfo != null)
{
eventInfo.RmvAction(action);
if (eventInfo.EventCount <= 0)
{
_eventDic.Remove(eventId);
MemoryPool.Release(eventInfo);
}
}
else
{
throw new Exception("The Same GameEventId RemoveEventListener Need Same Args");
}
}
}
public void RemoveEventListener<T, U, W, X, Y>(int eventId, Action<T, U, W, X, Y> action)
{
if (action == null)
{
return;
}
if (_eventDic.ContainsKey(eventId))
{
var eventInfo = _eventDic[eventId] as EventInfo<T, U, W, X, Y>;
if (eventInfo != null)
{
eventInfo.RmvAction(action);
if (eventInfo.EventCount <= 0)
{
_eventDic.Remove(eventId);
MemoryPool.Release(eventInfo);
}
}
else
{
throw new Exception("The Same GameEventId RemoveEventListener Need Same Args");
}
}
}
public void RemoveEventListener(int eventId, Action action)
{
if (action == null)
{
return;
}
if (_eventDic.ContainsKey(eventId))
{
var eventInfo = _eventDic[eventId] as EventInfo;
if (eventInfo != null)
{
eventInfo.RmvAction(action);
if (eventInfo.EventCount <= 0)
{
_eventDic.Remove(eventId);
MemoryPool.Release(eventInfo);
}
}
else
{
throw new Exception("The Same GameEventId RemoveEventListener Need Same Args");
}
}
}
#endregion
#region Send
public void Send<T>(int eventId, T info)
{
if (_eventDic.ContainsKey(eventId))
{
var eventInfo = _eventDic[eventId] as EventInfo<T>;
if (eventInfo != null)
{
eventInfo.Actions?.Invoke(info);
}
}
}
public void Send<T, U>(int eventId, T info, U info2)
{
if (_eventDic.ContainsKey(eventId))
{
var eventInfo = _eventDic[eventId] as EventInfo<T, U>;
if (eventInfo != null)
{
eventInfo.Actions?.Invoke(info, info2);
}
}
}
public void Send<T, U, W>(int eventId, T info, U info2, W info3)
{
if (_eventDic.ContainsKey(eventId))
{
var eventInfo = _eventDic[eventId] as EventInfo<T, U, W>;
if (eventInfo != null)
{
eventInfo.Actions?.Invoke(info, info2, info3);
}
}
}
public void Send<T, U, W, X>(int eventId, T info, U info2, W info3, X info4)
{
if (_eventDic.ContainsKey(eventId))
{
var eventInfo = _eventDic[eventId] as EventInfo<T, U, W, X>;
if (eventInfo != null)
{
eventInfo.Actions?.Invoke(info, info2, info3, info4);
}
}
}
public void Send<T, U, W, X, Y>(int eventId, T info, U info2, W info3, X info4, Y Info5)
{
if (_eventDic.ContainsKey(eventId))
{
var eventInfo = _eventDic[eventId] as EventInfo<T, U, W, X, Y>;
if (eventInfo != null)
{
eventInfo.Actions?.Invoke(info, info2, info3, info4, Info5);
}
}
}
public void Send(int eventId)
{
if (_eventDic.ContainsKey(eventId))
{
var eventInfo = _eventDic[eventId] as EventInfo;
if (eventInfo != null)
{
eventInfo.Actions?.Invoke();
}
}
}
#endregion
#region StringEvent
#region AddEventListener
public void AddEventListener<T>(string eventId, Action<T> action)
{
if (m_eventStrDic.ContainsKey(eventId))
{
var eventInfo = m_eventStrDic[eventId] as EventInfo<T>;
if (eventInfo != null)
{
eventInfo.AddAction(action);
}
else
{
throw new Exception("The Same GameEventId AddEventListener Need Same Args");
}
}
else
{
var eventInfo = MemoryPool.Acquire<EventInfo<T>>();
eventInfo.AddAction(action);
m_eventStrDic.Add(eventId, eventInfo);
}
}
public void AddEventListener<T, U>(string eventId, Action<T, U> action)
{
if (m_eventStrDic.ContainsKey(eventId))
{
var eventInfo = m_eventStrDic[eventId] as EventInfo<T, U>;
if (eventInfo != null)
{
eventInfo.AddAction(action);
}
else
{
throw new Exception("The Same GameEventId AddEventListener Need Same Args");
}
}
else
{
var eventInfo = MemoryPool.Acquire<EventInfo<T, U>>();
eventInfo.AddAction(action);
m_eventStrDic.Add(eventId, eventInfo);
}
}
public void AddEventListener<T, U, W>(string eventId, Action<T, U, W> action)
{
if (m_eventStrDic.ContainsKey(eventId))
{
var eventInfo = m_eventStrDic[eventId] as EventInfo<T, U, W>;
if (eventInfo != null)
{
eventInfo.AddAction(action);
}
else
{
throw new Exception("The Same GameEventId AddEventListener Need Same Args");
}
}
else
{
var eventInfo = MemoryPool.Acquire<EventInfo<T, U, W>>();
eventInfo.AddAction(action);
m_eventStrDic.Add(eventId, eventInfo);
}
}
public void AddEventListener(string eventId, Action action)
{
if (m_eventStrDic.ContainsKey(eventId))
{
var eventInfo = m_eventStrDic[eventId] as EventInfo;
if (eventInfo != null)
{
eventInfo.AddAction(action);
}
else
{
throw new Exception("The Same GameEventId AddEventListener Need Same Args");
}
}
else
{
var eventInfo = MemoryPool.Acquire<EventInfo>();
eventInfo.AddAction(action);
m_eventStrDic.Add(eventId, eventInfo);
}
}
#endregion
#region RemoveEventListener
public void RemoveEventListener<T>(string eventId, Action<T> action)
{
if (action == null)
{
return;
}
if (m_eventStrDic.ContainsKey(eventId))
{
var eventInfo = m_eventStrDic[eventId] as EventInfo<T>;
if (eventInfo != null)
{
eventInfo.RmvAction(action);
if (eventInfo.EventCount <= 0)
{
m_eventStrDic.Remove(eventId);
MemoryPool.Release(eventInfo);
}
}
else
{
throw new Exception("The Same GameEventId RemoveEventListener Need Same Args");
}
}
}
public void RemoveEventListener<T, U>(string eventId, Action<T, U> action)
{
if (action == null)
{
return;
}
if (m_eventStrDic.ContainsKey(eventId))
{
var eventInfo = m_eventStrDic[eventId] as EventInfo<T, U>;
if (eventInfo != null)
{
eventInfo.RmvAction(action);
if (eventInfo.EventCount <= 0)
{
m_eventStrDic.Remove(eventId);
MemoryPool.Release(eventInfo);
}
}
else
{
throw new Exception("The Same GameEventId RemoveEventListener Need Same Args");
}
}
}
public void RemoveEventListener<T, U, W>(string eventId, Action<T, U, W> action)
{
if (action == null)
{
return;
}
if (m_eventStrDic.ContainsKey(eventId))
{
var eventInfo = m_eventStrDic[eventId] as EventInfo<T, U, W>;
if (eventInfo != null)
{
eventInfo.RmvAction(action);
if (eventInfo.EventCount <= 0)
{
m_eventStrDic.Remove(eventId);
MemoryPool.Release(eventInfo);
}
}
else
{
throw new Exception("The Same GameEventId RemoveEventListener Need Same Args");
}
}
}
public void RemoveEventListener(string eventId, Action action)
{
if (action == null)
{
return;
}
if (m_eventStrDic.ContainsKey(eventId))
{
var eventInfo = m_eventStrDic[eventId] as EventInfo;
if (eventInfo != null)
{
eventInfo.RmvAction(action);
if (eventInfo.EventCount <= 0)
{
m_eventStrDic.Remove(eventId);
MemoryPool.Release(eventInfo);
}
}
else
{
throw new Exception("The Same GameEventId RemoveEventListener Need Same Args");
}
}
}
#endregion
#region Send
public void Send<T>(string eventId, T info)
{
if (m_eventStrDic.ContainsKey(eventId))
{
var eventInfo = (m_eventStrDic[eventId] as EventInfo<T>);
if (eventInfo != null)
{
eventInfo.Actions?.Invoke(info);
}
}
}
public void Send<T, U>(string eventId, T info, U info2)
{
if (m_eventStrDic.ContainsKey(eventId))
{
var eventInfo = (m_eventStrDic[eventId] as EventInfo<T, U>);
if (eventInfo != null)
{
eventInfo.Actions?.Invoke(info, info2);
}
}
}
public void Send<T, U, W>(string eventId, T info, U info2, W info3)
{
if (m_eventStrDic.ContainsKey(eventId))
{
var eventInfo = (m_eventStrDic[eventId] as EventInfo<T, U, W>);
if (eventInfo != null)
{
eventInfo.Actions?.Invoke(info, info2, info3);
}
}
}
public void Send(string eventId)
{
if (m_eventStrDic.ContainsKey(eventId))
{
var eventInfo = (m_eventStrDic[eventId] as EventInfo);
if (eventInfo != null)
{
eventInfo.Actions?.Invoke();
}
}
}
#endregion
#endregion
#region Clear
public void Clear()
{
var etr = _eventDic.GetEnumerator();
while (etr.MoveNext())
{
var eventInfo = etr.Current.Value;
eventInfo.Free();
}
etr.Dispose();
var etrStr = m_eventStrDic.GetEnumerator();
while (etrStr.MoveNext())
{
var eventInfo = etrStr.Current.Value;
eventInfo.Free();
}
etrStr.Dispose();
_eventDic.Clear();
m_eventStrDic.Clear();
}
#endregion
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 8bb87835faef0ad4f9bf016b5df511f0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,215 +0,0 @@
using System;
namespace TEngine.Runtime
{
/// <summary>
/// 总观察者 - 总事件中心系统
/// </summary>
public class GameEventMgr : TSingleton<GameEventMgr>
{
private GameEvent _gameEvent;
protected override void Init()
{
base.Init();
_gameEvent = MemoryPool.Acquire<GameEvent>();
}
public override void Release()
{
MemoryPool.Release(_gameEvent);
}
public override void Active()
{
base.Active();
}
#region AddEventListener
public void AddEventListener<T>(int eventId, Action<T> action)
{
_gameEvent.AddEventListener(eventId, action);
}
public void AddEventListener<T, U>(int eventId, Action<T, U> action)
{
_gameEvent.AddEventListener(eventId, action);
}
public void AddEventListener<T, U, W>(int eventId, Action<T, U, W> action)
{
_gameEvent.AddEventListener(eventId, action);
}
public void AddEventListener<T, U, W, X>(int eventId, Action<T, U, W, X> action)
{
_gameEvent.AddEventListener(eventId, action);
}
public void AddEventListener<T, U, W, X, Y>(int eventId, Action<T, U, W, X, Y> action)
{
_gameEvent.AddEventListener(eventId, action);
}
public void AddEventListener(int eventId, Action action)
{
_gameEvent.AddEventListener(eventId, action);
}
#endregion
#region RemoveEventListener
public void RemoveEventListener<T>(int eventId, Action<T> action)
{
_gameEvent.RemoveEventListener(eventId, action);
}
public void RemoveEventListener<T, U>(int eventId, Action<T, U> action)
{
_gameEvent.RemoveEventListener(eventId, action);
}
public void RemoveEventListener<T, U, W>(int eventId, Action<T, U, W> action)
{
_gameEvent.RemoveEventListener(eventId, action);
}
public void RemoveEventListener<T, U, W, X>(int eventId, Action<T, U, W, X> action)
{
_gameEvent.RemoveEventListener(eventId, action);
}
public void RemoveEventListener<T, U, W, X, Y>(int eventId, Action<T, U, W, X, Y> action)
{
_gameEvent.RemoveEventListener(eventId, action);
}
public void RemoveEventListener(int eventId, Action action)
{
_gameEvent.RemoveEventListener(eventId, action);
}
#endregion
#region Send
public void Send<T>(int eventId, T info)
{
_gameEvent.Send(eventId, info);
}
public void Send<T, U>(int eventId, T info, U info2)
{
_gameEvent.Send(eventId, info, info2);
}
public void Send<T, U, W>(int eventId, T info, U info2, W info3)
{
_gameEvent.Send(eventId, info, info2, info3);
}
public void Send<T, U, W, X>(int eventId, T info, U info2, W info3, X info4)
{
_gameEvent.Send(eventId, info, info2, info3, info4);
}
public void Send<T, U, W, X, Y>(int eventId, T info, U info2, W info3, X info4, Y info5)
{
_gameEvent.Send(eventId, info, info2, info3, info4, info5);
}
public void Send(int eventId)
{
_gameEvent.Send(eventId);
}
#endregion
#region StringEvent
#region AddEventListener
public void AddEventListener<T>(string eventId, Action<T> action)
{
_gameEvent.AddEventListener(eventId, action);
}
public void AddEventListener<T, U>(string eventId, Action<T, U> action)
{
_gameEvent.AddEventListener(eventId, action);
}
public void AddEventListener<T, U, W>(string eventId, Action<T, U, W> action)
{
_gameEvent.AddEventListener(eventId, action);
}
public void AddEventListener(string eventId, Action action)
{
_gameEvent.AddEventListener(eventId, action);
}
#endregion
#region RemoveEventListener
public void RemoveEventListener<T>(string eventId, Action<T> action)
{
_gameEvent.RemoveEventListener(eventId, action);
}
public void RemoveEventListener<T, U>(string eventId, Action<T, U> action)
{
_gameEvent.RemoveEventListener(eventId, action);
}
public void RemoveEventListener<T, U, W>(string eventId, Action<T, U, W> action)
{
_gameEvent.RemoveEventListener(eventId, action);
}
public void RemoveEventListener(string eventId, Action action)
{
_gameEvent.RemoveEventListener(eventId, action);
}
#endregion
#region Send
public void Send<T>(string eventId, T info)
{
_gameEvent.Send(eventId, info);
}
public void Send<T, U>(string eventId, T info, U info2)
{
_gameEvent.Send(eventId, info, info2);
}
public void Send<T, U, W>(string eventId, T info, U info2, W info3)
{
_gameEvent.Send(eventId, info, info2, info3);
}
public void Send(string eventId)
{
_gameEvent.Send(eventId);
}
#endregion
#endregion
#region Clear
public void Clear()
{
_gameEvent.Clear();
}
#endregion
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: c42c5b68ecfcd7849bc964b670a1217e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -138,27 +138,27 @@ namespace TEngine.Runtime
private void OnNetworkConnected(INetworkChannel channel, object obj) private void OnNetworkConnected(INetworkChannel channel, object obj)
{ {
GameEventMgr.Instance.Send(NetWorkEventId.NetworkConnectedEvent,channel, obj); GameEvent.Send(NetWorkEventId.NetworkConnectedEvent,channel, obj);
} }
private void OnNetworkClosed(INetworkChannel channel) private void OnNetworkClosed(INetworkChannel channel)
{ {
GameEventMgr.Instance.Send(NetWorkEventId.NetworkClosedEvent,channel); GameEvent.Send(NetWorkEventId.NetworkClosedEvent,channel);
} }
private void OnNetworkMissHeartBeat(INetworkChannel channel, int missCount) private void OnNetworkMissHeartBeat(INetworkChannel channel, int missCount)
{ {
GameEventMgr.Instance.Send(NetWorkEventId.NetworkMissHeartBeatEvent,channel,missCount); GameEvent.Send(NetWorkEventId.NetworkMissHeartBeatEvent,channel,missCount);
} }
private void OnNetworkError(INetworkChannel channel, NetworkErrorCode errorCode, string message) private void OnNetworkError(INetworkChannel channel, NetworkErrorCode errorCode, string message)
{ {
GameEventMgr.Instance.Send(NetWorkEventId.NetworkErrorEvent,channel,errorCode,message); GameEvent.Send(NetWorkEventId.NetworkErrorEvent,channel,errorCode,message);
} }
private void OnNetworkCustomError(INetworkChannel channel,object message) private void OnNetworkCustomError(INetworkChannel channel,object message)
{ {
GameEventMgr.Instance.Send(NetWorkEventId.NetworkCustomErrorEvent,channel,message); GameEvent.Send(NetWorkEventId.NetworkCustomErrorEvent,channel,message);
} }
/// <summary> /// <summary>

View File

@@ -24,11 +24,11 @@ namespace TEngine.Runtime
{ {
m_NetworkChannel = networkChannel; m_NetworkChannel = networkChannel;
GameEventMgr.Instance.AddEventListener<INetworkChannel,object>(NetWorkEventId.NetworkConnectedEvent,OnNetworkConnected); GameEvent.AddEventListener<INetworkChannel,object>(NetWorkEventId.NetworkConnectedEvent,OnNetworkConnected);
GameEventMgr.Instance.AddEventListener<INetworkChannel>(NetWorkEventId.NetworkClosedEvent,OnNetworkClosed); GameEvent.AddEventListener<INetworkChannel>(NetWorkEventId.NetworkClosedEvent,OnNetworkClosed);
GameEventMgr.Instance.AddEventListener<INetworkChannel,int>(NetWorkEventId.NetworkMissHeartBeatEvent,OnNetworkMissHeartBeat); GameEvent.AddEventListener<INetworkChannel,int>(NetWorkEventId.NetworkMissHeartBeatEvent,OnNetworkMissHeartBeat);
GameEventMgr.Instance.AddEventListener<INetworkChannel,NetworkErrorCode,string>(NetWorkEventId.NetworkErrorEvent,OnNetworkError); GameEvent.AddEventListener<INetworkChannel,NetworkErrorCode,string>(NetWorkEventId.NetworkErrorEvent,OnNetworkError);
GameEventMgr.Instance.AddEventListener<INetworkChannel,object>(NetWorkEventId.NetworkCustomErrorEvent,OnNetworkCustomError); GameEvent.AddEventListener<INetworkChannel,object>(NetWorkEventId.NetworkCustomErrorEvent,OnNetworkCustomError);
m_NetworkChannel.RegisterHandler((int)ActionCode.HeartBeat,HandleHeartBeat); m_NetworkChannel.RegisterHandler((int)ActionCode.HeartBeat,HandleHeartBeat);
} }
@@ -98,11 +98,11 @@ namespace TEngine.Runtime
/// </summary> /// </summary>
public void Shutdown() public void Shutdown()
{ {
GameEventMgr.Instance.RemoveEventListener<INetworkChannel,object>(NetWorkEventId.NetworkConnectedEvent,OnNetworkConnected); GameEvent.RemoveEventListener<INetworkChannel,object>(NetWorkEventId.NetworkConnectedEvent,OnNetworkConnected);
GameEventMgr.Instance.RemoveEventListener<INetworkChannel>(NetWorkEventId.NetworkClosedEvent,OnNetworkClosed); GameEvent.RemoveEventListener<INetworkChannel>(NetWorkEventId.NetworkClosedEvent,OnNetworkClosed);
GameEventMgr.Instance.RemoveEventListener<INetworkChannel,int>(NetWorkEventId.NetworkMissHeartBeatEvent,OnNetworkMissHeartBeat); GameEvent.RemoveEventListener<INetworkChannel,int>(NetWorkEventId.NetworkMissHeartBeatEvent,OnNetworkMissHeartBeat);
GameEventMgr.Instance.RemoveEventListener<INetworkChannel,NetworkErrorCode,string>(NetWorkEventId.NetworkErrorEvent,OnNetworkError); GameEvent.RemoveEventListener<INetworkChannel,NetworkErrorCode,string>(NetWorkEventId.NetworkErrorEvent,OnNetworkError);
GameEventMgr.Instance.RemoveEventListener<INetworkChannel,object>(NetWorkEventId.NetworkCustomErrorEvent,OnNetworkCustomError); GameEvent.RemoveEventListener<INetworkChannel,object>(NetWorkEventId.NetworkCustomErrorEvent,OnNetworkCustomError);
m_NetworkChannel = null; m_NetworkChannel = null;
} }

View File

@@ -8,17 +8,19 @@ namespace TEngine.Runtime
{ {
public override GameObject Load(string path) public override GameObject Load(string path)
{ {
return Resources.Load<GameObject>(path); return Resources.Load<GameObject>(RegularPath(path));
} }
public override GameObject Load(string path, Transform parent) public override GameObject Load(string path, Transform parent)
{ {
var obj = Load(path); var obj = Load(RegularPath(path));
if (obj == null) if (obj == null)
{ {
return null; return null;
} }
obj = UnityEngine.Object.Instantiate(obj);
if (parent != null) if (parent != null)
{ {
obj.transform.SetParent(parent); obj.transform.SetParent(parent);
@@ -27,19 +29,42 @@ namespace TEngine.Runtime
return obj; return obj;
} }
public static string RegularPath(string path)
{
if (string.IsNullOrEmpty(path))
{
return string.Empty;
}
var splits = path.Split('.');
if (splits.Length > 1)
{
string ret = string.Empty;
for (int i = 0; i < splits.Length-1; i++)
{
ret += splits[i];
}
return ret;
}
else
{
return path;
}
}
public override T Load<T>(string path) public override T Load<T>(string path)
{ {
return Resources.Load<T>(path); return Resources.Load<T>(RegularPath(path));
} }
public override void LoadAsync(string path, Action<GameObject> callBack) public override void LoadAsync(string path, Action<GameObject> callBack)
{ {
MonoUtility.StartCoroutine(ReallyLoadAsync(path, callBack)); MonoUtility.StartCoroutine(ReallyLoadAsync(RegularPath(path), callBack));
} }
private IEnumerator ReallyLoadAsync<T>(string path, Action<T> callback = null) where T : UnityEngine.Object private IEnumerator ReallyLoadAsync<T>(string path, Action<T> callback = null) where T : UnityEngine.Object
{ {
ResourceRequest request = Resources.LoadAsync<T>(path); ResourceRequest request = Resources.LoadAsync<T>(RegularPath(path));
yield return request; yield return request;
@@ -55,7 +80,7 @@ namespace TEngine.Runtime
public override void LoadAsync<T>(string path, Action<T> callBack, bool withSubAsset = false) public override void LoadAsync<T>(string path, Action<T> callBack, bool withSubAsset = false)
{ {
MonoUtility.StartCoroutine(ReallyLoadAsync<T>(path, callBack)); MonoUtility.StartCoroutine(ReallyLoadAsync<T>(RegularPath(path), callBack));
} }
} }
} }

View File

@@ -1091,7 +1091,7 @@ namespace TEngine.Runtime.Entity
/// <param name="userData">用户自定义数据。</param> /// <param name="userData">用户自定义数据。</param>
private void OnShowEntitySuccess(IEntity entity, float duration, object userData) private void OnShowEntitySuccess(IEntity entity, float duration, object userData)
{ {
GameEventMgr.Instance.Send(EntityEvent.ShowEntitySuccess,entity,duration,userData); GameEvent.Send(EntityEvent.ShowEntitySuccess,entity,duration,userData);
} }
/// <summary> /// <summary>
@@ -1109,7 +1109,7 @@ namespace TEngine.Runtime.Entity
entityAssetName, entityAssetName,
entityGroupName, entityGroupName,
errorMessage); errorMessage);
GameEventMgr.Instance.Send(EntityEvent.ShowEntityFailure,entityId,entityAssetName,entityGroupName,errorMessage,userData); GameEvent.Send(EntityEvent.ShowEntityFailure,entityId,entityAssetName,entityGroupName,errorMessage,userData);
} }
/// <summary> /// <summary>
@@ -1122,7 +1122,7 @@ namespace TEngine.Runtime.Entity
/// <param name="userData">用户自定义数据。</param> /// <param name="userData">用户自定义数据。</param>
private void OnShowEntityUpdate(int entityId, string entityAssetName, string entityGroupName, float progress, object userData) private void OnShowEntityUpdate(int entityId, string entityAssetName, string entityGroupName, float progress, object userData)
{ {
GameEventMgr.Instance.Send(EntityEvent.ShowEntityUpdate,entityId,entityAssetName,entityGroupName,progress,userData); GameEvent.Send(EntityEvent.ShowEntityUpdate,entityId,entityAssetName,entityGroupName,progress,userData);
} }
/// <summary> /// <summary>
@@ -1137,7 +1137,7 @@ namespace TEngine.Runtime.Entity
/// <param name="userData">用户自定义数据。</param> /// <param name="userData">用户自定义数据。</param>
private void OnShowEntityDependencyAsset(int entityId, string entityAssetName, string entityGroupName, string dependencyAssetName, int loadedCount, int totalCount, object userData) private void OnShowEntityDependencyAsset(int entityId, string entityAssetName, string entityGroupName, string dependencyAssetName, int loadedCount, int totalCount, object userData)
{ {
GameEventMgr.Instance.Send(EntityEvent.ShowEntityDependency,entityId,entityAssetName,entityGroupName,userData); GameEvent.Send(EntityEvent.ShowEntityDependency,entityId,entityAssetName,entityGroupName,userData);
} }
/// <summary> /// <summary>
@@ -1149,7 +1149,7 @@ namespace TEngine.Runtime.Entity
/// <param name="userData">用户自定义数据。</param> /// <param name="userData">用户自定义数据。</param>
private void OnHideEntityComplete(int entityId, string entityAssetName, IEntityGroup entityGroup, object userData) private void OnHideEntityComplete(int entityId, string entityAssetName, IEntityGroup entityGroup, object userData)
{ {
GameEventMgr.Instance.Send(EntityEvent.HideEntityComplete,entityId,entityAssetName,entityGroup,userData); GameEvent.Send(EntityEvent.HideEntityComplete,entityId,entityAssetName,entityGroup,userData);
} }
public override void OnUpdate(float elapseSeconds, float realElapseSeconds) public override void OnUpdate(float elapseSeconds, float realElapseSeconds)

View File

@@ -9,6 +9,7 @@ namespace TEngine.Runtime.HotUpdate
#pragma warning disable CS0162 #pragma warning disable CS0162
public class LoadMgr : TSingleton<LoadMgr> public class LoadMgr : TSingleton<LoadMgr>
{ {
public static int DownLoadFinish = StringId.StringToHash("DownLoadResult.AllDownLoaded");
/// <summary> /// <summary>
/// 资源版本号 /// 资源版本号
/// </summary> /// </summary>
@@ -31,7 +32,7 @@ namespace TEngine.Runtime.HotUpdate
if (result == (int)DownLoadResult.AllDownLoaded) if (result == (int)DownLoadResult.AllDownLoaded)
{ {
_UnPackCallback(100, status, 100); _UnPackCallback(100, status, 100);
GameEventMgr.Instance.Send("DownLoadResult.AllDownLoaded", true); GameEvent.Send(DownLoadFinish, true);
_StopLoadingCheck(); _StopLoadingCheck();
} }
else else

View File

@@ -19,7 +19,7 @@ namespace TEngine.Runtime.UIModule
{ {
if (m_eventMgr == null) if (m_eventMgr == null)
{ {
m_eventMgr = GameEventMgr.Instance; m_eventMgr = MemoryPool.Acquire<GameEventMgr>();
} }
return m_eventMgr; return m_eventMgr;
@@ -61,42 +61,29 @@ namespace TEngine.Runtime.UIModule
#region Event #region Event
private Dictionary<int, Delegate> m_eventTable = new Dictionary<int, Delegate>();
protected void ClearAllRegisterEvent() protected void ClearAllRegisterEvent()
{ {
var element = m_eventTable.GetEnumerator(); MemoryPool.Release(m_eventMgr);
while (element.MoveNext())
{
var m_event = element.Current.Value;
//GameEventMgr.Instance.RemoveEventListener(element.Current.Key, m_event);
}
m_eventTable.Clear();
} }
protected void AddUIEvent(int eventType, Action handler) protected void AddUIEvent(int eventType, Action handler)
{ {
m_eventTable.Add(eventType, handler); EventMgr.AddUIEvent(eventType, handler);
EventMgr.AddEventListener(eventType, handler);
} }
protected void AddUIEvent<T>(int eventType, Action<T> handler) protected void AddUIEvent<T>(int eventType, Action<T> handler)
{ {
m_eventTable.Add(eventType, handler); EventMgr.AddUIEvent(eventType, handler);
EventMgr.AddEventListener(eventType, handler);
} }
protected void AddUIEvent<T, U>(int eventType, Action<T, U> handler) protected void AddUIEvent<T, U>(int eventType, Action<T, U> handler)
{ {
m_eventTable.Add(eventType, handler); EventMgr.AddUIEvent(eventType, handler);
EventMgr.AddEventListener(eventType, handler);
} }
protected void AddUIEvent<T, U, V>(int eventType, Action<T, U, V> handler) protected void AddUIEvent<T, U, V>(int eventType, Action<T, U, V> handler)
{ {
m_eventTable.Add(eventType, handler); EventMgr.AddUIEvent(eventType, handler);
EventMgr.AddEventListener(eventType, handler);
} }
#endregion #endregion

View File

@@ -143,6 +143,8 @@ namespace TEngine.Runtime.UIModule
m_destroyed = true; m_destroyed = true;
ClearAllRegisterEvent();
DestroyAllChild(); DestroyAllChild();
OnDestroy(); OnDestroy();