EventSystem扩展

This commit is contained in:
2025-01-16 19:21:33 +08:00
parent cb3eff896d
commit 879f74b7bf
11 changed files with 234 additions and 53 deletions
+6 -6
View File
@@ -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
@@ -59,12 +59,12 @@ namespace AibisDream.FixSystem
public void PlugIn()
{
// 插入就在示波器显示图片
if (!_bodyModuleSystem.inHotErr)
{
StartCoroutine(FixSystemCenter.SystemDic.Get<IOscilloscopeSystem>()
?.ShowScanImage(data.ScreenPic, data.checkPoints));
}
// // 插入就在示波器显示图片
// if (!_bodyModuleSystem.inHotErr)
// {
// StartCoroutine(FixSystemCenter.SystemDic.Get<IOscilloscopeSystem>()
// ?.ShowScanImage(data.ScreenPic, data.checkPoints));
// }
if (DialogController.Instance)
// 然后触发Yarn节点
+1 -1
View File
@@ -49,7 +49,7 @@ namespace AibisDream.Framework
}
}
public IUnRegister Register<T, TE>(T key, Action<TE> onEvent) where T : IConvertible where TE : struct
public IUnRegister Register<T, TE>(T key, Action<TE> onEvent) where T : IConvertible
{
var kv = key.ToInt32(null);
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 630fe61c68acf6e49a99491b75ac5566
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,66 @@
using AibisDream.Kit;
using UnityEngine;
namespace AibisDream.Framework
{
public class EventSystemEx : SingletonBase<EventSystemEx>
{
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
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f55689aa6dac4461bba273d8987762dd
timeCreated: 1737014094
@@ -0,0 +1,86 @@
using System.Linq;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
namespace AibisDream.Framework
{
/// <summary>
/// EventTrigger扩展
/// </summary>
[RequireComponent(typeof(Collider2D))]
public class EventTriggerEx : EventTrigger
{
/// <summary>
/// 注册事件
/// </summary>
/// <param name="triggerType">事件类型</param>
/// <param name="action">函数</param>
public void Register(EventTriggerType triggerType, UnityAction<BaseEventData> action)
{
if (TryGetTriggerEvent(triggerType, out var triggerEvent))
{
triggerEvent.AddListener(action);
}
else
{
Debug.LogWarning($"{triggerType.ToString()}未添加");
}
}
/// <summary>
/// 卸载事件
/// </summary>
/// <param name="triggerType">事件类型</param>
/// <param name="action">函数</param>
public void UnRegister(EventTriggerType triggerType, UnityAction<BaseEventData> action)
{
if (TryGetTriggerEvent(triggerType, out var triggerEvent))
{
triggerEvent.RemoveListener(action);
}
else
{
Debug.LogWarning($"{triggerType.ToString()}未添加");
}
}
/// <summary>
/// 获取触发事件
/// </summary>
/// <param name="triggerType">事件类型</param>
/// <param name="triggerEvent">事件</param>
/// <returns>是否存在</returns>
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)
{
}
}
}
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 8e1d0d6ab059a9b4a8979dbd0c8b2b68
guid: 0c4fbab01ad40c2449c849cd2a8c620f
MonoImporter:
externalObjects: {}
serializedVersion: 2
@@ -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;
}
}
}
+50 -4
View File
@@ -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, DialogLine>(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, GameObject>(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;
}
/// <summary>
/// 延迟切换指针。如果后面有其他切换状态,就直接打断
@@ -142,6 +182,12 @@ namespace AibisDream
}
#endregion
private static IEnumerator DelayAction(Action action)
{
yield return new WaitForSeconds(DelayTime);
action.Invoke();
}
}
public enum CursorState
+7 -6
View File
@@ -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();
}
/// <summary>