update Input new in script

This commit is contained in:
2026-05-31 10:31:59 +07:00
parent b2dbcf60e5
commit d4db20b92b
5 changed files with 171 additions and 85 deletions

View File

@@ -6,27 +6,11 @@
<component name="ChangeListManager">
<list default="true" id="f9183c68-daf0-43b8-be4c-fad79983f91b" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/.idea.HALLUCINATE/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.HALLUCINATE/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Animation/Idle.fbx.meta" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Animation/Idle.fbx.meta" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Animation/PLayer.controller" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Animation/PLayer.controller" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Animation/Standard Walk.fbx.meta" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Animation/Standard Walk.fbx.meta" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Models/HumanM_Model.fbx.meta" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Models/HumanM_Model.fbx.meta" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scripts/EnvironmentScanner.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/EnvironmentScanner.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scripts/Network/BasicSpawner.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/Network/BasicSpawner.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scripts/Network/PlayerInputData.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/Network/PlayerInputData.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Invector-3rdPersonController/Basic Locomotion/Scripts/CharacterController/vThirdPersonInput.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Invector-3rdPersonController/Basic Locomotion/Scripts/CharacterController/vThirdPersonInput.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Invector-3rdPersonController/Melee Combat/Scripts/CharacterController/vMeleeCombatInput.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Invector-3rdPersonController/Melee Combat/Scripts/CharacterController/vMeleeCombatInput.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Invector-3rdPersonController/Shooter/Scripts/Shooter/vShooterMeleeInput.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Invector-3rdPersonController/Shooter/Scripts/Shooter/vShooterMeleeInput.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scripts/Player Controller/InputReader.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/Player Controller/InputReader.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerAnimationHandler.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerAnimationHandler.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerDashState.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerDashState.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerDodgeState.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerDodgeState.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerFallState.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerFallState.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerIdleState.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerIdleState.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerJumpState.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerJumpState.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerMoveState.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerMoveState.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerMovement.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerMovement.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerParkourState.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerParkourState.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerRunState.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerRunState.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerStateMachine.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerStateMachine.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerThrustState.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerThrustState.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/TEST CUA TUAN/DEMO MAP.unity" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/TEST CUA TUAN/DEMO MAP.unity" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ProjectSettings/Packages/com.unity.probuilder/Settings.json" beforeDir="false" afterPath="$PROJECT_DIR$/ProjectSettings/Packages/com.unity.probuilder/Settings.json" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -55,6 +39,9 @@
<urls />
</component>
<component name="MetaFilesCheckinStateConfiguration" checkMetaFiles="true" />
<component name="ProblemsViewState">
<option name="selectedTabId" value="CurrentFile" />
</component>
<component name="ProjectColorInfo">{
&quot;associatedIndex&quot;: 4
}</component>
@@ -79,7 +66,7 @@
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;preferences.pluginManager&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;editor.preferences.completion&quot;,
&quot;to.speed.mode.migration.done&quot;: &quot;true&quot;,
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
}
@@ -185,6 +172,10 @@
<workItem from="1779293096539" duration="3004000" />
<workItem from="1779962085481" duration="671000" />
<workItem from="1780000221080" duration="1566000" />
<workItem from="1780139911301" duration="1008000" />
<workItem from="1780140952531" duration="441000" />
<workItem from="1780141455151" duration="159000" />
<workItem from="1780141729457" duration="9450000" />
</task>
<servers />
</component>

View File

@@ -1,6 +1,7 @@
using System.Collections;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.InputSystem;
namespace Invector.vCharacterController
{
@@ -23,13 +24,19 @@ namespace Invector.vCharacterController
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");
// 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 OnlyScove.Scripts.InputReader inputReader;
protected bool _lockInput = false;
[HideInInspector] public virtual bool lockInput { get { return _lockInput; } set { _lockInput = value; } }
@@ -37,11 +44,11 @@ namespace Invector.vCharacterController
[vEditorToolbar("Camera Settings")]
public bool lockCameraInput;
public bool invertCameraInputVertical, invertCameraInputHorizontal;
[vEditorToolbar("Inputs")]
// [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", "", "");
// 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;
@@ -136,6 +143,33 @@ 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()
@@ -448,19 +482,26 @@ namespace Invector.vCharacterController
public virtual void MoveInput()
{
if (inputReader == null) return;
if (!lockMoveInput)
{
// gets input
var input = cc.input;
input.x = horizontalInput.GetAxisRaw();
input.z = verticalInput.GetAxisRaw();
// input.x = horizontalInput.GetAxisRaw();
// input.z = verticalInput.GetAxisRaw();
// Input.GetAxisRaw("Horizontal");
// Input.GetAxisRaw("Vertical");
input.x = inputReader.MoveInput.x;
input.z = inputReader.MoveInput.y;
cc.input = input;
}
if (Input.GetKeyDown(toggleWalk))
{
cc.alwaysWalkByDefault = !cc.alwaysWalkByDefault;
}
//if (Input.GetKeyDown(toggleWalk))
//{
//cc.alwaysWalkByDefault = !cc.alwaysWalkByDefault;
//}
Input.GetKeyDown(KeyCode.CapsLock);
cc.ControlKeepDirection();
}
@@ -488,28 +529,30 @@ namespace Invector.vCharacterController
public virtual void StrafeInput()
{
if (strafeInput.GetButtonDown())
{
cc.Strafe();
}
// if (strafeInput.GetButtonDown())
// {
// cc.Strafe();
// }
}
public virtual void SprintInput()
{
if (sprintInput.useInput)
{
cc.Sprint(cc.useContinuousSprint ? sprintInput.GetButtonDown() : sprintInput.GetButton());
}
// if (sprintInput.useInput)
// {
// cc.Sprint(cc.useContinuousSprint ? sprintInput.GetButtonDown() : sprintInput.GetButton());
// }
if (inputReader == null) return;
cc.Sprint(inputReader.IsSprintHeld);
}
public virtual void CrouchInput()
{
cc.AutoCrouch();
if (crouchInput.useInput && crouchInput.GetButtonDown())
{
cc.Crouch();
}
// if (crouchInput.useInput && crouchInput.GetButtonDown())
// {
// cc.Crouch();
// }
}
/// <summary>
@@ -526,10 +569,10 @@ namespace Invector.vCharacterController
/// </summary>
public virtual void JumpInput()
{
if (jumpInput.GetButtonDown() && JumpConditions())
{
cc.Jump(true);
}
// if (jumpInput.GetButtonDown() && JumpConditions())
// {
// cc.Jump(true);
// }
}
/// <summary>
@@ -546,10 +589,10 @@ namespace Invector.vCharacterController
/// </summary>
public virtual void RollInput()
{
if (rollInput.GetButtonDown() && RollConditions())
{
cc.Roll();
}
// if (rollInput.GetButtonDown() && RollConditions())
// {
// cc.Roll();
// }
}
#endregion
@@ -567,20 +610,19 @@ namespace Invector.vCharacterController
{
return;
}
if (!cameraMain || tpCamera == null || inputReader == null) return;
var Y = lockCameraInput ? 0f : rotateCameraYInput.GetAxis();
var X = lockCameraInput ? 0f : rotateCameraXInput.GetAxis();
if (invertCameraInputHorizontal)
{
X *= -1;
}
if (invertCameraInputVertical)
{
Y *= -1;
}
var zoom = cameraZoomInput.GetAxis();
// var Y = lockCameraInput ? 0f : rotateCameraYInput.GetAxis();
// var X = lockCameraInput ? 0f : rotateCameraXInput.GetAxis();
var Y = lockCameraInput ? 0f : inputReader.LookInput.y;
var X = lockCameraInput ? 0f : inputReader.LookInput.x;
if (invertCameraInputHorizontal) X *= -1;
if (invertCameraInputVertical) Y *= -1;
// var zoom = cameraZoomInput.GetAxis();
var zoom = inputReader.ScrollInput.y;
tpCamera.RotateCamera(X, Y);
if (!lockCameraInput)

View File

@@ -58,6 +58,11 @@ namespace Invector.vCharacterController
protected override void Start()
{
base.Start();
if (inputReader != null)
{
inputReader.OnAttackEvent += TriggerWeakAttack;
inputReader.OnStrongAttackEvent += TriggerStrongAttack;
}
}
protected override void LateUpdate()
@@ -82,9 +87,9 @@ namespace Invector.vCharacterController
if (MeleeAttackConditions() && !lockMeleeInput)
{
MeleeWeakAttackInput();
MeleeStrongAttackInput();
BlockingInput();
// MeleeWeakAttackInput();
// MeleeStrongAttackInput();
// BlockingInput();
}
else
{
@@ -149,7 +154,8 @@ namespace Invector.vCharacterController
return;
}
isBlocking = blockInput.GetButton() && cc.currentStamina > 0 && !cc.customAction && !isAttacking;
// isBlocking = blockInput.GetButton() && cc.currentStamina > 0 && !cc.customAction && !isAttacking;
isBlocking = inputReader.IsBlockHeld && cc.currentStamina > 0 && !cc.customAction && !isAttacking;
}
/// <summary>
@@ -157,11 +163,13 @@ namespace Invector.vCharacterController
/// </summary>
public override void SprintInput()
{
if (sprintInput.useInput)
{
bool canSprint = cc.useContinuousSprint ? sprintInput.GetButtonDown() : sprintInput.GetButton();
cc.Sprint(canSprint && !isAttacking);
}
// if (sprintInput.useInput)
// {
// bool canSprint = cc.useContinuousSprint ? sprintInput.GetButtonDown() : sprintInput.GetButton();
// cc.Sprint(canSprint && !isAttacking);
//}
if(inputReader == null) return;
cc.Sprint(inputReader.IsSprintHeld && !isAttacking);
}
#endregion

View File

@@ -357,6 +357,14 @@ namespace Invector.vCharacterController
}
muzzlePosition = Vector3.forward * cc._capsuleCollider.radius * 2;
muzzleForward = Vector3.forward;
if (inputReader != null)
{
inputReader.OnReloadEvent += () =>
{
if (!isReloading) shooterManager.ReloadWeapon();
};
inputReader.OnSwitchSideEvent += SwitchCameraSide;
}
}
@@ -379,7 +387,7 @@ namespace Invector.vCharacterController
// We change the Melee Attack Input for the Shooter because 'Mouse1' is the same input to Shot a Fire Weapon
weakAttackInput = new GenericInput("Mouse2", "RB", "RB");
// By default it's disable because it uses the same input as the switchCameraSideInput
strafeInput.useInput = false;
// strafeInput.useInput = false;
}
/// <summary>
@@ -666,7 +674,11 @@ namespace Invector.vCharacterController
}
// reset the aimTimming if you sprint while still aiming through the hipfire
if (sprintInput.GetButtonDown() && _aimTiming > 0f)
// if (sprintInput.GetButtonDown() && _aimTiming > 0f)
// {
// _aimTiming = 0f;
// }
if(inputReader.IsSprintHeld && _aimTiming > 0f)
{
_aimTiming = 0f;
}
@@ -692,8 +704,7 @@ namespace Invector.vCharacterController
if (!cc.isRolling)
{
isAimingByInput = (!isReloading || shooterManager.keepAimingWhenReload) && (aimInput.GetButton() || (shooterManager.alwaysAiming && CurrentActiveWeapon)) && !cc.ragdolled && !cc.customAction
|| (cc.customAction && cc.isJumping);
isAimingByInput = (!isReloading || shooterManager.keepAimingWhenReload) && (inputReader.IsAimHeld || (shooterManager.alwaysAiming && CurrentActiveWeapon)) && !cc.ragdolled && !cc.customAction;
}
if (aimInput.GetButtonUp() && !shotInput.GetButton())
@@ -774,7 +785,8 @@ namespace Invector.vCharacterController
{
if (CurrentActiveWeapon || (shooterManager.CurrentWeapon && shooterManager.hipfireShot))
{
HandleShotCount(shooterManager.CurrentWeapon, shotInput.GetButton());
// HandleShotCount(shooterManager.CurrentWeapon, shotInput.GetButton());
HandleShotCount(shooterManager.CurrentWeapon, inputReader.IsAttackHeld);
}
}
else if (!IsAiming)

View File

@@ -60,6 +60,10 @@ namespace OnlyScove.Scripts
public virtual Vector2 ScrollInput { get; protected set; }
public virtual bool IsSprintHeld { get; protected set; }
public virtual bool IsAttackHeld { get; protected set; }
public bool IsAimHeld { get; protected set; }
public bool IsBlockHeld { get; protected set; }
public void ApplyNetworkInput(Vector2 move, bool isSprint)
{
@@ -77,6 +81,10 @@ namespace OnlyScove.Scripts
public event Action OnNextInteractEvent;
public event Action OnPreviousInteractEvent;
public event Action OnToggleViewEvent;
public event Action OnReloadEvent;
public event Action OnStrongAttackEvent;
public event Action OnSwitchSideEvent;
// UI Events
public event Action OnToggleSettingsEvent; // Cho Ctrl+O
@@ -185,5 +193,30 @@ namespace OnlyScove.Scripts
OnCancelEvent?.Invoke();
}
}
public void OnAim(InputAction.CallbackContext context)
{
if (context.performed) IsAimHeld = true;
if (context.canceled) IsAimHeld = false;
}
public void OnBlock(InputAction.CallbackContext context)
{
if (context.performed) IsBlockHeld = true;
if (context.canceled) IsBlockHeld = false;
}
public void OnStrongAttack(InputAction.CallbackContext context)
{
if(context.performed) OnStrongAttackEvent?.Invoke();
}
public void OnReload(InputAction.CallbackContext context)
{
if (context.performed) OnReloadEvent?.Invoke();
}
public void OnSwitchSide(InputAction.CallbackContext context)
{
if (context.performed) OnSwitchSideEvent?.Invoke();
}
}
}