修改 掏出工具逻辑

This commit is contained in:
YangHua 2024-09-03 18:30:49 +08:00
parent 5f1e34b3d0
commit c4d6ab745f
4 changed files with 63 additions and 20 deletions

View File

@ -17,6 +17,7 @@ public class LiveSceneManager : SingletonMono<LiveSceneManager>
base.Awake(); base.Awake();
firstPersonController = GameObject.FindGameObjectWithTag("Player").GetComponent<FirstPersonController>(); firstPersonController = GameObject.FindGameObjectWithTag("Player").GetComponent<FirstPersonController>();
tMDTips.gameObject.SetActive(false); tMDTips.gameObject.SetActive(false);
GameManager.EventMgr.AddEventListener<GameObject>(Enum_EventType.TakeOutAndRetrievingTheTools, SetSpawnToolInfo);
firstPersonController.zoomAction += OnZoom; firstPersonController.zoomAction += OnZoom;
} }
@ -26,6 +27,7 @@ public class LiveSceneManager : SingletonMono<LiveSceneManager>
} }
public void SetSpawnToolInfo(GameObject tool) public void SetSpawnToolInfo(GameObject tool)
{ {
if (tool == null) return;
currentTool = tool; currentTool = tool;
currentTool.transform.parent = Camera.main.transform; currentTool.transform.parent = Camera.main.transform;
currentTool.transform.localPosition = spawnToolPos.localPosition; currentTool.transform.localPosition = spawnToolPos.localPosition;
@ -73,8 +75,6 @@ public class LiveSceneManager : SingletonMono<LiveSceneManager>
tMDTips.gameObject.SetActive(false); tMDTips.gameObject.SetActive(false);
currentTool.transform.localEulerAngles = new Vector3(-90, 0, -180); currentTool.transform.localEulerAngles = new Vector3(-90, 0, -180);
} }
if (GameManager.RunModelMgr.ModeType != E_ModeType.Study)
GameManager.EventMgr.EventTrigger<bool>(Enum_EventType.TakeOutAndRetrievingTheTools, false);
} }
private void Update() private void Update()
@ -99,8 +99,7 @@ public class LiveSceneManager : SingletonMono<LiveSceneManager>
if (ifdestroy) if (ifdestroy)
Destroy(currentTool); Destroy(currentTool);
currentTool = null; currentTool = null;
if (GameManager.RunModelMgr.ModeType != E_ModeType.Study) GameManager.EventMgr.EventTrigger<GameObject>(Enum_EventType.TakeOutAndRetrievingTheTools, null);
GameManager.EventMgr.EventTrigger<bool>(Enum_EventType.TakeOutAndRetrievingTheTools, true);
} }
private void OnDestroy() private void OnDestroy()

View File

@ -71,7 +71,8 @@ public class UI_ToolOrMaterialsOrDeviceItem : BaseItem
currentTool.GetComponent<BaseToolOrDevice>().enabled = false; currentTool.GetComponent<BaseToolOrDevice>().enabled = false;
currentTool.GetComponent<Collider>().enabled = false; currentTool.GetComponent<Collider>().enabled = false;
currentTool.name = currentItem.toolName; currentTool.name = currentItem.toolName;
LiveSceneManager.Instance.SetSpawnToolInfo(currentTool); GameManager.EventMgr.EventTrigger<GameObject>(Enum_EventType.TakeOutAndRetrievingTheTools, currentTool);
//LiveSceneManager.Instance.SetSpawnToolInfo(currentTool);
GameManager.UIMgr.imageTips.HideTips(); GameManager.UIMgr.imageTips.HideTips();
} }
break; break;

View File

@ -57,13 +57,13 @@ public class UI_MenuBar : BasePanel
if (GameManager.RunModelMgr.ModeType == E_ModeType.Study) if (GameManager.RunModelMgr.ModeType == E_ModeType.Study)
GameManager.EventMgr.AddEventListener<string>(Enum_EventType.SwitchSubProcessStepTriggerID, SwitchSubProcessStepTriggerID); GameManager.EventMgr.AddEventListener<string>(Enum_EventType.SwitchSubProcessStepTriggerID, SwitchSubProcessStepTriggerID);
else else
GameManager.EventMgr.AddEventListener<bool>(Enum_EventType.TakeOutAndRetrievingTheTools, TakeOutAndRetrievingTheTools); GameManager.EventMgr.AddEventListener<GameObject>(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) private void SwitchSubProcessStepTriggerID(string triggerID)
@ -124,6 +124,8 @@ public class UI_MenuBar : BasePanel
GameManager.EventMgr.RemoveEventListener<E_SceneType>(Enum_EventType.SwitchScene, CheckBtnBySceneName); GameManager.EventMgr.RemoveEventListener<E_SceneType>(Enum_EventType.SwitchScene, CheckBtnBySceneName);
if (GameManager.RunModelMgr.ModeType == E_ModeType.Study) if (GameManager.RunModelMgr.ModeType == E_ModeType.Study)
GameManager.EventMgr.RemoveEventListener<string>(Enum_EventType.SwitchSubProcessStepTriggerID, SwitchSubProcessStepTriggerID); GameManager.EventMgr.RemoveEventListener<string>(Enum_EventType.SwitchSubProcessStepTriggerID, SwitchSubProcessStepTriggerID);
else
GameManager.EventMgr.RemoveEventListener<GameObject>(Enum_EventType.TakeOutAndRetrievingTheTools, TakeOutAndRetrievingTheTools);
} }
public void CheckBtnBySceneName(E_SceneType type) public void CheckBtnBySceneName(E_SceneType type)
{ {

View File

@ -17,9 +17,18 @@ public class EventInfo<T> : IEventInfo
actions += action; actions += action;
} }
} }
public class EventInfo<T, D> : IEventInfo
{
public UnityAction<T, D> actions;
public EventInfo(UnityAction<T, D> action)
{
actions += action;
}
}
public class EventInfo: IEventInfo public class EventInfo : IEventInfo
{ {
public UnityAction actions; public UnityAction actions;
@ -80,6 +89,23 @@ public class EventCenter : BaseManager<EventCenter>
eventEnumDic.Add(type, new EventInfo<T>(action)); eventEnumDic.Add(type, new EventInfo<T>(action));
} }
} }
/// <summary>
/// 添加有多个参事件监听
/// </summary>
/// <typeparam name="T">参数类型</typeparam>
/// <param name="type">事件名称</param>
/// <param name="action">有参委托函数</param>
public void AddEventListener<T,D>(Enum_EventType type, UnityAction<T,D> action)
{
if (eventEnumDic.ContainsKey(type))
{
(eventEnumDic[type] as EventInfo<T,D>).actions += action;
}
else
{
eventEnumDic.Add(type, new EventInfo<T,D>(action));
}
}
/// <summary> /// <summary>
/// 移除无参事件监听 /// 移除无参事件监听
@ -107,6 +133,19 @@ public class EventCenter : BaseManager<EventCenter>
(eventEnumDic[type] as EventInfo<T>).actions -= action; (eventEnumDic[type] as EventInfo<T>).actions -= action;
} }
} }
/// <summary>
/// 移除有多个参事件监听
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="type"></param>
/// <param name="action"></param>
public void RemoveEventListener<T,D>(Enum_EventType type, UnityAction<T,D> action)
{
if (eventEnumDic.ContainsKey(type))
{
(eventEnumDic[type] as EventInfo<T,D>).actions -= action;
}
}
/// <summary> /// <summary>
/// 触发无参事件 /// 触发无参事件
@ -130,7 +169,16 @@ public class EventCenter : BaseManager<EventCenter>
(eventEnumDic[type] as EventInfo<T>).actions?.Invoke(info); (eventEnumDic[type] as EventInfo<T>).actions?.Invoke(info);
} }
} }
/// <summary>
/// 触发有多个参事件
/// </summary>
public void EventTrigger<T, D>(Enum_EventType type, T info, D info2)
{
if (eventEnumDic.ContainsKey(type))
{
(eventEnumDic[type] as EventInfo<T, D>).actions?.Invoke(info, info2);
}
}
/// <summary> /// <summary>
/// 添加无参事件监听 /// 添加无参事件监听
@ -194,6 +242,8 @@ public class EventCenter : BaseManager<EventCenter>
} }
} }
/// <summary> /// <summary>
/// 触发无参事件 /// 触发无参事件
/// </summary> /// </summary>
@ -217,16 +267,7 @@ public class EventCenter : BaseManager<EventCenter>
} }
} }
/// <summary>
/// 触发有参事件
/// </summary>
public void EventTrigger<T,D>(string eventName, T info)
{
if (eventDic.ContainsKey(eventName))
{
(eventDic[eventName] as EventInfo<T>).actions?.Invoke(info);
}
}
/// <summary> /// <summary>
/// 清空所有事件监听 /// 清空所有事件监听