diff --git a/Assets/GameMain/Scripts/GameProcedure/ProcedureResourcesInit.cs b/Assets/GameMain/Scripts/GameProcedure/ProcedureResourcesInit.cs index eeed1040..498acf9b 100644 --- a/Assets/GameMain/Scripts/GameProcedure/ProcedureResourcesInit.cs +++ b/Assets/GameMain/Scripts/GameProcedure/ProcedureResourcesInit.cs @@ -7,17 +7,19 @@ namespace TEngine.Runtime /// public class ProcedureResourcesInit : ProcedureBase { + public static int OnInitResourceCompleteEvent = StringId.StringToHash("OnInitResourceComplete"); + private bool m_initResourceComplete = false; protected override void OnEnter(IFsm procedureOwner) { base.OnEnter(procedureOwner); - GameEventMgr.Instance.AddEventListener("OnInitResourceComplete", OnInitResourceComplete); + GameEvent.AddEventListener(OnInitResourceCompleteEvent, OnInitResourceComplete); m_initResourceComplete = false; LoaderUtilities.DelayFun((() => { - GameEventMgr.Instance.Send("OnInitResourceComplete"); + GameEvent.Send(OnInitResourceCompleteEvent); }),new WaitForSeconds(1f)); } @@ -35,7 +37,7 @@ namespace TEngine.Runtime protected override void OnLeave(IFsm procedureOwner, bool isShutdown) { base.OnLeave(procedureOwner, isShutdown); - GameEventMgr.Instance.RemoveEventListener("OnInitResourceComplete", OnInitResourceComplete); + GameEvent.RemoveEventListener(OnInitResourceCompleteEvent, OnInitResourceComplete); } private void OnInitResourceComplete() diff --git a/Assets/GameMain/Scripts/GameProcedure/ProcedureResourcesUpdate.cs b/Assets/GameMain/Scripts/GameProcedure/ProcedureResourcesUpdate.cs index e731f9a0..505fb5eb 100644 --- a/Assets/GameMain/Scripts/GameProcedure/ProcedureResourcesUpdate.cs +++ b/Assets/GameMain/Scripts/GameProcedure/ProcedureResourcesUpdate.cs @@ -18,7 +18,7 @@ namespace TEngine.Runtime { base.OnEnter(procedureOwner); - GameEventMgr.Instance.AddEventListener("DownLoadResult.AllDownLoaded",AllDownLoaded); + GameEvent.AddEventListener(LoadMgr.DownLoadFinish,AllDownLoaded); _procedureOwner = procedureOwner; diff --git a/Assets/GameMain/Scripts/GameProcedure/ProcedureStartGame.cs b/Assets/GameMain/Scripts/GameProcedure/ProcedureStartGame.cs index 081af4ff..52c78945 100644 --- a/Assets/GameMain/Scripts/GameProcedure/ProcedureStartGame.cs +++ b/Assets/GameMain/Scripts/GameProcedure/ProcedureStartGame.cs @@ -13,7 +13,7 @@ protected override void OnEnter(IFsm procedureOwner) { base.OnEnter(procedureOwner); - GameEventMgr.Instance.Send(TEngineEvent.OnStartGame); + GameEvent.Send(TEngineEvent.OnStartGame); } } } \ No newline at end of file diff --git a/Assets/Scenes/DemoMain.cs b/Assets/Scenes/DemoMain.cs index b131fd96..36e56bd2 100644 --- a/Assets/Scenes/DemoMain.cs +++ b/Assets/Scenes/DemoMain.cs @@ -11,7 +11,7 @@ public class DemoMain : MonoBehaviour { //Demo示例,监听TEngine流程加载器OnStartGame事件 //抛出这个事件说明框架流程加载完成(热更新,初始化等) - GameEventMgr.Instance.AddEventListener(TEngineEvent.OnStartGame,OnStartGame); + GameEvent.AddEventListener(TEngineEvent.OnStartGame,OnStartGame); } private void OnStartGame() diff --git a/Assets/TEngine.Demo/Demo/TEngine.ActorDemo/ActorTestMain.cs b/Assets/TEngine.Demo/Demo/TEngine.ActorDemo/ActorTestMain.cs index 5d891dc8..4934f106 100644 --- a/Assets/TEngine.Demo/Demo/TEngine.ActorDemo/ActorTestMain.cs +++ b/Assets/TEngine.Demo/Demo/TEngine.ActorDemo/ActorTestMain.cs @@ -11,7 +11,7 @@ public class ActorTestMain : MonoBehaviour { //Demo示例,监听TEngine流程加载器OnStartGame事件 //抛出这个事件说明框架流程加载完成(热更新,初始化等) - GameEventMgr.Instance.AddEventListener(TEngineEvent.OnStartGame,OnStartGame); + GameEvent.AddEventListener(TEngineEvent.OnStartGame,OnStartGame); } private void OnStartGame() diff --git a/Assets/TEngine.Demo/Demo/TEngine.ActorDemo/PlayEntityMgr.cs b/Assets/TEngine.Demo/Demo/TEngine.ActorDemo/PlayEntityMgr.cs index 6363c9bd..d6a4f62c 100644 --- a/Assets/TEngine.Demo/Demo/TEngine.ActorDemo/PlayEntityMgr.cs +++ b/Assets/TEngine.Demo/Demo/TEngine.ActorDemo/PlayEntityMgr.cs @@ -17,9 +17,9 @@ namespace TEngine.Runtime.Actor /// void RegisterEvent() { - GameEventMgr.Instance.AddEventListener(EntityEvent.ShowEntitySuccess, OnShowEntitySuccess); - GameEventMgr.Instance.AddEventListener(EntityEvent.ShowEntityFailure, OnShowEntityFailure); - GameEventMgr.Instance.AddEventListener(EntityEvent.HideEntityComplete, OnHideEntityComplete); + GameEvent.AddEventListener(EntityEvent.ShowEntitySuccess, OnShowEntitySuccess); + GameEvent.AddEventListener(EntityEvent.ShowEntityFailure, OnShowEntityFailure); + GameEvent.AddEventListener(EntityEvent.HideEntityComplete, OnHideEntityComplete); } /// diff --git a/Assets/TEngine.Demo/Demo/TEngine.EntityDemo/EntityTestMain.cs b/Assets/TEngine.Demo/Demo/TEngine.EntityDemo/EntityTestMain.cs index 9f36a3a7..ab9f918f 100644 --- a/Assets/TEngine.Demo/Demo/TEngine.EntityDemo/EntityTestMain.cs +++ b/Assets/TEngine.Demo/Demo/TEngine.EntityDemo/EntityTestMain.cs @@ -11,7 +11,7 @@ public class EntityTestMain : MonoBehaviour { //Demo示例,监听TEngine流程加载器OnStartGame事件 //抛出这个事件说明框架流程加载完成(热更新,初始化等) - GameEventMgr.Instance.AddEventListener(TEngineEvent.OnStartGame,OnStartGame); + GameEvent.AddEventListener(TEngineEvent.OnStartGame,OnStartGame); } private void OnStartGame() diff --git a/Assets/TEngine.Demo/Demo/TEngine.EntityDemo/LightEntityMgr.cs b/Assets/TEngine.Demo/Demo/TEngine.EntityDemo/LightEntityMgr.cs index 64a9caf4..1620bea0 100644 --- a/Assets/TEngine.Demo/Demo/TEngine.EntityDemo/LightEntityMgr.cs +++ b/Assets/TEngine.Demo/Demo/TEngine.EntityDemo/LightEntityMgr.cs @@ -40,9 +40,9 @@ namespace TEngine.Demo.TEngine.EntityDemo /// void RegisterEvent() { - GameEventMgr.Instance.AddEventListener(EntityEvent.ShowEntitySuccess, OnShowEntitySuccess); - GameEventMgr.Instance.AddEventListener(EntityEvent.ShowEntityFailure, OnShowEntityFailure); - GameEventMgr.Instance.AddEventListener(EntityEvent.HideEntityComplete, OnHideEntityComplete); + GameEvent.AddEventListener(EntityEvent.ShowEntitySuccess, OnShowEntitySuccess); + GameEvent.AddEventListener(EntityEvent.ShowEntityFailure, OnShowEntityFailure); + GameEvent.AddEventListener(EntityEvent.HideEntityComplete, OnHideEntityComplete); } /// diff --git a/Assets/TEngine.Demo/Demo/TEngine.NetDemo/NetTestMain.cs b/Assets/TEngine.Demo/Demo/TEngine.NetDemo/NetTestMain.cs index bb89db34..0a39997b 100644 --- a/Assets/TEngine.Demo/Demo/TEngine.NetDemo/NetTestMain.cs +++ b/Assets/TEngine.Demo/Demo/TEngine.NetDemo/NetTestMain.cs @@ -16,7 +16,7 @@ public class NetTestMain : MonoBehaviour { //Demo示例,监听TEngine流程加载器OnStartGame事件 //抛出这个事件说明框架流程加载完成(热更新,初始化等) - GameEventMgr.Instance.AddEventListener(TEngineEvent.OnStartGame,OnStartGame); + GameEvent.AddEventListener(TEngineEvent.OnStartGame,OnStartGame); } diff --git a/Assets/TEngine.Demo/Demo/TEngine.UIDemo/Resources/UI/TestUI.prefab b/Assets/TEngine.Demo/Demo/TEngine.UIDemo/Resources/UI/TestUI.prefab new file mode 100644 index 00000000..764889f0 --- /dev/null +++ b/Assets/TEngine.Demo/Demo/TEngine.UIDemo/Resources/UI/TestUI.prefab @@ -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 diff --git a/Assets/TEngine.Demo/Demo/TEngine.UIDemo/Resources/UI/TestUI.prefab.meta b/Assets/TEngine.Demo/Demo/TEngine.UIDemo/Resources/UI/TestUI.prefab.meta new file mode 100644 index 00000000..76139504 --- /dev/null +++ b/Assets/TEngine.Demo/Demo/TEngine.UIDemo/Resources/UI/TestUI.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 8da8ae71cd1ab564fb2735b351ee48a0 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TEngine.Demo/Demo/TEngine.UIDemo/TestUI.cs b/Assets/TEngine.Demo/Demo/TEngine.UIDemo/TestUI.cs new file mode 100644 index 00000000..4f4bdc84 --- /dev/null +++ b/Assets/TEngine.Demo/Demo/TEngine.UIDemo/TestUI.cs @@ -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("m_text233"); + } + #endregion + + protected override void RegisterEvent() + { + base.RegisterEvent(); + AddUIEvent(TestEvent,Test); + } + + private void Test() + { + Log.Fatal("Test Trigger"); + } + + #region 事件 + #endregion + +} \ No newline at end of file diff --git a/Assets/TEngine.Demo/Demo/TEngine.UIDemo/TestUI.cs.meta b/Assets/TEngine.Demo/Demo/TEngine.UIDemo/TestUI.cs.meta new file mode 100644 index 00000000..be1b0c15 --- /dev/null +++ b/Assets/TEngine.Demo/Demo/TEngine.UIDemo/TestUI.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 0ec109ee7f6e49e796052056bacefbcf +timeCreated: 1666767723 \ No newline at end of file diff --git a/Assets/TEngine.Demo/Demo/TEngine.UIDemo/UIDemo.unity b/Assets/TEngine.Demo/Demo/TEngine.UIDemo/UIDemo.unity index ff922442..2434a0d3 100644 --- a/Assets/TEngine.Demo/Demo/TEngine.UIDemo/UIDemo.unity +++ b/Assets/TEngine.Demo/Demo/TEngine.UIDemo/UIDemo.unity @@ -38,12 +38,12 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {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 --- !u!157 &3 LightmapSettings: m_ObjectHideFlags: 0 - serializedVersion: 11 + serializedVersion: 12 m_GIWorkflowMode: 1 m_GISettings: serializedVersion: 2 @@ -98,7 +98,7 @@ LightmapSettings: m_TrainingDataDestination: TrainingData m_LightProbeSampleCountMultiplier: 4 m_LightingDataAsset: {fileID: 0} - m_UseShadowmask: 1 + m_LightingSettings: {fileID: 0} --- !u!196 &4 NavMeshSettings: serializedVersion: 2 @@ -118,6 +118,8 @@ NavMeshSettings: manualTileSize: 0 tileSize: 256 accuratePlacement: 0 + maxJobWorkers: 0 + preserveTilesOutsideBounds: 0 debug: m_Flags: 0 m_NavMeshData: {fileID: 0} @@ -240,6 +242,7 @@ Light: m_UseColorTemperature: 0 m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0} m_UseBoundingSphereOverride: 0 + m_UseViewFrustumForShadowCasterCull: 1 m_ShadowRadius: 0 m_ShadowAngle: 0 --- !u!4 &1274323984 @@ -356,13 +359,13 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 3463045026010536330, guid: 161ff7c8132079c4a95e2e4e70ddd41b, type: 3} - propertyPath: m_ResourceHelperTypeName - value: TEngine.Runtime.UnityResourceHelper + propertyPath: ResourceMode + value: 1 objectReference: {fileID: 0} - target: {fileID: 3463045026010536330, guid: 161ff7c8132079c4a95e2e4e70ddd41b, type: 3} - propertyPath: ResourceMode - value: 3 + propertyPath: m_ResourceHelperTypeName + value: TEngine.Runtime.UnityResourceHelper objectReference: {fileID: 0} - target: {fileID: 3463045026180535776, guid: 161ff7c8132079c4a95e2e4e70ddd41b, type: 3} @@ -427,7 +430,7 @@ PrefabInstance: - target: {fileID: 3463045026377943191, guid: 161ff7c8132079c4a95e2e4e70ddd41b, type: 3} propertyPath: m_EntranceProcedureTypeName - value: TEngine.Runtime.ProcedureCodeInit + value: TEngine.Runtime.ProcedureLaunch objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 161ff7c8132079c4a95e2e4e70ddd41b, type: 3} diff --git a/Assets/TEngine.Demo/Demo/TEngine.UIDemo/UITestMain.cs b/Assets/TEngine.Demo/Demo/TEngine.UIDemo/UITestMain.cs index 1d7a18b1..a21c9362 100644 --- a/Assets/TEngine.Demo/Demo/TEngine.UIDemo/UITestMain.cs +++ b/Assets/TEngine.Demo/Demo/TEngine.UIDemo/UITestMain.cs @@ -10,9 +10,10 @@ public class UITestMain : MonoBehaviour { //Demo示例,监听TEngine流程加载器OnStartGame事件 //抛出这个事件说明框架流程加载完成(热更新,初始化等) - GameEventMgr.Instance.AddEventListener(TEngineEvent.OnStartGame,OnStartGame); + GameEvent.AddEventListener(TEngineEvent.OnStartGame,OnStartGame); } + private int _loopTime = 0; /// /// OnStartGame /// @@ -20,5 +21,17 @@ public class UITestMain : MonoBehaviour { // 激活UI系统 UISys.Instance.Active(); + + UISys.Mgr.ShowWindow(); + + TimerMgr.Instance.AddTimer((args => + { + _loopTime++; + GameEvent.Send(TestUI.TestEvent); + if (_loopTime > 7) + { + UISys.Mgr.CloseWindow(); + } + }), 1f, true); } } diff --git a/Assets/TEngine/Scripts/Runtime/Core/Event/Core.meta b/Assets/TEngine/Scripts/Runtime/Core/Event/Core.meta new file mode 100644 index 00000000..f2948811 --- /dev/null +++ b/Assets/TEngine/Scripts/Runtime/Core/Event/Core.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: a7f4494cbe10422e98e459dcf2af76a8 +timeCreated: 1666765074 \ No newline at end of file diff --git a/Assets/TEngine/Scripts/Runtime/Core/Event/Core/DEventDispatcher.cs b/Assets/TEngine/Scripts/Runtime/Core/Event/Core/DEventDispatcher.cs new file mode 100644 index 00000000..a0c2df9e --- /dev/null +++ b/Assets/TEngine/Scripts/Runtime/Core/Event/Core/DEventDispatcher.cs @@ -0,0 +1,265 @@ +using System; +using System.Collections.Generic; + +namespace TEngine.Runtime +{ + class DEventDelegateData + { + private int m_eventType = 0; + public List m_listExist = new List(); + private List m_addList = new List(); + private List m_deleteList = new List(); + 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 arg1) + { + m_isExcute = true; + for (var i = 0; i < m_listExist.Count; i++) + { + var d = m_listExist[i]; + var action = d as Action; + if (action != null) + { + action(arg1); + } + } + + CheckModify(); + } + + public void Callback(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; + if (action != null) + { + action(arg1, arg2); + } + } + + CheckModify(); + } + + public void Callback(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; + if (action != null) + { + action(arg1, arg2, arg3); + } + } + + CheckModify(); + } + + public void Callback(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; + if (action != null) + { + action(arg1, arg2, arg3, arg4); + } + } + + CheckModify(); + } + + public void Callback(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; + if (action != null) + { + action(arg1, arg2, arg3, arg4, arg5); + } + } + + CheckModify(); + } + } + + /// + /// 封装消息的底层分发和注册 + /// + class DEventDispatcher + { + static Dictionary m_eventTable = new Dictionary(); + + #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(int eventType, T arg1) + { + DEventDelegateData d; + if (m_eventTable.TryGetValue(eventType, out d)) + { + d.Callback(arg1); + } + } + + public void Send(int eventType, T arg1, U arg2) + { + DEventDelegateData d; + if (m_eventTable.TryGetValue(eventType, out d)) + { + d.Callback(arg1, arg2); + } + } + + public void Send(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(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(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 + } +} \ No newline at end of file diff --git a/Assets/TEngine/Scripts/Runtime/Core/Event/Core/DEventDispatcher.cs.meta b/Assets/TEngine/Scripts/Runtime/Core/Event/Core/DEventDispatcher.cs.meta new file mode 100644 index 00000000..50a71688 --- /dev/null +++ b/Assets/TEngine/Scripts/Runtime/Core/Event/Core/DEventDispatcher.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ff8f95404d2a458682f4eca4cdbc93f0 +timeCreated: 1666765082 \ No newline at end of file diff --git a/Assets/TEngine/Scripts/Runtime/Core/Event/Core/DEventInterfaceAttribute.cs b/Assets/TEngine/Scripts/Runtime/Core/Event/Core/DEventInterfaceAttribute.cs new file mode 100644 index 00000000..9f3e2f49 --- /dev/null +++ b/Assets/TEngine/Scripts/Runtime/Core/Event/Core/DEventInterfaceAttribute.cs @@ -0,0 +1,27 @@ +using System; + +namespace TEngine.Runtime +{ + public enum DEventGroup + { + /// + /// UI相关的交互 + /// + GroupUI, + + /// + /// 逻辑层内部相关的交互 + /// + GroupLogic, + } + + [System.AttributeUsage(System.AttributeTargets.Interface)] + public class DEventInterface : Attribute + { + public DEventGroup m_group; + public DEventInterface(DEventGroup group) + { + m_group = group; + } + } +} diff --git a/Assets/TEngine/Scripts/Runtime/Core/Event/Core/DEventInterfaceAttribute.cs.meta b/Assets/TEngine/Scripts/Runtime/Core/Event/Core/DEventInterfaceAttribute.cs.meta new file mode 100644 index 00000000..78564a65 --- /dev/null +++ b/Assets/TEngine/Scripts/Runtime/Core/Event/Core/DEventInterfaceAttribute.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: a1bd30ea28cb457ea60b77c28fad0a2b +timeCreated: 1666765181 \ No newline at end of file diff --git a/Assets/TEngine/Scripts/Runtime/Core/Event/Core/DEventMgr.cs b/Assets/TEngine/Scripts/Runtime/Core/Event/Core/DEventMgr.cs new file mode 100644 index 00000000..0ff7ec8b --- /dev/null +++ b/Assets/TEngine/Scripts/Runtime/Core/Event/Core/DEventMgr.cs @@ -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(); + + /// + /// 封装了调用的代理函数 + /// + private Dictionary m_entry = new Dictionary(); + + public T GetInterface() + { + string typeName = typeof(T).FullName; + DEventEntryData entry; + if (m_entry.TryGetValue(typeName, out entry)) + { + return (T)entry.m_interfaceWrap; + } + + return default(T); + } + + /// + /// 注册wrap的函数 + /// + /// + /// + public void RegWrapInterface(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; + } + } +} \ No newline at end of file diff --git a/Assets/TEngine/Scripts/Runtime/Core/Event/Core/DEventMgr.cs.meta b/Assets/TEngine/Scripts/Runtime/Core/Event/Core/DEventMgr.cs.meta new file mode 100644 index 00000000..4ddae327 --- /dev/null +++ b/Assets/TEngine/Scripts/Runtime/Core/Event/Core/DEventMgr.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 5313d1a916d548028065c2de344836f3 +timeCreated: 1666765217 \ No newline at end of file diff --git a/Assets/TEngine/Scripts/Runtime/Core/Event/Core/GameEvent.cs b/Assets/TEngine/Scripts/Runtime/Core/Event/Core/GameEvent.cs new file mode 100644 index 00000000..a48d8f0a --- /dev/null +++ b/Assets/TEngine/Scripts/Runtime/Core/Event/Core/GameEvent.cs @@ -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(int eventType, Action handler) + { + return m_mgr.GetDispatcher().AddEventListener(eventType, handler); + } + + public static bool AddEventListener(int eventType, Action handler) + { + return m_mgr.GetDispatcher().AddEventListener(eventType, handler); + } + + public static bool AddEventListener(int eventType, Action handler) + { + return m_mgr.GetDispatcher().AddEventListener(eventType, handler); + } + + public static bool AddEventListener(int eventType, Action handler) + { + return m_mgr.GetDispatcher().AddEventListener(eventType, handler); + } + + public static bool AddEventListener(int eventType, Action 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(int eventType, Action handler) + { + m_mgr.GetDispatcher().RemoveEventListener(eventType, handler); + } + + public static void RemoveEventListener(int eventType, Action handler) + { + m_mgr.GetDispatcher().RemoveEventListener(eventType, handler); + } + + public static void RemoveEventListener(int eventType, Action handler) + { + m_mgr.GetDispatcher().RemoveEventListener(eventType, handler); + } + + public static void RemoveEventListener(int eventType, Action handler) + { + m_mgr.GetDispatcher().RemoveEventListener(eventType, handler); + } + + public static void RemoveEventListener(int eventType, Action 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() + { + return m_mgr.GetInterface(); + } + + public static void Send(int eventType) + { + m_mgr.GetDispatcher().Send(eventType); + } + + public static void Send(int eventType, T arg1) + { + m_mgr.GetDispatcher().Send(eventType, arg1); + } + + public static void Send(int eventType, T arg1, U arg2) + { + m_mgr.GetDispatcher().Send(eventType, arg1, arg2); + } + + public static void Send(int eventType, T arg1, U arg2, V arg3) + { + m_mgr.GetDispatcher().Send(eventType, arg1, arg2, arg3); + } + + public static void Send(int eventType, T arg1, U arg2, V arg3, W arg4) + { + m_mgr.GetDispatcher().Send(eventType, arg1, arg2, arg3); + } + + public static void Send(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 + } +} \ No newline at end of file diff --git a/Assets/TEngine/Scripts/Runtime/Core/Event/Core/GameEvent.cs.meta b/Assets/TEngine/Scripts/Runtime/Core/Event/Core/GameEvent.cs.meta new file mode 100644 index 00000000..d7808a51 --- /dev/null +++ b/Assets/TEngine/Scripts/Runtime/Core/Event/Core/GameEvent.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ce11e95182ff4ac8928b21c833fe1d0b +timeCreated: 1666765360 \ No newline at end of file diff --git a/Assets/TEngine/Scripts/Runtime/Core/Event/Core/GameEventMgr.cs b/Assets/TEngine/Scripts/Runtime/Core/Event/Core/GameEventMgr.cs new file mode 100644 index 00000000..1e1f7ed8 --- /dev/null +++ b/Assets/TEngine/Scripts/Runtime/Core/Event/Core/GameEventMgr.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; + +namespace TEngine.Runtime +{ + public class GameEventMgr : IMemory + { + private List m_listEventTypes; + private List m_listHandles; + private bool m_isInit = false; + + public GameEventMgr() + { + if (m_isInit) + { + return; + } + + m_isInit = true; + m_listEventTypes = new List(); + m_listHandles = new List(); + } + + 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(int eventType, Action handler) + { + if (GameEvent.AddEventListener(eventType, handler)) + { + AddEvent(eventType, handler); + } + } + + public void AddUIEvent(int eventType, Action handler) + { + if (GameEvent.AddEventListener(eventType, handler)) + { + AddEvent(eventType, handler); + } + } + + public void AddUIEvent(int eventType, Action handler) + { + if (GameEvent.AddEventListener(eventType, handler)) + { + AddEvent(eventType, handler); + } + } + + public void AddUIEvent(int eventType, Action handler) + { + if (GameEvent.AddEventListener(eventType, handler)) + { + AddEvent(eventType, handler); + } + } + } +} \ No newline at end of file diff --git a/Assets/TEngine/Scripts/Runtime/Core/Event/Core/GameEventMgr.cs.meta b/Assets/TEngine/Scripts/Runtime/Core/Event/Core/GameEventMgr.cs.meta new file mode 100644 index 00000000..fbd852d6 --- /dev/null +++ b/Assets/TEngine/Scripts/Runtime/Core/Event/Core/GameEventMgr.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: dbfc91838eab49f6a9c8e0cd222e5f16 +timeCreated: 1666765305 \ No newline at end of file diff --git a/Assets/TEngine/Scripts/Runtime/Core/Event/GameEvent.cs b/Assets/TEngine/Scripts/Runtime/Core/Event/GameEvent.cs deleted file mode 100644 index 7fcaa675..00000000 --- a/Assets/TEngine/Scripts/Runtime/Core/Event/GameEvent.cs +++ /dev/null @@ -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 : 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 : 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 : 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 : 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 : 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); - } - } - - #endregion - - public class GameEvent : IMemory - { - public void Destroy() - { - Clear(); - } - - /// - /// Dictionary Key->Int.32 Value->EventInfo,调用频率高建议使用int事件,减少字典内String的哈希碰撞 - /// - private Dictionary _eventDic = new Dictionary(); - - /// - /// Dictionary Key->string Value->EventInfo,调用频率不高的时候可以使用 - /// - private Dictionary m_eventStrDic = new Dictionary(); - - #region AddEventListener - - 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.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.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.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.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.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.AddAction(action); - _eventDic.Add(eventId, eventInfo); - } - } - - #endregion - - #region RemoveEventListener - - 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"); - } - } - } - - 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"); - } - } - } - - 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"); - } - } - } - - 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"); - } - } - } - - 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"); - } - } - } - - 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(int eventId, T info) - { - if (_eventDic.ContainsKey(eventId)) - { - var eventInfo = _eventDic[eventId] as EventInfo; - if (eventInfo != null) - { - eventInfo.Actions?.Invoke(info); - } - } - } - - public void Send(int eventId, T info, U info2) - { - if (_eventDic.ContainsKey(eventId)) - { - var eventInfo = _eventDic[eventId] as EventInfo; - if (eventInfo != null) - { - eventInfo.Actions?.Invoke(info, info2); - } - } - } - - public void Send(int eventId, T info, U info2, W info3) - { - if (_eventDic.ContainsKey(eventId)) - { - var eventInfo = _eventDic[eventId] as EventInfo; - if (eventInfo != null) - { - eventInfo.Actions?.Invoke(info, info2, info3); - } - } - } - - public void Send(int eventId, T info, U info2, W info3, X info4) - { - if (_eventDic.ContainsKey(eventId)) - { - var eventInfo = _eventDic[eventId] as EventInfo; - if (eventInfo != null) - { - eventInfo.Actions?.Invoke(info, info2, info3, info4); - } - } - } - - public void Send(int eventId, T info, U info2, W info3, X info4, Y Info5) - { - if (_eventDic.ContainsKey(eventId)) - { - var eventInfo = _eventDic[eventId] as EventInfo; - 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(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.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.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.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.AddAction(action); - m_eventStrDic.Add(eventId, eventInfo); - } - } - - #endregion - - #region RemoveEventListener - - 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"); - } - } - } - - 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"); - } - } - } - - 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"); - } - } - } - - 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(string eventId, T info) - { - if (m_eventStrDic.ContainsKey(eventId)) - { - var eventInfo = (m_eventStrDic[eventId] as EventInfo); - if (eventInfo != null) - { - eventInfo.Actions?.Invoke(info); - } - } - } - - public void Send(string eventId, T info, U info2) - { - if (m_eventStrDic.ContainsKey(eventId)) - { - var eventInfo = (m_eventStrDic[eventId] as EventInfo); - if (eventInfo != null) - { - eventInfo.Actions?.Invoke(info, info2); - } - } - } - - public void Send(string eventId, T info, U info2, W info3) - { - if (m_eventStrDic.ContainsKey(eventId)) - { - var eventInfo = (m_eventStrDic[eventId] as EventInfo); - 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 - } -} \ No newline at end of file diff --git a/Assets/TEngine/Scripts/Runtime/Core/Event/GameEvent.cs.meta b/Assets/TEngine/Scripts/Runtime/Core/Event/GameEvent.cs.meta deleted file mode 100644 index b8163b74..00000000 --- a/Assets/TEngine/Scripts/Runtime/Core/Event/GameEvent.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 8bb87835faef0ad4f9bf016b5df511f0 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/TEngine/Scripts/Runtime/Core/Event/GameEventMgr.cs b/Assets/TEngine/Scripts/Runtime/Core/Event/GameEventMgr.cs deleted file mode 100644 index 18cb7f1a..00000000 --- a/Assets/TEngine/Scripts/Runtime/Core/Event/GameEventMgr.cs +++ /dev/null @@ -1,215 +0,0 @@ -using System; - -namespace TEngine.Runtime -{ - /// - /// 总观察者 - 总事件中心系统 - /// - public class GameEventMgr : TSingleton - { - private GameEvent _gameEvent; - - protected override void Init() - { - base.Init(); - _gameEvent = MemoryPool.Acquire(); - } - - public override void Release() - { - MemoryPool.Release(_gameEvent); - } - - public override void Active() - { - base.Active(); - } - - #region AddEventListener - - public void AddEventListener(int eventId, Action action) - { - _gameEvent.AddEventListener(eventId, action); - } - - public void AddEventListener(int eventId, Action action) - { - _gameEvent.AddEventListener(eventId, action); - } - - public void AddEventListener(int eventId, Action action) - { - _gameEvent.AddEventListener(eventId, action); - } - - public void AddEventListener(int eventId, Action action) - { - _gameEvent.AddEventListener(eventId, action); - } - - public void AddEventListener(int eventId, Action action) - { - _gameEvent.AddEventListener(eventId, action); - } - - public void AddEventListener(int eventId, Action action) - { - _gameEvent.AddEventListener(eventId, action); - } - - #endregion - - #region RemoveEventListener - - public void RemoveEventListener(int eventId, Action action) - { - _gameEvent.RemoveEventListener(eventId, action); - } - - public void RemoveEventListener(int eventId, Action action) - { - _gameEvent.RemoveEventListener(eventId, action); - } - - public void RemoveEventListener(int eventId, Action action) - { - _gameEvent.RemoveEventListener(eventId, action); - } - - public void RemoveEventListener(int eventId, Action action) - { - _gameEvent.RemoveEventListener(eventId, action); - } - - public void RemoveEventListener(int eventId, Action action) - { - _gameEvent.RemoveEventListener(eventId, action); - } - - public void RemoveEventListener(int eventId, Action action) - { - _gameEvent.RemoveEventListener(eventId, action); - } - - #endregion - - #region Send - - public void Send(int eventId, T info) - { - _gameEvent.Send(eventId, info); - } - - public void Send(int eventId, T info, U info2) - { - _gameEvent.Send(eventId, info, info2); - } - - public void Send(int eventId, T info, U info2, W info3) - { - _gameEvent.Send(eventId, info, info2, info3); - } - - public void Send(int eventId, T info, U info2, W info3, X info4) - { - _gameEvent.Send(eventId, info, info2, info3, info4); - } - - public void Send(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(string eventId, Action action) - { - _gameEvent.AddEventListener(eventId, action); - } - - public void AddEventListener(string eventId, Action action) - { - _gameEvent.AddEventListener(eventId, action); - } - - public void AddEventListener(string eventId, Action action) - { - _gameEvent.AddEventListener(eventId, action); - } - - public void AddEventListener(string eventId, Action action) - { - _gameEvent.AddEventListener(eventId, action); - } - - #endregion - - #region RemoveEventListener - - public void RemoveEventListener(string eventId, Action action) - { - _gameEvent.RemoveEventListener(eventId, action); - } - - public void RemoveEventListener(string eventId, Action action) - { - _gameEvent.RemoveEventListener(eventId, action); - } - - public void RemoveEventListener(string eventId, Action action) - { - _gameEvent.RemoveEventListener(eventId, action); - } - - public void RemoveEventListener(string eventId, Action action) - { - _gameEvent.RemoveEventListener(eventId, action); - } - - #endregion - - #region Send - - public void Send(string eventId, T info) - { - _gameEvent.Send(eventId, info); - } - - public void Send(string eventId, T info, U info2) - { - _gameEvent.Send(eventId, info, info2); - } - - public void Send(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 - } -} \ No newline at end of file diff --git a/Assets/TEngine/Scripts/Runtime/Core/Event/GameEventMgr.cs.meta b/Assets/TEngine/Scripts/Runtime/Core/Event/GameEventMgr.cs.meta deleted file mode 100644 index 127725c3..00000000 --- a/Assets/TEngine/Scripts/Runtime/Core/Event/GameEventMgr.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: c42c5b68ecfcd7849bc964b670a1217e -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/TEngine/Scripts/Runtime/Core/NetWork/Core/Network.cs b/Assets/TEngine/Scripts/Runtime/Core/NetWork/Core/Network.cs index dc3e54cf..8c8db0bb 100644 --- a/Assets/TEngine/Scripts/Runtime/Core/NetWork/Core/Network.cs +++ b/Assets/TEngine/Scripts/Runtime/Core/NetWork/Core/Network.cs @@ -138,27 +138,27 @@ namespace TEngine.Runtime 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) { - GameEventMgr.Instance.Send(NetWorkEventId.NetworkClosedEvent,channel); + GameEvent.Send(NetWorkEventId.NetworkClosedEvent,channel); } 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) { - GameEventMgr.Instance.Send(NetWorkEventId.NetworkErrorEvent,channel,errorCode,message); + GameEvent.Send(NetWorkEventId.NetworkErrorEvent,channel,errorCode,message); } private void OnNetworkCustomError(INetworkChannel channel,object message) { - GameEventMgr.Instance.Send(NetWorkEventId.NetworkCustomErrorEvent,channel,message); + GameEvent.Send(NetWorkEventId.NetworkCustomErrorEvent,channel,message); } /// diff --git a/Assets/TEngine/Scripts/Runtime/Core/NetWork/Helper/NetworkChannelHelper.cs b/Assets/TEngine/Scripts/Runtime/Core/NetWork/Helper/NetworkChannelHelper.cs index da5cffd8..01c8aed1 100644 --- a/Assets/TEngine/Scripts/Runtime/Core/NetWork/Helper/NetworkChannelHelper.cs +++ b/Assets/TEngine/Scripts/Runtime/Core/NetWork/Helper/NetworkChannelHelper.cs @@ -24,11 +24,11 @@ namespace TEngine.Runtime { m_NetworkChannel = networkChannel; - GameEventMgr.Instance.AddEventListener(NetWorkEventId.NetworkConnectedEvent,OnNetworkConnected); - GameEventMgr.Instance.AddEventListener(NetWorkEventId.NetworkClosedEvent,OnNetworkClosed); - GameEventMgr.Instance.AddEventListener(NetWorkEventId.NetworkMissHeartBeatEvent,OnNetworkMissHeartBeat); - GameEventMgr.Instance.AddEventListener(NetWorkEventId.NetworkErrorEvent,OnNetworkError); - GameEventMgr.Instance.AddEventListener(NetWorkEventId.NetworkCustomErrorEvent,OnNetworkCustomError); + GameEvent.AddEventListener(NetWorkEventId.NetworkConnectedEvent,OnNetworkConnected); + GameEvent.AddEventListener(NetWorkEventId.NetworkClosedEvent,OnNetworkClosed); + GameEvent.AddEventListener(NetWorkEventId.NetworkMissHeartBeatEvent,OnNetworkMissHeartBeat); + GameEvent.AddEventListener(NetWorkEventId.NetworkErrorEvent,OnNetworkError); + GameEvent.AddEventListener(NetWorkEventId.NetworkCustomErrorEvent,OnNetworkCustomError); m_NetworkChannel.RegisterHandler((int)ActionCode.HeartBeat,HandleHeartBeat); } @@ -98,11 +98,11 @@ namespace TEngine.Runtime /// public void Shutdown() { - GameEventMgr.Instance.RemoveEventListener(NetWorkEventId.NetworkConnectedEvent,OnNetworkConnected); - GameEventMgr.Instance.RemoveEventListener(NetWorkEventId.NetworkClosedEvent,OnNetworkClosed); - GameEventMgr.Instance.RemoveEventListener(NetWorkEventId.NetworkMissHeartBeatEvent,OnNetworkMissHeartBeat); - GameEventMgr.Instance.RemoveEventListener(NetWorkEventId.NetworkErrorEvent,OnNetworkError); - GameEventMgr.Instance.RemoveEventListener(NetWorkEventId.NetworkCustomErrorEvent,OnNetworkCustomError); + GameEvent.RemoveEventListener(NetWorkEventId.NetworkConnectedEvent,OnNetworkConnected); + GameEvent.RemoveEventListener(NetWorkEventId.NetworkClosedEvent,OnNetworkClosed); + GameEvent.RemoveEventListener(NetWorkEventId.NetworkMissHeartBeatEvent,OnNetworkMissHeartBeat); + GameEvent.RemoveEventListener(NetWorkEventId.NetworkErrorEvent,OnNetworkError); + GameEvent.RemoveEventListener(NetWorkEventId.NetworkCustomErrorEvent,OnNetworkCustomError); m_NetworkChannel = null; } diff --git a/Assets/TEngine/Scripts/Runtime/Core/Res/UnityResourceHelper/UnityResourceHelper.cs b/Assets/TEngine/Scripts/Runtime/Core/Res/UnityResourceHelper/UnityResourceHelper.cs index 6719463a..f402d16d 100644 --- a/Assets/TEngine/Scripts/Runtime/Core/Res/UnityResourceHelper/UnityResourceHelper.cs +++ b/Assets/TEngine/Scripts/Runtime/Core/Res/UnityResourceHelper/UnityResourceHelper.cs @@ -8,17 +8,19 @@ namespace TEngine.Runtime { public override GameObject Load(string path) { - return Resources.Load(path); + return Resources.Load(RegularPath(path)); } public override GameObject Load(string path, Transform parent) { - var obj = Load(path); + var obj = Load(RegularPath(path)); if (obj == null) { return null; } + obj = UnityEngine.Object.Instantiate(obj); + if (parent != null) { obj.transform.SetParent(parent); @@ -27,19 +29,42 @@ namespace TEngine.Runtime 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(string path) { - return Resources.Load(path); + return Resources.Load(RegularPath(path)); } public override void LoadAsync(string path, Action callBack) { - MonoUtility.StartCoroutine(ReallyLoadAsync(path, callBack)); + MonoUtility.StartCoroutine(ReallyLoadAsync(RegularPath(path), callBack)); } private IEnumerator ReallyLoadAsync(string path, Action callback = null) where T : UnityEngine.Object { - ResourceRequest request = Resources.LoadAsync(path); + ResourceRequest request = Resources.LoadAsync(RegularPath(path)); yield return request; @@ -55,7 +80,7 @@ namespace TEngine.Runtime public override void LoadAsync(string path, Action callBack, bool withSubAsset = false) { - MonoUtility.StartCoroutine(ReallyLoadAsync(path, callBack)); + MonoUtility.StartCoroutine(ReallyLoadAsync(RegularPath(path), callBack)); } } } \ No newline at end of file diff --git a/Assets/TEngine/Scripts/Runtime/Entity/EntitySystem.cs b/Assets/TEngine/Scripts/Runtime/Entity/EntitySystem.cs index 00d55cf2..202e5279 100644 --- a/Assets/TEngine/Scripts/Runtime/Entity/EntitySystem.cs +++ b/Assets/TEngine/Scripts/Runtime/Entity/EntitySystem.cs @@ -1091,7 +1091,7 @@ namespace TEngine.Runtime.Entity /// 用户自定义数据。 private void OnShowEntitySuccess(IEntity entity, float duration, object userData) { - GameEventMgr.Instance.Send(EntityEvent.ShowEntitySuccess,entity,duration,userData); + GameEvent.Send(EntityEvent.ShowEntitySuccess,entity,duration,userData); } /// @@ -1109,7 +1109,7 @@ namespace TEngine.Runtime.Entity entityAssetName, entityGroupName, errorMessage); - GameEventMgr.Instance.Send(EntityEvent.ShowEntityFailure,entityId,entityAssetName,entityGroupName,errorMessage,userData); + GameEvent.Send(EntityEvent.ShowEntityFailure,entityId,entityAssetName,entityGroupName,errorMessage,userData); } /// @@ -1122,7 +1122,7 @@ namespace TEngine.Runtime.Entity /// 用户自定义数据。 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); } /// @@ -1137,7 +1137,7 @@ namespace TEngine.Runtime.Entity /// 用户自定义数据。 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); } /// @@ -1149,7 +1149,7 @@ namespace TEngine.Runtime.Entity /// 用户自定义数据。 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) diff --git a/Assets/TEngine/Scripts/Runtime/HotUpdate/Scripts/Logic/LoadMgr.cs b/Assets/TEngine/Scripts/Runtime/HotUpdate/Scripts/Logic/LoadMgr.cs index 15925b21..c6b7acf3 100644 --- a/Assets/TEngine/Scripts/Runtime/HotUpdate/Scripts/Logic/LoadMgr.cs +++ b/Assets/TEngine/Scripts/Runtime/HotUpdate/Scripts/Logic/LoadMgr.cs @@ -9,6 +9,7 @@ namespace TEngine.Runtime.HotUpdate #pragma warning disable CS0162 public class LoadMgr : TSingleton { + public static int DownLoadFinish = StringId.StringToHash("DownLoadResult.AllDownLoaded"); /// /// 资源版本号 /// @@ -31,7 +32,7 @@ namespace TEngine.Runtime.HotUpdate if (result == (int)DownLoadResult.AllDownLoaded) { _UnPackCallback(100, status, 100); - GameEventMgr.Instance.Send("DownLoadResult.AllDownLoaded", true); + GameEvent.Send(DownLoadFinish, true); _StopLoadingCheck(); } else diff --git a/Assets/TEngine/Scripts/Runtime/UIModule/Scripts/UI/UIBase.cs b/Assets/TEngine/Scripts/Runtime/UIModule/Scripts/UI/UIBase.cs index be7c3910..326a3df9 100644 --- a/Assets/TEngine/Scripts/Runtime/UIModule/Scripts/UI/UIBase.cs +++ b/Assets/TEngine/Scripts/Runtime/UIModule/Scripts/UI/UIBase.cs @@ -19,7 +19,7 @@ namespace TEngine.Runtime.UIModule { if (m_eventMgr == null) { - m_eventMgr = GameEventMgr.Instance; + m_eventMgr = MemoryPool.Acquire(); } return m_eventMgr; @@ -61,42 +61,29 @@ namespace TEngine.Runtime.UIModule #region Event - private Dictionary m_eventTable = new Dictionary(); - protected void ClearAllRegisterEvent() { - var element = m_eventTable.GetEnumerator(); - while (element.MoveNext()) - { - var m_event = element.Current.Value; - //GameEventMgr.Instance.RemoveEventListener(element.Current.Key, m_event); - } - - m_eventTable.Clear(); + MemoryPool.Release(m_eventMgr); } protected void AddUIEvent(int eventType, Action handler) { - m_eventTable.Add(eventType, handler); - EventMgr.AddEventListener(eventType, handler); + EventMgr.AddUIEvent(eventType, handler); } protected void AddUIEvent(int eventType, Action handler) { - m_eventTable.Add(eventType, handler); - EventMgr.AddEventListener(eventType, handler); + EventMgr.AddUIEvent(eventType, handler); } protected void AddUIEvent(int eventType, Action handler) { - m_eventTable.Add(eventType, handler); - EventMgr.AddEventListener(eventType, handler); + EventMgr.AddUIEvent(eventType, handler); } protected void AddUIEvent(int eventType, Action handler) { - m_eventTable.Add(eventType, handler); - EventMgr.AddEventListener(eventType, handler); + EventMgr.AddUIEvent(eventType, handler); } #endregion diff --git a/Assets/TEngine/Scripts/Runtime/UIModule/Scripts/UI/UIWindowBase.cs b/Assets/TEngine/Scripts/Runtime/UIModule/Scripts/UI/UIWindowBase.cs index 9eddf2b2..ac49d77a 100644 --- a/Assets/TEngine/Scripts/Runtime/UIModule/Scripts/UI/UIWindowBase.cs +++ b/Assets/TEngine/Scripts/Runtime/UIModule/Scripts/UI/UIWindowBase.cs @@ -143,6 +143,8 @@ namespace TEngine.Runtime.UIModule m_destroyed = true; + ClearAllRegisterEvent(); + DestroyAllChild(); OnDestroy();