EventSystem扩展
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user