update Input new in script
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user