From c4d6ab745f1133528f07a91c18e477d4f757d261 Mon Sep 17 00:00:00 2001 From: YangHua <1475658476@qq.com> Date: Tue, 3 Sep 2024 18:30:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20=E6=8E=8F=E5=87=BA?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Project/Manager/LiveSceneManager.cs | 7 +- .../UI_Item/UI_ToolOrMaterialsOrDeviceItem.cs | 3 +- .../Scripts/Project/UI/UI_Panel/UI_MenuBar.cs | 8 ++- .../ProjectBase/EventCenter/EventCenter.cs | 65 +++++++++++++++---- 4 files changed, 63 insertions(+), 20 deletions(-) diff --git a/Assets/Scripts/Project/Manager/LiveSceneManager.cs b/Assets/Scripts/Project/Manager/LiveSceneManager.cs index 996f6e6..396e5c8 100644 --- a/Assets/Scripts/Project/Manager/LiveSceneManager.cs +++ b/Assets/Scripts/Project/Manager/LiveSceneManager.cs @@ -17,6 +17,7 @@ public class LiveSceneManager : SingletonMono base.Awake(); firstPersonController = GameObject.FindGameObjectWithTag("Player").GetComponent(); tMDTips.gameObject.SetActive(false); + GameManager.EventMgr.AddEventListener(Enum_EventType.TakeOutAndRetrievingTheTools, SetSpawnToolInfo); firstPersonController.zoomAction += OnZoom; } @@ -26,6 +27,7 @@ public class LiveSceneManager : SingletonMono } public void SetSpawnToolInfo(GameObject tool) { + if (tool == null) return; currentTool = tool; currentTool.transform.parent = Camera.main.transform; currentTool.transform.localPosition = spawnToolPos.localPosition; @@ -73,8 +75,6 @@ public class LiveSceneManager : SingletonMono tMDTips.gameObject.SetActive(false); currentTool.transform.localEulerAngles = new Vector3(-90, 0, -180); } - if (GameManager.RunModelMgr.ModeType != E_ModeType.Study) - GameManager.EventMgr.EventTrigger(Enum_EventType.TakeOutAndRetrievingTheTools, false); } private void Update() @@ -99,8 +99,7 @@ public class LiveSceneManager : SingletonMono if (ifdestroy) Destroy(currentTool); currentTool = null; - if (GameManager.RunModelMgr.ModeType != E_ModeType.Study) - GameManager.EventMgr.EventTrigger(Enum_EventType.TakeOutAndRetrievingTheTools, true); + GameManager.EventMgr.EventTrigger(Enum_EventType.TakeOutAndRetrievingTheTools, null); } private void OnDestroy() diff --git a/Assets/Scripts/Project/UI/UI_Item/UI_ToolOrMaterialsOrDeviceItem.cs b/Assets/Scripts/Project/UI/UI_Item/UI_ToolOrMaterialsOrDeviceItem.cs index 844583f..1624c35 100644 --- a/Assets/Scripts/Project/UI/UI_Item/UI_ToolOrMaterialsOrDeviceItem.cs +++ b/Assets/Scripts/Project/UI/UI_Item/UI_ToolOrMaterialsOrDeviceItem.cs @@ -71,7 +71,8 @@ public class UI_ToolOrMaterialsOrDeviceItem : BaseItem currentTool.GetComponent().enabled = false; currentTool.GetComponent().enabled = false; currentTool.name = currentItem.toolName; - LiveSceneManager.Instance.SetSpawnToolInfo(currentTool); + GameManager.EventMgr.EventTrigger(Enum_EventType.TakeOutAndRetrievingTheTools, currentTool); + //LiveSceneManager.Instance.SetSpawnToolInfo(currentTool); GameManager.UIMgr.imageTips.HideTips(); } break; diff --git a/Assets/Scripts/Project/UI/UI_Panel/UI_MenuBar.cs b/Assets/Scripts/Project/UI/UI_Panel/UI_MenuBar.cs index 5d9aa50..e833b8e 100644 --- a/Assets/Scripts/Project/UI/UI_Panel/UI_MenuBar.cs +++ b/Assets/Scripts/Project/UI/UI_Panel/UI_MenuBar.cs @@ -57,13 +57,13 @@ public class UI_MenuBar : BasePanel if (GameManager.RunModelMgr.ModeType == E_ModeType.Study) GameManager.EventMgr.AddEventListener(Enum_EventType.SwitchSubProcessStepTriggerID, SwitchSubProcessStepTriggerID); else - GameManager.EventMgr.AddEventListener(Enum_EventType.TakeOutAndRetrievingTheTools, TakeOutAndRetrievingTheTools); + GameManager.EventMgr.AddEventListener(Enum_EventType.TakeOutAndRetrievingTheTools, TakeOutAndRetrievingTheTools); } - private void TakeOutAndRetrievingTheTools(bool isOn) + private void TakeOutAndRetrievingTheTools(GameObject obj) { - toolKitBtn.interactable = isOn; + toolKitBtn.interactable = (obj == null); } private void SwitchSubProcessStepTriggerID(string triggerID) @@ -124,6 +124,8 @@ public class UI_MenuBar : BasePanel GameManager.EventMgr.RemoveEventListener(Enum_EventType.SwitchScene, CheckBtnBySceneName); if (GameManager.RunModelMgr.ModeType == E_ModeType.Study) GameManager.EventMgr.RemoveEventListener(Enum_EventType.SwitchSubProcessStepTriggerID, SwitchSubProcessStepTriggerID); + else + GameManager.EventMgr.RemoveEventListener(Enum_EventType.TakeOutAndRetrievingTheTools, TakeOutAndRetrievingTheTools); } public void CheckBtnBySceneName(E_SceneType type) { diff --git a/Assets/Scripts/ProjectBase/EventCenter/EventCenter.cs b/Assets/Scripts/ProjectBase/EventCenter/EventCenter.cs index 94552d9..e505308 100644 --- a/Assets/Scripts/ProjectBase/EventCenter/EventCenter.cs +++ b/Assets/Scripts/ProjectBase/EventCenter/EventCenter.cs @@ -17,9 +17,18 @@ public class EventInfo : IEventInfo actions += action; } } +public class EventInfo : IEventInfo +{ + public UnityAction actions; + + public EventInfo(UnityAction action) + { + actions += action; + } +} -public class EventInfo: IEventInfo +public class EventInfo : IEventInfo { public UnityAction actions; @@ -80,6 +89,23 @@ public class EventCenter : BaseManager eventEnumDic.Add(type, new EventInfo(action)); } } + /// + /// 添加有多个参事件监听 + /// + /// 参数类型 + /// 事件名称 + /// 有参委托函数 + public void AddEventListener(Enum_EventType type, UnityAction action) + { + if (eventEnumDic.ContainsKey(type)) + { + (eventEnumDic[type] as EventInfo).actions += action; + } + else + { + eventEnumDic.Add(type, new EventInfo(action)); + } + } /// /// 移除无参事件监听 @@ -107,6 +133,19 @@ public class EventCenter : BaseManager (eventEnumDic[type] as EventInfo).actions -= action; } } + /// + /// 移除有多个参事件监听 + /// + /// + /// + /// + public void RemoveEventListener(Enum_EventType type, UnityAction action) + { + if (eventEnumDic.ContainsKey(type)) + { + (eventEnumDic[type] as EventInfo).actions -= action; + } + } /// /// 触发无参事件 @@ -130,7 +169,16 @@ public class EventCenter : BaseManager (eventEnumDic[type] as EventInfo).actions?.Invoke(info); } } - + /// + /// 触发有多个参事件 + /// + public void EventTrigger(Enum_EventType type, T info, D info2) + { + if (eventEnumDic.ContainsKey(type)) + { + (eventEnumDic[type] as EventInfo).actions?.Invoke(info, info2); + } + } /// /// 添加无参事件监听 @@ -194,6 +242,8 @@ public class EventCenter : BaseManager } } + + /// /// 触发无参事件 /// @@ -217,16 +267,7 @@ public class EventCenter : BaseManager } } - /// - /// 触发有参事件 - /// - public void EventTrigger(string eventName, T info) - { - if (eventDic.ContainsKey(eventName)) - { - (eventDic[eventName] as EventInfo).actions?.Invoke(info); - } - } + /// /// 清空所有事件监听