77 lines
2.5 KiB
C#
77 lines
2.5 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace Cielonos.MainGame.Characters
|
|
{
|
|
public partial class PlayerInputSubcontroller
|
|
{
|
|
public class PlayerPreinputSubmodule : SubmoduleBase<PlayerInputSubcontroller>
|
|
{
|
|
public const int DashDodgePreinputPriority = 100;
|
|
|
|
public class PlayerPreinputRequest
|
|
{
|
|
public string actionId;
|
|
public int priority;
|
|
public Action action;
|
|
|
|
public PlayerPreinputRequest(string actionId, Action action, int priority)
|
|
{
|
|
this.actionId = actionId;
|
|
this.action = action;
|
|
this.priority = priority;
|
|
}
|
|
|
|
public void Execute()
|
|
{
|
|
action?.Invoke();
|
|
}
|
|
}
|
|
|
|
public bool isReceivingPreinput;
|
|
public int currentPreinputPriority;
|
|
public PlayerPreinputRequest currentRequest;
|
|
|
|
public PlayerPreinputSubmodule(PlayerInputSubcontroller owner) : base(owner)
|
|
{
|
|
Reset();
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
isReceivingPreinput = false;
|
|
currentPreinputPriority = int.MinValue;
|
|
currentRequest = null;
|
|
}
|
|
|
|
public void Update(bool isReceiving, bool canExecute)
|
|
{
|
|
isReceivingPreinput = isReceiving;
|
|
|
|
if (canExecute)
|
|
{
|
|
//Debug.Log($"Executing preinput action with priority {currentPreinputPriority}");
|
|
currentRequest?.Execute();
|
|
Reset();
|
|
}
|
|
}
|
|
|
|
public void RegisterPreinputAction(Action action, int priority)
|
|
{
|
|
RegisterPreinputAction(null, action, priority);
|
|
}
|
|
|
|
public void RegisterPreinputAction(string actionId, Action action, int priority)
|
|
{
|
|
//Debug.Log($"Registering preinput action with priority {priority}, current priority is {currentPreinputPriority}, isReceivingPreinput: {isReceivingPreinput}");
|
|
if (isReceivingPreinput && priority >= currentPreinputPriority)
|
|
{
|
|
//Debug.Log($"Preinput action registered.");
|
|
currentRequest = new PlayerPreinputRequest(actionId, action, priority);
|
|
currentPreinputPriority = priority;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|