47 lines
1.4 KiB
C#
47 lines
1.4 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace Cielonos.MainGame.Characters
|
|
{
|
|
public class PlayerPreinputSubmodule : SubmoduleBase<PlayerInputSubcontroller>
|
|
{
|
|
public bool isReceivingPreinput;
|
|
public int currentPreinputPriority;
|
|
public Action preinputAction;
|
|
|
|
public PlayerPreinputSubmodule(PlayerInputSubcontroller owner) : base(owner)
|
|
{
|
|
Reset();
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
isReceivingPreinput = false;
|
|
currentPreinputPriority = int.MinValue;
|
|
preinputAction = null;
|
|
}
|
|
|
|
public void Update(bool isReceiving, bool canExecute)
|
|
{
|
|
isReceivingPreinput = isReceiving;
|
|
|
|
if (canExecute)
|
|
{
|
|
Debug.Log($"Executing preinput action with priority {currentPreinputPriority}");
|
|
preinputAction?.Invoke();
|
|
Reset();
|
|
}
|
|
}
|
|
|
|
public void RegisterPreinputAction(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.");
|
|
preinputAction = action;
|
|
currentPreinputPriority = priority;
|
|
}
|
|
}
|
|
}
|
|
} |