update
This commit is contained in:
@@ -2,14 +2,15 @@
|
||||
using Invector.vCharacterController;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using OnlyScove.Scripts;
|
||||
|
||||
[vClassHeader("Simple Trigger Input")]
|
||||
public class vSimpleTriggerWithInput : vSimpleTrigger
|
||||
{
|
||||
public InputType inputType = InputType.GetButtonDown;
|
||||
|
||||
[Tooltip("Input to make the action")]
|
||||
public GenericInput actionInput = new GenericInput("E", "A", "A");
|
||||
[HideInInspector]
|
||||
public InputReader inputReader;
|
||||
|
||||
public enum InputType
|
||||
{
|
||||
@@ -40,18 +41,28 @@ public class vSimpleTriggerWithInput : vSimpleTrigger
|
||||
return;
|
||||
}
|
||||
|
||||
if (inputReader == null)
|
||||
{
|
||||
inputReader = other.GetComponentInParent<InputReader>();
|
||||
if (inputReader == null) inputReader = other.GetComponent<InputReader>();
|
||||
}
|
||||
|
||||
if (inputReader == null) return;
|
||||
|
||||
// GetButtonDown
|
||||
if (inputType == InputType.GetButtonDown)
|
||||
{
|
||||
if (actionInput.GetButtonDown())
|
||||
if (inputReader.ConsumeInteract())
|
||||
{
|
||||
OnPressButton.Invoke();
|
||||
}
|
||||
}
|
||||
// GetDoubleButton
|
||||
// GetDoubleButton (Note: New Input System handles double tap via Interactions,
|
||||
// but here we can implement a simple version or just skip if not used often)
|
||||
else if (inputType == InputType.GetDoubleButton)
|
||||
{
|
||||
if (actionInput.GetDoubleButtonDown(doubleButtomTime))
|
||||
// For now, mapping to single press or custom logic if needed.
|
||||
if (inputReader.ConsumeInteract())
|
||||
{
|
||||
OnPressButton.Invoke();
|
||||
}
|
||||
@@ -61,25 +72,29 @@ public class vSimpleTriggerWithInput : vSimpleTrigger
|
||||
{
|
||||
if (_currentInputDelay <= 0)
|
||||
{
|
||||
var up = false;
|
||||
var t = 0f;
|
||||
var up = !inputReader.IsInteractHeld;
|
||||
var t = currentButtonTimer;
|
||||
|
||||
// call the OnPressButton event after the buttomTimer is finished
|
||||
if (actionInput.GetButtonTimer(ref t, ref up, buttonTimer))
|
||||
{
|
||||
_currentInputDelay = inputDelay;
|
||||
OnPressButton.Invoke();
|
||||
}
|
||||
|
||||
// update the button timer
|
||||
if (actionInput.inButtomTimer)
|
||||
if (inputReader.IsInteractHeld)
|
||||
{
|
||||
currentButtonTimer += Time.deltaTime;
|
||||
t = currentButtonTimer / buttonTimer;
|
||||
UpdateButtonTimer(t);
|
||||
|
||||
if (currentButtonTimer >= buttonTimer)
|
||||
{
|
||||
_currentInputDelay = inputDelay;
|
||||
currentButtonTimer = 0;
|
||||
OnPressButton.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
// reset the buttonTimer if you release the button before finishing
|
||||
if (up)
|
||||
if (up && currentButtonTimer > 0)
|
||||
{
|
||||
currentButtonTimer = 0;
|
||||
CancelButtonTimer();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user