From 879f74b7bf8bf059c4055d289f0d7e662b7c91c4 Mon Sep 17 00:00:00 2001 From: Ding Yuntian <1491671119@qq.com> Date: Thu, 16 Jan 2025 19:21:33 +0800 Subject: [PATCH] =?UTF-8?q?EventSystem=E6=89=A9=E5=B1=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scenes/Persistence.unity | 12 +-- .../FixSystemNew/BodyModule/BodyModule.cs | 12 +-- Assets/Scripts/Framework/Core/EventKit.cs | 2 +- Assets/Scripts/Framework/EventSystemKit.meta | 8 ++ .../Framework/EventSystemKit/EventSystemEx.cs | 66 ++++++++++++++ .../EventSystemKit/EventSystemEx.cs.meta | 3 + .../EventSystemKit/EventTriggerEx.cs | 86 +++++++++++++++++++ .../EventTriggerEx.cs.meta} | 2 +- .../Framework/OtherKit/EventSystemEx.cs | 29 ------- Assets/Scripts/UI/Cursor/CursorManager.cs | 54 +++++++++++- Assets/Scripts/UI/DialogUI/DialogBoxBase.cs | 13 +-- 11 files changed, 234 insertions(+), 53 deletions(-) create mode 100644 Assets/Scripts/Framework/EventSystemKit.meta create mode 100644 Assets/Scripts/Framework/EventSystemKit/EventSystemEx.cs create mode 100644 Assets/Scripts/Framework/EventSystemKit/EventSystemEx.cs.meta create mode 100644 Assets/Scripts/Framework/EventSystemKit/EventTriggerEx.cs rename Assets/Scripts/Framework/{OtherKit/EventSystemEx.cs.meta => EventSystemKit/EventTriggerEx.cs.meta} (83%) delete mode 100644 Assets/Scripts/Framework/OtherKit/EventSystemEx.cs diff --git a/Assets/Scenes/Persistence.unity b/Assets/Scenes/Persistence.unity index c77265fc4..dc02c3341 100644 --- a/Assets/Scenes/Persistence.unity +++ b/Assets/Scenes/Persistence.unity @@ -6198,7 +6198,7 @@ Transform: m_GameObject: {fileID: 519420028} serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -0.009999275, y: 0, z: -10} + m_LocalPosition: {x: 0, y: 0, z: -10} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] @@ -6218,7 +6218,7 @@ MonoBehaviour: m_EditorClassIdentifier: m_EventMask: serializedVersion: 2 - m_Bits: 4294967295 + m_Bits: 983 m_MaxRayIntersections: 0 --- !u!114 &519420034 MonoBehaviour: @@ -8106,7 +8106,7 @@ MonoBehaviour: - {fileID: 11400000, guid: fe71f935f1f9a52458c994362567a211, type: 2} runMode: 0 firstTalkSo: {fileID: 11400000, guid: 6d49b124127007b48b6881ce33350263, type: 2} - testTalkSo: {fileID: 11400000, guid: 10601ce26230723479d875a630f15732, type: 2} + testTalkSo: {fileID: 11400000, guid: 6d49b124127007b48b6881ce33350263, type: 2} saveFileName: StoneDay1_5 --- !u!4 &719228339 Transform: @@ -13395,8 +13395,8 @@ Transform: m_ConstrainProportionsScale: 0 m_Children: - {fileID: 947129552} - - {fileID: 984233631} - {fileID: 1788453626} + - {fileID: 984233631} - {fileID: 1604842429} - {fileID: 515480973} - {fileID: 2302717115629548829} @@ -16310,7 +16310,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: m_FirstSelected: {fileID: 0} - m_sendNavigationEvents: 1 + m_sendNavigationEvents: 0 m_DragThreshold: 10 --- !u!4 &1655147933 Transform: @@ -18229,7 +18229,7 @@ MonoBehaviour: yarnProject: {fileID: 0} _variableStorage: {fileID: 667130563} dialogueViews: - - {fileID: 0} + - {fileID: 1584263515} startNode: Start startAutomatically: 0 runSelectedOptionAsLine: 0 diff --git a/Assets/Scripts/FixSystemNew/BodyModule/BodyModule.cs b/Assets/Scripts/FixSystemNew/BodyModule/BodyModule.cs index b9cf324ad..e598e0745 100644 --- a/Assets/Scripts/FixSystemNew/BodyModule/BodyModule.cs +++ b/Assets/Scripts/FixSystemNew/BodyModule/BodyModule.cs @@ -59,12 +59,12 @@ namespace AibisDream.FixSystem public void PlugIn() { - // 插入就在示波器显示图片 - if (!_bodyModuleSystem.inHotErr) - { - StartCoroutine(FixSystemCenter.SystemDic.Get() - ?.ShowScanImage(data.ScreenPic, data.checkPoints)); - } + // // 插入就在示波器显示图片 + // if (!_bodyModuleSystem.inHotErr) + // { + // StartCoroutine(FixSystemCenter.SystemDic.Get() + // ?.ShowScanImage(data.ScreenPic, data.checkPoints)); + // } if (DialogController.Instance) // 然后触发Yarn节点 diff --git a/Assets/Scripts/Framework/Core/EventKit.cs b/Assets/Scripts/Framework/Core/EventKit.cs index 23aae2916..b4b4c2638 100644 --- a/Assets/Scripts/Framework/Core/EventKit.cs +++ b/Assets/Scripts/Framework/Core/EventKit.cs @@ -49,7 +49,7 @@ namespace AibisDream.Framework } } - public IUnRegister Register(T key, Action onEvent) where T : IConvertible where TE : struct + public IUnRegister Register(T key, Action onEvent) where T : IConvertible { var kv = key.ToInt32(null); diff --git a/Assets/Scripts/Framework/EventSystemKit.meta b/Assets/Scripts/Framework/EventSystemKit.meta new file mode 100644 index 000000000..62938b287 --- /dev/null +++ b/Assets/Scripts/Framework/EventSystemKit.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 630fe61c68acf6e49a99491b75ac5566 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Framework/EventSystemKit/EventSystemEx.cs b/Assets/Scripts/Framework/EventSystemKit/EventSystemEx.cs new file mode 100644 index 000000000..f0d04ae81 --- /dev/null +++ b/Assets/Scripts/Framework/EventSystemKit/EventSystemEx.cs @@ -0,0 +1,66 @@ +using AibisDream.Kit; +using UnityEngine; + +namespace AibisDream.Framework +{ + public class EventSystemEx : SingletonBase + { + public GameObject pointerOverObj; + public GameObject draggingObj; + public GameObject holdingObj; + + #region 事件触发中转 + + public void OnPointerEnter(GameObject gameObject) + { + pointerOverObj = gameObject; + EnumEventSystem.Global.Send(TriggerEnum.PointerEnter, gameObject); + } + + public void OnPointerExit(GameObject gameObject) + { + EnumEventSystem.Global.Send(TriggerEnum.PointerExit, gameObject); + if (pointerOverObj == gameObject) + { + pointerOverObj = null; + } + } + + public void OnPointerDown(GameObject gameObject) + { + EnumEventSystem.Global.Send(TriggerEnum.PointerDown, gameObject); + holdingObj = gameObject; + } + + public void OnPointerUp(GameObject gameObject) + { + EnumEventSystem.Global.Send(TriggerEnum.PointerUp, gameObject); + if (holdingObj == gameObject) + { + holdingObj = null; + } + } + + #endregion + + #region 单例必须的代码 + + private EventSystemEx() + { + } + + public override void OnSingletonInit() + { + } + + #endregion + } + + public enum TriggerEnum + { + PointerEnter, + PointerExit, + PointerDown, + PointerUp + } +} \ No newline at end of file diff --git a/Assets/Scripts/Framework/EventSystemKit/EventSystemEx.cs.meta b/Assets/Scripts/Framework/EventSystemKit/EventSystemEx.cs.meta new file mode 100644 index 000000000..e2711409c --- /dev/null +++ b/Assets/Scripts/Framework/EventSystemKit/EventSystemEx.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: f55689aa6dac4461bba273d8987762dd +timeCreated: 1737014094 \ No newline at end of file diff --git a/Assets/Scripts/Framework/EventSystemKit/EventTriggerEx.cs b/Assets/Scripts/Framework/EventSystemKit/EventTriggerEx.cs new file mode 100644 index 000000000..d80982acb --- /dev/null +++ b/Assets/Scripts/Framework/EventSystemKit/EventTriggerEx.cs @@ -0,0 +1,86 @@ +using System.Linq; +using UnityEngine; +using UnityEngine.Events; +using UnityEngine.EventSystems; + +namespace AibisDream.Framework +{ + /// + /// EventTrigger扩展 + /// + [RequireComponent(typeof(Collider2D))] + public class EventTriggerEx : EventTrigger + { + /// + /// 注册事件 + /// + /// 事件类型 + /// 函数 + public void Register(EventTriggerType triggerType, UnityAction action) + { + if (TryGetTriggerEvent(triggerType, out var triggerEvent)) + { + triggerEvent.AddListener(action); + } + else + { + Debug.LogWarning($"{triggerType.ToString()}未添加"); + } + } + + /// + /// 卸载事件 + /// + /// 事件类型 + /// 函数 + public void UnRegister(EventTriggerType triggerType, UnityAction action) + { + if (TryGetTriggerEvent(triggerType, out var triggerEvent)) + { + triggerEvent.RemoveListener(action); + } + else + { + Debug.LogWarning($"{triggerType.ToString()}未添加"); + } + } + + /// + /// 获取触发事件 + /// + /// 事件类型 + /// 事件 + /// 是否存在 + private bool TryGetTriggerEvent(EventTriggerType triggerType, out TriggerEvent triggerEvent) + { + var entry = triggers.FirstOrDefault(item => item.eventID == triggerType); + if (entry == null) + { + triggerEvent = null; + return false; + } + else + { + triggerEvent = entry.callback; + return true; + } + } + + public override void OnPointerEnter(PointerEventData data) + { + EventSystemEx.Instance.OnPointerEnter(gameObject); + base.OnPointerEnter(data); + } + + public override void OnPointerExit(PointerEventData data) + { + EventSystemEx.Instance.OnPointerExit(gameObject); + base.OnPointerExit(data); + } + + public override void OnPointerDown(PointerEventData eventData) + { + + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Framework/OtherKit/EventSystemEx.cs.meta b/Assets/Scripts/Framework/EventSystemKit/EventTriggerEx.cs.meta similarity index 83% rename from Assets/Scripts/Framework/OtherKit/EventSystemEx.cs.meta rename to Assets/Scripts/Framework/EventSystemKit/EventTriggerEx.cs.meta index 3af55ca4e..a2a3daa0f 100644 --- a/Assets/Scripts/Framework/OtherKit/EventSystemEx.cs.meta +++ b/Assets/Scripts/Framework/EventSystemKit/EventTriggerEx.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 8e1d0d6ab059a9b4a8979dbd0c8b2b68 +guid: 0c4fbab01ad40c2449c849cd2a8c620f MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Scripts/Framework/OtherKit/EventSystemEx.cs b/Assets/Scripts/Framework/OtherKit/EventSystemEx.cs deleted file mode 100644 index 4ea6db3ce..000000000 --- a/Assets/Scripts/Framework/OtherKit/EventSystemEx.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace AibisDream.Framework -{ - [RequireComponent(typeof(EventSystem))] - public class EventSystemExtension : MonoBehaviour - { - public string targetTag; - - #region 物体索引 - - private GameObject _lastObject; - - #endregion - - public void LateUpdate() - { - // if () - // { - // - // } - - var curGameObject = EventSystem.current.currentSelectedGameObject; - } - } -} - diff --git a/Assets/Scripts/UI/Cursor/CursorManager.cs b/Assets/Scripts/UI/Cursor/CursorManager.cs index 38e45c1a6..5cae2c5c8 100644 --- a/Assets/Scripts/UI/Cursor/CursorManager.cs +++ b/Assets/Scripts/UI/Cursor/CursorManager.cs @@ -1,4 +1,5 @@ -using System.Collections; +using System; +using System.Collections; using System.Collections.Generic; using AibisDream.Framework; using UnityEngine; @@ -20,6 +21,7 @@ namespace AibisDream private Coroutine _switchCoroutine; private CursorState _curState = CursorState.Default; + private bool _isTalking = false; #endregion @@ -65,7 +67,7 @@ namespace AibisDream // 此处监听所有可能对鼠标状态产生影响的事件 // 对话相关 _unRegisters.Add(EnumEventSystem.Global.Register(DialogEventEnum.LineStart, - _ => SwitchCursor(talking))); + OnLineStart)); _unRegisters.Add(EnumEventSystem.Global.Register(DialogEventEnum.LineShowed, () => SwitchCursor(nextTalk))); _unRegisters.Add(EnumEventSystem.Global.Register(DialogEventEnum.LineEnd, () => SwitchCursorDelay(defaultCursor))); @@ -77,6 +79,9 @@ namespace AibisDream // 交互相关 _unRegisters.Add(EnumEventSystem.Global.Register(InteractionEventEnum.Start, OnInteractiveStart)); _unRegisters.Add(EnumEventSystem.Global.Register(InteractionEventEnum.End, OnInteractiveEnd)); + + _unRegisters.Add( + EnumEventSystem.Global.Register(TriggerEnum.PointerEnter, OnPointerEnter)); } private void LateUpdate() @@ -90,7 +95,22 @@ namespace AibisDream // 在输入状态,要单独处理 } - #region 交互状态相关 + #region 对话相关 + + private void OnLineStart(DialogLine line) + { + _isTalking = true; + SwitchCursor(talking); + } + + private void OnLineEnd() + { + + } + + #endregion + + #region 交互相关 private void OnInteractiveStart() { @@ -99,7 +119,25 @@ namespace AibisDream private void OnInteractiveEnd() { - _curState = CursorState.Interactive; + _curState = CursorState.Default; + // 退出时把Cursor置为Default + SwitchCursor(defaultCursor); + } + + private void OnPointerEnter(GameObject target) + { + if (_curState == CursorState.Interactive) + { + SwitchCursor(interactive); + } + } + + private void OnPointerExit(GameObject target) + { + if (_curState == CursorState.Interactive) + { + SwitchCursor(defaultCursor); + } } #endregion @@ -115,6 +153,8 @@ namespace AibisDream StopDelayCursor(); _cursor.sprite = sprite; } + + /// /// 延迟切换指针。如果后面有其他切换状态,就直接打断 @@ -142,6 +182,12 @@ namespace AibisDream } #endregion + + private static IEnumerator DelayAction(Action action) + { + yield return new WaitForSeconds(DelayTime); + action.Invoke(); + } } public enum CursorState diff --git a/Assets/Scripts/UI/DialogUI/DialogBoxBase.cs b/Assets/Scripts/UI/DialogUI/DialogBoxBase.cs index face63efe..db8f3f90a 100644 --- a/Assets/Scripts/UI/DialogUI/DialogBoxBase.cs +++ b/Assets/Scripts/UI/DialogUI/DialogBoxBase.cs @@ -91,11 +91,11 @@ namespace AibisDream bool isAutoSkip = false) { gameObject.SetActive(true); - // 没有dialogText说明不能显示对话,直接跳过 - if (!dialogText) - { - return; - } + // // 没有dialogText说明不能显示对话,直接跳过 + // if (!dialogText) + // { + // return; + // } // 把原有对话清掉 ClearBox(); @@ -126,8 +126,9 @@ namespace AibisDream if (_nextStep == null) return; EnumEventSystem.Global.Send(DialogEventEnum.LineEnd); - _nextStep.Invoke(); + var next = _nextStep; _nextStep = null; + next.Invoke(); } ///