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();

View File

@@ -30,8 +30,7 @@ namespace Invector.vCharacterController
///Disable input usage if Unarmed
if (!IsActiveUnarmedAttack)
{
meleeCombatInput.weakAttackInput.useInput = meleeCombatInput.isArmed;
meleeCombatInput.strongAttackInput.useInput = meleeCombatInput.isArmed;
// Inputs are now handled via InputReader polling in vMeleeCombatInput
}
}
@@ -40,8 +39,6 @@ namespace Invector.vCharacterController
if (value != IsActiveUnarmedAttack)
{
IsActiveUnarmedAttack = value;
meleeCombatInput.weakAttackInput.useInput = value;
meleeCombatInput.strongAttackInput.useInput = value;
}
}
}

View File

@@ -12,12 +12,6 @@ namespace Invector.vCharacterController
{
#region Variables
[vEditorToolbar("Inputs")]
[Header("Melee Inputs")]
public GenericInput weakAttackInput = new GenericInput("Mouse0", "RB", "RB");
public GenericInput strongAttackInput = new GenericInput("Alpha1", false, "RT", true, "RT", false);
public GenericInput blockInput = new GenericInput("Mouse1", "LB", "LB");
internal vMeleeManager meleeManager;
protected virtual bool _isAttacking { get; set; }
public virtual bool isAttacking { get => _isAttacking || cc.IsAnimatorTag("Attack"); protected set { _isAttacking = value; } }
@@ -58,11 +52,6 @@ namespace Invector.vCharacterController
protected override void Start()
{
base.Start();
if (inputReader != null)
{
inputReader.OnAttackEvent += TriggerWeakAttack;
inputReader.OnStrongAttackEvent += TriggerStrongAttack;
}
}
protected override void LateUpdate()
@@ -87,9 +76,9 @@ namespace Invector.vCharacterController
if (MeleeAttackConditions() && !lockMeleeInput)
{
// MeleeWeakAttackInput();
// MeleeStrongAttackInput();
// BlockingInput();
MeleeWeakAttackInput();
MeleeStrongAttackInput();
BlockingInput();
}
else
{
@@ -105,12 +94,12 @@ namespace Invector.vCharacterController
/// </summary>
public virtual void MeleeWeakAttackInput()
{
if (animator == null)
if (animator == null || inputReader == null)
{
return;
}
if (weakAttackInput.GetButtonDown() && MeleeAttackStaminaConditions())
if (inputReader.ConsumeAttack() && MeleeAttackStaminaConditions())
{
TriggerWeakAttack();
}
@@ -127,12 +116,12 @@ namespace Invector.vCharacterController
/// </summary>
public virtual void MeleeStrongAttackInput()
{
if (animator == null)
if (animator == null || inputReader == null)
{
return;
}
if (strongAttackInput.GetButtonDown() && (!meleeManager.CurrentActiveAttackWeapon || meleeManager.CurrentActiveAttackWeapon.useStrongAttack) && MeleeAttackStaminaConditions())
if (inputReader.ConsumeStrongAttack() && (!meleeManager.CurrentActiveAttackWeapon || meleeManager.CurrentActiveAttackWeapon.useStrongAttack) && MeleeAttackStaminaConditions())
{
TriggerStrongAttack();
}

View File

@@ -24,18 +24,6 @@ namespace Invector.vCharacterController
[vHelpBox("PC only - use it to toggle between run/walk", vHelpBoxAttribute.MessageType.Info)]
public KeyCode toggleWalk = KeyCode.CapsLock;
[Header("Movement Input")]
// public GenericInput horizontalInput = new GenericInput("Horizontal", "LeftAnalogHorizontal", "Horizontal");
// public GenericInput verticalInput = new GenericInput("Vertical", "LeftAnalogVertical", "Vertical");
// public GenericInput sprintInput = new GenericInput("LeftShift", "LeftStickClick", "LeftStickClick");
// public GenericInput crouchInput = new GenericInput("C", "Y", "Y");
// public GenericInput strafeInput = new GenericInput("Tab", "RightStickClick", "RightStickClick");
// public GenericInput jumpInput = new GenericInput("Space", "X", "X");
// public GenericInput rollInput = new GenericInput("Q", "B", "B");
[Header("New Input System")]
public InputReader inputReader;
@@ -45,12 +33,6 @@ namespace Invector.vCharacterController
[vEditorToolbar("Camera Settings")]
public bool lockCameraInput;
public bool invertCameraInputVertical, invertCameraInputHorizontal;
// [vEditorToolbar("Inputs")]
[Header("Camera Input")]
// public GenericInput rotateCameraXInput = new GenericInput("Mouse X", "RightAnalogHorizontal", "Mouse X");
// public GenericInput rotateCameraYInput = new GenericInput("Mouse Y", "RightAnalogVertical", "Mouse Y");
// public GenericInput cameraZoomInput = new GenericInput("Mouse ScrollWheel", "", "");
[vEditorToolbar("Events")]
public UnityEvent OnLockCamera;
public UnityEvent OnUnlockCamera;
@@ -144,33 +126,6 @@ namespace Invector.vCharacterController
ShowCursor(showCursorOnStart);
LockCursor(unlockCursorOnStart);
EnableOnAnimatorMove();
if (inputReader != null)
{
// Nhảy (Jump)
inputReader.OnJumpEvent += () =>
{
if (JumpConditions()) cc.Jump(true);
};
// Lộn vòng (Roll / Dodge)
inputReader.OnDodgeEvent += () =>
{
if (RollConditions()) cc.Roll();
};
// Ngồi (Crouch)
inputReader.OnCrouchEvent += () =>
{
cc.AutoCrouch();
cc.Crouch();
};
// Đổi góc nhìn hoặc Khóa mục tiêu (Strafe) - Tuỳ bạn map nút nào vào OnToggleViewEvent
inputReader.OnToggleViewEvent += () =>
{
cc.Strafe();
};
}
}
protected virtual IEnumerator CharacterInit()
@@ -530,18 +485,14 @@ namespace Invector.vCharacterController
public virtual void StrafeInput()
{
// if (strafeInput.GetButtonDown())
// {
// cc.Strafe();
// }
if (inputReader != null && inputReader.ConsumeToggleView())
{
cc.Strafe();
}
}
public virtual void SprintInput()
{
// if (sprintInput.useInput)
// {
// cc.Sprint(cc.useContinuousSprint ? sprintInput.GetButtonDown() : sprintInput.GetButton());
// }
if (inputReader == null) return;
cc.Sprint(inputReader.IsSprintHeld);
}
@@ -550,10 +501,10 @@ namespace Invector.vCharacterController
{
cc.AutoCrouch();
// if (crouchInput.useInput && crouchInput.GetButtonDown())
// {
// cc.Crouch();
// }
if (inputReader != null && inputReader.ConsumeCrouch())
{
cc.Crouch();
}
}
/// <summary>
@@ -570,10 +521,10 @@ namespace Invector.vCharacterController
/// </summary>
public virtual void JumpInput()
{
// if (jumpInput.GetButtonDown() && JumpConditions())
// {
// cc.Jump(true);
// }
if (inputReader != null && inputReader.ConsumeJump() && JumpConditions())
{
cc.Jump(true);
}
}
/// <summary>
@@ -590,10 +541,10 @@ namespace Invector.vCharacterController
/// </summary>
public virtual void RollInput()
{
// if (rollInput.GetButtonDown() && RollConditions())
// {
// cc.Roll();
// }
if (inputReader != null && inputReader.ConsumeDodge() && RollConditions())
{
cc.Roll();
}
}
#endregion