92 lines
2.5 KiB
C#
92 lines
2.5 KiB
C#
using AibisDream.Framework;
|
|
using UnityEngine;
|
|
|
|
namespace AibisDream
|
|
{
|
|
public class LineAdvanceInput : MonoBehaviour
|
|
{
|
|
#region 状态
|
|
|
|
private bool _inGame;
|
|
private bool _isDialog;
|
|
private LineSyncToken _curSyncToken;
|
|
|
|
#endregion
|
|
|
|
[SerializeField] private KeyCode advanceKey;
|
|
|
|
private void OnEnable()
|
|
{
|
|
RegisterEvents();
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
UnRegisterEvents();
|
|
}
|
|
|
|
public void RunLine(LineSyncToken lineSyncEvent)
|
|
{
|
|
_curSyncToken = lineSyncEvent;
|
|
}
|
|
|
|
private bool IsInputAvailable()
|
|
{
|
|
return _inGame && _isDialog && _curSyncToken != null && _curSyncToken.state != LineSyncState.Advanced;
|
|
}
|
|
|
|
private void OnAdvanceInput()
|
|
{
|
|
if (!IsInputAvailable())
|
|
{
|
|
return;
|
|
}
|
|
|
|
switch (_curSyncToken.state)
|
|
{
|
|
case LineSyncState.PlayText:
|
|
_curSyncToken.TrySkip();
|
|
break;
|
|
case LineSyncState.WaitForAdvance:
|
|
_curSyncToken.TryAdvance();
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.Space))
|
|
{
|
|
OnAdvanceInput();
|
|
}
|
|
}
|
|
|
|
#region 事件处理
|
|
|
|
private IUnRegister[] _unRegisters;
|
|
|
|
private void RegisterEvents()
|
|
{
|
|
_unRegisters = new IUnRegister[6];
|
|
|
|
_unRegisters[0] = EnumEventSystem.Global.Register(GameLoopEnum.GameStart, () => _inGame = true);
|
|
_unRegisters[1] = EnumEventSystem.Global.Register(GameLoopEnum.UnPauseGame, () => _inGame = true);
|
|
|
|
_unRegisters[2] = EnumEventSystem.Global.Register(GameLoopEnum.GameQuit, () => _inGame = false);
|
|
_unRegisters[3] = EnumEventSystem.Global.Register(GameLoopEnum.PauseGame, () => _inGame = false);
|
|
|
|
_unRegisters[4] = EnumEventSystem.Global.Register(InteractionEventEnum.DialogStart, () => _isDialog = true);
|
|
_unRegisters[5] = EnumEventSystem.Global.Register(InteractionEventEnum.DialogEnd, () => _isDialog = true);
|
|
}
|
|
|
|
private void UnRegisterEvents()
|
|
{
|
|
foreach (var unRegister in _unRegisters)
|
|
{
|
|
unRegister.UnRegister();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |