指针功能完成,齿轮未接入

This commit is contained in:
2025-01-16 22:20:04 +08:00
parent b80d78ad23
commit 74025f3d5b
11 changed files with 123 additions and 398 deletions
+57 -26
View File
@@ -9,7 +9,7 @@ namespace AibisDream
{
public class CursorManager : MonoBehaviour
{
private const float DelayTime = 0.2f;
private const float DelayTime = 0.1f;
[Header("指针图片")] public Sprite defaultCursor;
public Sprite nextTalk, talking, option, interactive, holding, disable, eye;
@@ -21,12 +21,12 @@ namespace AibisDream
private Coroutine _switchCoroutine;
private CursorState _curState = CursorState.Default;
private bool _isTalking = false;
private bool _isTalking;
#endregion
// 卸载时注销事件
private List<IUnRegister> _unRegisters = new();
private readonly List<IUnRegister> _unRegisters = new();
public void Awake()
{
@@ -69,12 +69,11 @@ namespace AibisDream
_unRegisters.Add(EnumEventSystem.Global.Register<DialogEventEnum, DialogLine>(DialogEventEnum.LineStart,
OnLineStart));
_unRegisters.Add(EnumEventSystem.Global.Register(DialogEventEnum.LineShowed, () => SwitchCursor(nextTalk)));
_unRegisters.Add(EnumEventSystem.Global.Register(DialogEventEnum.LineEnd,
() => SwitchCursorDelay(defaultCursor)));
_unRegisters.Add(EnumEventSystem.Global.Register(DialogEventEnum.OptionShow, () => SwitchCursor(option)));
_unRegisters.Add(EnumEventSystem.Global.Register(DialogEventEnum.LineEnd, OnLineEnd));
_unRegisters.Add(EnumEventSystem.Global.Register(DialogEventEnum.OptionShow, OnOptionShow));
_unRegisters.Add(
EnumEventSystem.Global.Register<DialogEventEnum, DialogLine>(DialogEventEnum.OptionSelected,
_ => SwitchCursorDelay(defaultCursor)));
OnOptionSelect));
// 交互相关
_unRegisters.Add(EnumEventSystem.Global.Register(InteractionEventEnum.Start, OnInteractiveStart));
@@ -82,6 +81,12 @@ namespace AibisDream
_unRegisters.Add(
EnumEventSystem.Global.Register<TriggerEnum, GameObject>(TriggerEnum.PointerEnter, OnPointerEnter));
_unRegisters.Add(
EnumEventSystem.Global.Register<TriggerEnum, GameObject>(TriggerEnum.PointerExit, OnPointerExit));
_unRegisters.Add(
EnumEventSystem.Global.Register<TriggerEnum, GameObject>(TriggerEnum.PointerDown, OnPointerDown));
_unRegisters.Add(
EnumEventSystem.Global.Register<TriggerEnum, GameObject>(TriggerEnum.PointerUp, OnPointerUp));
}
private void LateUpdate()
@@ -105,7 +110,28 @@ namespace AibisDream
private void OnLineEnd()
{
StopDelayCursor();
_switchCoroutine = StartCoroutine(DelayAction(() =>
{
_isTalking = false;
_cursor.sprite = defaultCursor;
}));
}
private void OnOptionShow()
{
_isTalking = true;
SwitchCursor(option);
}
private void OnOptionSelect(DialogLine line)
{
StopDelayCursor();
StartCoroutine(DelayAction(() =>
{
_isTalking = false;
_cursor.sprite = defaultCursor;
}));
}
#endregion
@@ -115,6 +141,10 @@ namespace AibisDream
private void OnInteractiveStart()
{
_curState = CursorState.Interactive;
if (EventSystemEx.Instance.pointerOverObj)
{
SwitchCursor(interactive);
}
}
private void OnInteractiveEnd()
@@ -126,7 +156,7 @@ namespace AibisDream
private void OnPointerEnter(GameObject target)
{
if (_curState == CursorState.Interactive)
if (_curState == CursorState.Interactive && !_isTalking)
{
SwitchCursor(interactive);
}
@@ -134,12 +164,29 @@ namespace AibisDream
private void OnPointerExit(GameObject target)
{
if (_curState == CursorState.Interactive)
if (_curState == CursorState.Interactive && !_isTalking)
{
SwitchCursor(defaultCursor);
}
}
private void OnPointerDown(GameObject target)
{
if (_curState == CursorState.Interactive && !_isTalking)
{
SwitchCursor(holding);
}
}
private void OnPointerUp(GameObject target)
{
if (_curState == CursorState.Interactive && !_isTalking)
{
// 如果松手时还在物体之上
SwitchCursor(EventSystemEx.Instance.holdingObj == target ? interactive : defaultCursor);
}
}
#endregion
#region
@@ -154,22 +201,6 @@ namespace AibisDream
_cursor.sprite = sprite;
}
/// <summary>
/// 延迟切换指针。如果后面有其他切换状态,就直接打断
/// </summary>
/// <param name="sprite">指针图片</param>
private void SwitchCursorDelay(Sprite sprite)
{
StopDelayCursor();
_switchCoroutine = StartCoroutine(SwitchCursorAsync(sprite));
}
private IEnumerator SwitchCursorAsync(Sprite sprite)
{
yield return new WaitForSeconds(DelayTime);
_cursor.sprite = sprite;
}
private void StopDelayCursor()
{
if (_switchCoroutine != null)