This commit is contained in:
2026-06-04 12:42:00 +07:00
parent 5526341041
commit f70082a350
14 changed files with 697 additions and 447 deletions

View File

@@ -1,5 +1,6 @@
using System.Collections;
using System.Collections.Generic;
using OnlyScove.Scripts;
using UnityEngine;
using UnityEngine.Events;
namespace Invector.vCharacterController.vActions
@@ -18,27 +19,17 @@ namespace Invector.vCharacterController.vActions
public float fastClimbSpeed = 3f;
[Tooltip("How much Stamina will be consumed when climbing faster")]
public float fastClimbStamina = 30f;
[Tooltip("Input to use the ladder going up or down")]
public GenericInput verticalInput = new GenericInput("Vertical", "LeftAnalogVertical", "Vertical");
[Tooltip("Input to enter the ladder")]
public GenericInput enterInput = new GenericInput("E", "A", "A");
[Tooltip("Input to exit the ladder")]
public GenericInput exitInput = new GenericInput("Space", "B", "B");
[Tooltip("Input to climb faster")]
public GenericInput fastClimbInput = new GenericInput("LeftShift", "LeftStickClick", "LeftStickClick");
[Tooltip("Input to climb faster")]
public GenericInput slideDownInput = new GenericInput("Q", "X", "X");
[vEditorToolbar("Events")]
public UnityEvent OnEnterLadder;
public UnityEvent OnExitLadder;
public UnityEvent OnEnterTriggerLadder;
public UnityEvent OnExitTriggerLadder;
[vEditorToolbar("Debug")]
public bool debugMode;
protected vThirdPersonInput tpInput;
protected InputReader inputReader;
[vReadOnly(false)]
[SerializeField]
protected vTriggerLadderAction targetLadderAction;
@@ -77,7 +68,6 @@ namespace Invector.vCharacterController.vActions
#endregion
protected vThirdPersonInput tpInput;
protected bool isAligningMidAir;
protected override void SetUpListener()
@@ -93,12 +83,15 @@ namespace Invector.vCharacterController.vActions
tpInput = GetComponent<vThirdPersonInput>();
if (tpInput)
{
inputReader = tpInput.inputReader;
tpInput.onUpdate -= UpdateLadderBehavior;
tpInput.onUpdate += UpdateLadderBehavior;
tpInput.onAnimatorMove -= UsingLadder;
tpInput.onAnimatorMove += UsingLadder;
}
if (inputReader == null) inputReader = GetComponentInParent<InputReader>();
}
protected virtual void UpdateLadderBehavior()
@@ -110,12 +103,12 @@ namespace Invector.vCharacterController.vActions
protected virtual void EnterLadderInput()
{
if (targetLadderAction == null || tpInput.cc.customAction || tpInput.cc.isJumping || !tpInput.cc.isGrounded || tpInput.cc.isRolling)
if (targetLadderAction == null || tpInput.cc.customAction || tpInput.cc.isJumping || !tpInput.cc.isGrounded || tpInput.cc.isRolling || inputReader == null)
{
return;
}
if (enterInput.GetButtonDown() && !enterLadderStarted && !isUsingLadder && !targetLadderAction.autoAction)
if (inputReader.ConsumeInteract() && !enterLadderStarted && !isUsingLadder && !targetLadderAction.autoAction)
{
TriggerEnterLadder();
}
@@ -123,7 +116,7 @@ namespace Invector.vCharacterController.vActions
protected virtual void ExitLadderInput()
{
if (!isUsingLadder)
if (!isUsingLadder || inputReader == null)
{
return;
}
@@ -137,17 +130,17 @@ namespace Invector.vCharacterController.vActions
{
if (tpInput.cc.IsAnimatorTag("ClimbLadder"))
{
if (slideDownInput.GetButtonDown() && !inExitingLadderAnimation)
if (inputReader.ConsumeDodge() && !inExitingLadderAnimation)
{
tpInput.cc.animator.CrossFadeInFixedTime("Ladder_SlideDown", 0.2f);
}
// exit ladder at any moment by pressing the cancelInput
if (exitInput.GetButtonDown())
if (inputReader.ConsumeJump())
{
if (debugMode)
{
Debug.Log("Quick Exit..." + currentLadderAction.name + "_" + currentLadderAction.transform.parent.gameObject.name);
Debug.Log("Quick Exit...");
}
tpInput.cc.animator.speed = 1;
tpInput.cc.animator.CrossFadeInFixedTime("QuickExitLadder", 0.1f);
@@ -162,7 +155,7 @@ namespace Invector.vCharacterController.vActions
if (animationClip == "ExitLadderBottom")
{
// exit ladder when reach the bottom by pressing the cancelInput or pressing down at
if (exitInput.GetButtonDown() && !triggerExitOnce || (speed <= -0.05f && !triggerExitOnce) || (tpInput.cc.IsAnimatorTag("LadderSlideDown") && targetLadderAction != null && !triggerExitOnce))
if (inputReader.ConsumeJump() && !triggerExitOnce || (speed <= -0.05f && !triggerExitOnce) || (tpInput.cc.IsAnimatorTag("LadderSlideDown") && targetLadderAction != null && !triggerExitOnce))
{
if (debugMode)
{
@@ -337,7 +330,7 @@ namespace Invector.vCharacterController.vActions
protected virtual void UsingLadder()
{
if (!isUsingLadder)
if (!isUsingLadder || inputReader == null)
{
return;
}
@@ -349,7 +342,7 @@ namespace Invector.vCharacterController.vActions
tpInput.CameraInput();
// go up or down
speed = verticalInput.GetAxis();
speed = inputReader.MoveInput.y;
tpInput.cc.animator.SetFloat(vAnimatorParameters.InputVertical, speed, 0.1f, Time.deltaTime);
if (speed >= 0.05f || speed <= -0.05f)
{
@@ -361,7 +354,7 @@ namespace Invector.vCharacterController.vActions
}
// increase speed by input and consume stamina
if (fastClimbInput.GetButton() && tpInput.cc.currentStamina > 0)
if (inputReader.IsSprintHeld && tpInput.cc.currentStamina > 0)
{
currentClimbSpeed = fastClimbSpeed;
StaminaConsumption();