update
This commit is contained in:
@@ -61,9 +61,10 @@ namespace OnlyScove.Scripts
|
||||
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 bool IsInteractHeld { get; protected set; }
|
||||
public bool IsScopeViewHeld { get; protected set; }
|
||||
|
||||
public void ApplyNetworkInput(Vector2 move, bool isSprint)
|
||||
{
|
||||
@@ -85,15 +86,46 @@ namespace OnlyScove.Scripts
|
||||
public event Action OnReloadEvent;
|
||||
public event Action OnStrongAttackEvent;
|
||||
public event Action OnSwitchSideEvent;
|
||||
public event Action OnScopeViewEvent;
|
||||
|
||||
// UI Events
|
||||
public event Action OnToggleSettingsEvent; // Cho Ctrl+O
|
||||
public event Action OnCancelEvent; // Cho phím ESC hoặc phím đóng UI
|
||||
|
||||
// Polling flags
|
||||
private bool wasAttackPressed;
|
||||
private bool wasStrongAttackPressed;
|
||||
private bool wasReloadPressed;
|
||||
private bool wasSwitchSidePressed;
|
||||
private bool wasScopeViewPressed;
|
||||
private bool wasInteractPressed;
|
||||
private bool wasDodgePressed;
|
||||
private bool wasCrouchPressed;
|
||||
private bool wasJumpPressed;
|
||||
private bool wasAimReleased;
|
||||
private bool wasNextPressed;
|
||||
private bool wasPreviousPressed;
|
||||
private bool wasToggleViewPressed;
|
||||
|
||||
public bool ConsumeAttack() { bool v = wasAttackPressed; wasAttackPressed = false; return v; }
|
||||
public bool ConsumeStrongAttack() { bool v = wasStrongAttackPressed; wasStrongAttackPressed = false; return v; }
|
||||
public bool ConsumeReload() { bool v = wasReloadPressed; wasReloadPressed = false; return v; }
|
||||
public bool ConsumeSwitchSide() { bool v = wasSwitchSidePressed; wasSwitchSidePressed = false; return v; }
|
||||
public bool ConsumeScopeView() { bool v = wasScopeViewPressed; wasScopeViewPressed = false; return v; }
|
||||
public bool ConsumeInteract() { bool v = wasInteractPressed; wasInteractPressed = false; return v; }
|
||||
public bool ConsumeDodge() { bool v = wasDodgePressed; wasDodgePressed = false; return v; }
|
||||
public bool ConsumeCrouch() { bool v = wasCrouchPressed; wasCrouchPressed = false; return v; }
|
||||
public bool ConsumeJump() { bool v = wasJumpPressed; wasJumpPressed = false; return v; }
|
||||
public bool ConsumeAimReleased() { bool v = wasAimReleased; wasAimReleased = false; return v; }
|
||||
public bool ConsumeNext() { bool v = wasNextPressed; wasNextPressed = false; return v; }
|
||||
public bool ConsumePrevious() { bool v = wasPreviousPressed; wasPreviousPressed = false; return v; }
|
||||
public bool ConsumeToggleView() { bool v = wasToggleViewPressed; wasToggleViewPressed = false; return v; }
|
||||
|
||||
public void OnAttack(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context.performed)
|
||||
{
|
||||
wasAttackPressed = true;
|
||||
OnAttackEvent?.Invoke();
|
||||
IsAttackHeld = true;
|
||||
}
|
||||
@@ -130,7 +162,11 @@ namespace OnlyScove.Scripts
|
||||
|
||||
public void OnToggleView(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context.performed) OnToggleViewEvent?.Invoke();
|
||||
if (context.performed)
|
||||
{
|
||||
wasToggleViewPressed = true;
|
||||
OnToggleViewEvent?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnJump(InputAction.CallbackContext context)
|
||||
@@ -142,7 +178,6 @@ namespace OnlyScove.Scripts
|
||||
}
|
||||
}
|
||||
|
||||
private bool wasJumpPressed;
|
||||
public bool ConsumeJumpInput()
|
||||
{
|
||||
bool val = wasJumpPressed;
|
||||
@@ -152,27 +187,52 @@ namespace OnlyScove.Scripts
|
||||
|
||||
public void OnDodgeOrThrust(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context.performed) OnDodgeEvent?.Invoke();
|
||||
if (context.performed)
|
||||
{
|
||||
wasDodgePressed = true;
|
||||
OnDodgeEvent?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnCrouch(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context.performed) OnCrouchEvent?.Invoke();
|
||||
if (context.performed)
|
||||
{
|
||||
wasCrouchPressed = true;
|
||||
OnCrouchEvent?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnInteract(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context.performed) OnInteractEvent?.Invoke();
|
||||
if (context.performed)
|
||||
{
|
||||
wasInteractPressed = true;
|
||||
IsInteractHeld = true;
|
||||
OnInteractEvent?.Invoke();
|
||||
}
|
||||
if (context.canceled)
|
||||
{
|
||||
IsInteractHeld = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnNext(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context.performed) OnNextInteractEvent?.Invoke();
|
||||
if (context.performed)
|
||||
{
|
||||
wasNextPressed = true;
|
||||
OnNextInteractEvent?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPrevious(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context.performed) OnPreviousInteractEvent?.Invoke();
|
||||
if (context.performed)
|
||||
{
|
||||
wasPreviousPressed = true;
|
||||
OnPreviousInteractEvent?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
// UI Callbacks
|
||||
@@ -196,7 +256,11 @@ namespace OnlyScove.Scripts
|
||||
public void OnAim(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context.performed) IsAimHeld = true;
|
||||
if (context.canceled) IsAimHeld = false;
|
||||
if (context.canceled)
|
||||
{
|
||||
IsAimHeld = false;
|
||||
wasAimReleased = true;
|
||||
}
|
||||
}
|
||||
public void OnBlock(InputAction.CallbackContext context)
|
||||
{
|
||||
@@ -206,17 +270,43 @@ namespace OnlyScove.Scripts
|
||||
|
||||
public void OnStrongAttack(InputAction.CallbackContext context)
|
||||
{
|
||||
if(context.performed) OnStrongAttackEvent?.Invoke();
|
||||
if (context.performed)
|
||||
{
|
||||
wasStrongAttackPressed = true;
|
||||
OnStrongAttackEvent?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnReload(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context.performed) OnReloadEvent?.Invoke();
|
||||
if (context.performed)
|
||||
{
|
||||
wasReloadPressed = true;
|
||||
OnReloadEvent?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnSwitchSide(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context.performed) OnSwitchSideEvent?.Invoke();
|
||||
if (context.performed)
|
||||
{
|
||||
wasSwitchSidePressed = true;
|
||||
OnSwitchSideEvent?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnScopeView(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context.performed)
|
||||
{
|
||||
wasScopeViewPressed = true;
|
||||
IsScopeViewHeld = true;
|
||||
OnScopeViewEvent?.Invoke();
|
||||
}
|
||||
if (context.canceled)
|
||||
{
|
||||
IsScopeViewHeld = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Invector
|
||||
{
|
||||
@@ -16,7 +16,6 @@ namespace Invector
|
||||
public bool lockInventoryInputOnLock;
|
||||
[vReadOnly]
|
||||
public bool isLocked;
|
||||
public GenericInput hideAndDrawWeaponsInput = new GenericInput("H", "LB", "LB");
|
||||
|
||||
[vEditorToolbar("Melee")]
|
||||
[Header("Draw Immediate Conditions")]
|
||||
@@ -29,7 +28,6 @@ namespace Invector
|
||||
public bool weaponsHided;
|
||||
[vReadOnly(false)]
|
||||
public bool previouslyWeaponsHided;
|
||||
|
||||
protected float currentTimer;
|
||||
protected bool forceHide;
|
||||
|
||||
@@ -48,7 +46,7 @@ namespace Invector
|
||||
|
||||
protected virtual void ControlWeapons()
|
||||
{
|
||||
if (isLocked || melee.cc == null || melee.cc.customAction)
|
||||
if (isLocked || melee == null || melee.cc == null || melee.cc.customAction)
|
||||
return;
|
||||
|
||||
HandleInput();
|
||||
@@ -196,9 +194,10 @@ namespace Invector
|
||||
|
||||
protected virtual void HandleInput()
|
||||
{
|
||||
if (hideAndDrawWeaponsInput.GetButtonDown() && !IsEquipping)
|
||||
if (melee != null && melee.inputReader != null && melee.inputReader.ConsumeSwitchSide() && !IsEquipping)
|
||||
{
|
||||
|
||||
// Note: I'm using SwitchSide action as a placeholder or you can map a dedicated "Hide/Draw" action.
|
||||
// Assuming SwitchSide is suitable for now as it's Tab/Middle Click.
|
||||
if (CanHideRightWeapon() || CanHideLeftWeapon())
|
||||
{
|
||||
HideWeapons();
|
||||
@@ -221,11 +220,11 @@ namespace Invector
|
||||
|
||||
protected virtual bool DrawWeaponsImmediateConditions()
|
||||
{
|
||||
if (!melee || melee.cc.customAction || !melee.meleeManager || (melee.meleeManager.CurrentAttackWeapon == null && melee.meleeManager.CurrentDefenseWeapon == null))
|
||||
if (!melee || melee.inputReader == null || melee.cc.customAction || !melee.meleeManager || (melee.meleeManager.CurrentAttackWeapon == null && melee.meleeManager.CurrentDefenseWeapon == null))
|
||||
return false;
|
||||
else
|
||||
{
|
||||
return melee.weakAttackInput.GetButton() && meleeWeakAttack || melee.strongAttackInput.GetButton() && meleeStrongAttack || melee.blockInput.GetButton() && meleeBlock;
|
||||
return (melee.inputReader.IsAttackHeld && meleeWeakAttack) || (melee.inputReader.ConsumeStrongAttack() && meleeStrongAttack) || (melee.inputReader.IsBlockHeld && meleeBlock);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -353,5 +352,4 @@ namespace Invector
|
||||
StartCoroutine(holderManager.UnequipRoutine(equipment.referenceItem.disableDelayTime, immediate, onStart, onFinish));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using UnityEngine;
|
||||
using OnlyScove.Scripts;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Invector.vCharacterController
|
||||
{
|
||||
@@ -24,11 +25,10 @@ namespace Invector.vCharacterController
|
||||
public float cameraHeightOffset;
|
||||
[Tooltip("Transition Speed for the Camera")]
|
||||
public float lockSpeed = 0.5f;
|
||||
[Header("LockOn Inputs")]
|
||||
public GenericInput lockOnInput = new GenericInput("Tab", "RightStickClick", "RightStickClick");
|
||||
public GenericInput nexTargetInput = new GenericInput("X", false, false, "RightAnalogHorizontal", true, false, "X", false, false);
|
||||
public GenericInput previousTargetInput = new GenericInput("Z", false, false, "RightAnalogHorizontal", true, true, "Z", false, false);
|
||||
|
||||
|
||||
[vEditorToolbar("Debug")]
|
||||
public bool debugMode;
|
||||
|
||||
internal bool isLockingOn;
|
||||
public LockOnEvent onLockOnTarget;
|
||||
public LockOnEvent onUnLockOnTarget;
|
||||
@@ -38,6 +38,7 @@ namespace Invector.vCharacterController
|
||||
protected bool _inTarget;
|
||||
protected virtual bool inTarget { get { return _inTarget; } set { _inTarget = value; } }
|
||||
protected vThirdPersonInput tpInput;
|
||||
protected InputReader inputReader;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -49,6 +50,8 @@ namespace Invector.vCharacterController
|
||||
tpInput = GetComponent<vThirdPersonInput>();
|
||||
if (tpInput)
|
||||
{
|
||||
inputReader = tpInput.inputReader;
|
||||
|
||||
tpInput.onUpdate -= UpdateLockOn;
|
||||
tpInput.onUpdate += UpdateLockOn;
|
||||
|
||||
@@ -61,6 +64,8 @@ namespace Invector.vCharacterController
|
||||
UpdateLockOn();
|
||||
});
|
||||
}
|
||||
|
||||
if (inputReader == null) inputReader = GetComponentInParent<InputReader>();
|
||||
|
||||
if (!aimImageContainer)
|
||||
{
|
||||
@@ -89,31 +94,18 @@ namespace Invector.vCharacterController
|
||||
|
||||
protected virtual void UpdateLockOn()
|
||||
{
|
||||
if (this.tpInput == null) return;
|
||||
if (this.tpInput == null || inputReader == null) return;
|
||||
|
||||
LockOnInput();
|
||||
SwitchTargetsInput();
|
||||
CheckForTargetDistance();
|
||||
CheckForCharacterAlive();
|
||||
UpdateAimImage();
|
||||
}
|
||||
|
||||
protected virtual void LockOnInput()
|
||||
{
|
||||
if (tpInput.tpCamera == null || tpInput.cc == null) return;
|
||||
|
||||
// lock the camera into a target, if there is any around
|
||||
if (lockOnInput.GetButtonDown() && !tpInput.cc.customAction)
|
||||
{
|
||||
isLockingOn = !isLockingOn;
|
||||
LockOn(isLockingOn);
|
||||
}
|
||||
// unlock the camera if the target is null
|
||||
else if (isLockingOn && (tpInput.tpCamera.lockTarget == null) || LostTargetDistance())
|
||||
if (isLockingOn && (tpInput.tpCamera.lockTarget == null) || LostTargetDistance())
|
||||
{
|
||||
isLockingOn = false;
|
||||
LockOn(false);
|
||||
}
|
||||
// choose to use lock-on with strafe of free movement
|
||||
|
||||
// choose to use lock-on with strafe or free movement
|
||||
if (strafeWhileLockOn && !tpInput.cc.locomotionType.Equals(vThirdPersonMotor.LocomotionType.OnlyStrafe))
|
||||
{
|
||||
if (isLockingOn && tpInput.tpCamera.lockTarget != null)
|
||||
@@ -127,6 +119,26 @@ namespace Invector.vCharacterController
|
||||
tpInput.cc.isStrafing = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (isLockingOn && tpInput.tpCamera.lockTarget)
|
||||
{
|
||||
if (inputReader.ConsumeNext()) ChangeTarget(1);
|
||||
else if (inputReader.ConsumePrevious()) ChangeTarget(-1);
|
||||
}
|
||||
|
||||
CheckForTargetDistance();
|
||||
CheckForCharacterAlive();
|
||||
UpdateAimImage();
|
||||
}
|
||||
|
||||
protected virtual void LockOnInput()
|
||||
{
|
||||
// lock the camera into a target, if there is any around
|
||||
if (inputReader.ConsumeToggleView() && !tpInput.cc.customAction)
|
||||
{
|
||||
isLockingOn = !isLockingOn;
|
||||
LockOn(isLockingOn);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual bool LostTargetDistance()
|
||||
@@ -147,18 +159,6 @@ namespace Invector.vCharacterController
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void SwitchTargetsInput()
|
||||
{
|
||||
if (tpInput.tpCamera == null) return;
|
||||
|
||||
if (tpInput.tpCamera.lockTarget)
|
||||
{
|
||||
// switch between targets using Keyboard
|
||||
if (previousTargetInput.GetButtonDown()) PreviousTarget();
|
||||
else if (nexTargetInput.GetButtonDown()) NextTarget();
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void CheckForTargetDistance()
|
||||
{
|
||||
if (!isLockingOn || currentTarget == null) return;
|
||||
@@ -214,7 +214,7 @@ namespace Invector.vCharacterController
|
||||
aimImage.transform.gameObject.SetActive(false);
|
||||
}
|
||||
if (currentTarget && aimImage && aimImageContainer)
|
||||
aimImage.anchoredPosition = currentTarget.GetScreenPointOffBoundsCenter(aimImageContainer, tpCamera.targetCamera, spriteHeight);
|
||||
aimImage.anchoredPosition = currentTarget.GetScreenPointOffBoundsCenter(aimImageContainer, tpInput.tpCamera.targetCamera, spriteHeight);
|
||||
else if (aimImageContainer)
|
||||
aimImage.anchoredPosition = Vector2.zero;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Invector.vCharacterController;
|
||||
using Invector.vCharacterController;
|
||||
using OnlyScove.Scripts;
|
||||
|
||||
namespace Invector.vShooter
|
||||
{
|
||||
[vClassHeader("Shooter Lock-On")]
|
||||
@@ -30,9 +32,10 @@ namespace Invector.vShooter
|
||||
|
||||
protected override void LockOnInput()
|
||||
{
|
||||
if (tpInput.tpCamera == null || tpInput.cc == null) return;
|
||||
if (tpInput == null || tpInput.tpCamera == null || tpInput.cc == null || inputReader == null) return;
|
||||
|
||||
// lock the camera into a target, if there is any around
|
||||
if (lockOnInput.GetButtonDown() && !tpInput.cc.customAction)
|
||||
if (inputReader.ConsumeToggleView() && !tpInput.cc.customAction)
|
||||
{
|
||||
isLockingOn = !isLockingOn;
|
||||
LockOn(isLockingOn);
|
||||
@@ -43,10 +46,11 @@ namespace Invector.vShooter
|
||||
isLockingOn = false;
|
||||
LockOn(false);
|
||||
}
|
||||
|
||||
// choose to use lock-on with strafe of free movement
|
||||
if (strafeWhileLockOn && !tpInput.cc.locomotionType.Equals(vThirdPersonMotor.LocomotionType.OnlyStrafe))
|
||||
{
|
||||
if (shooterMelee.isAimingByInput || strafeWhileLockOn && isLockingOn && tpInput.tpCamera.lockTarget != null)
|
||||
if (shooterMelee.isAimingByInput || (strafeWhileLockOn && isLockingOn && tpInput.tpCamera.lockTarget != null))
|
||||
tpInput.cc.lockInStrafe = true;
|
||||
else
|
||||
tpInput.cc.lockInStrafe = false;
|
||||
|
||||
@@ -8,18 +8,6 @@ namespace Invector.vCharacterController
|
||||
[vClassHeader("SHOOTER/MELEE INPUT", iconName = "inputIcon")]
|
||||
public class vShooterMeleeInput : vMeleeCombatInput, vIShooterIKController, PlayerController.vILockCamera
|
||||
{
|
||||
#region Shooter Inputs
|
||||
|
||||
[vEditorToolbar("Inputs")]
|
||||
[Header("Shooter Inputs")]
|
||||
public GenericInput aimInput = new GenericInput("Mouse1", false, "LT", true, "LT", false);
|
||||
public GenericInput shotInput = new GenericInput("Mouse0", false, "RT", true, "RT", false);
|
||||
public GenericInput reloadInput = new GenericInput("R", "LB", "LB");
|
||||
public GenericInput switchCameraSideInput = new GenericInput("Tab", "RightStickClick", "RightStickClick");
|
||||
public GenericInput scopeViewInput = new GenericInput("Z", "RB", "RB");
|
||||
|
||||
#endregion
|
||||
|
||||
#region Shooter Variables
|
||||
|
||||
[HideInInspector] public vShooterManager shooterManager;
|
||||
@@ -293,7 +281,7 @@ namespace Invector.vCharacterController
|
||||
_aimTiming = 0;
|
||||
return false;
|
||||
}
|
||||
return shooterManager.hipfireShot && (_aimTiming > 0 || (shotInput.GetButton() && shooterManager.CurrentWeapon != null) || (!isAimingByInput && shootCountA > 0));
|
||||
return shooterManager.hipfireShot && (_aimTiming > 0 || (inputReader != null && inputReader.IsAttackHeld && shooterManager.CurrentWeapon != null) || (!isAimingByInput && shootCountA > 0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -357,15 +345,6 @@ 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected override void LateUpdate()
|
||||
@@ -384,10 +363,6 @@ namespace Invector.vCharacterController
|
||||
|
||||
protected virtual void Reset()
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -707,7 +682,7 @@ namespace Invector.vCharacterController
|
||||
isAimingByInput = (!isReloading || shooterManager.keepAimingWhenReload) && (inputReader.IsAimHeld || (shooterManager.alwaysAiming && CurrentActiveWeapon)) && !cc.ragdolled && !cc.customAction;
|
||||
}
|
||||
|
||||
if (aimInput.GetButtonUp() && !shotInput.GetButton())
|
||||
if (inputReader.ConsumeAimReleased() && !inputReader.IsAttackHeld)
|
||||
{
|
||||
_aimTiming = 0f;
|
||||
}
|
||||
@@ -887,7 +862,7 @@ namespace Invector.vCharacterController
|
||||
return;
|
||||
}
|
||||
|
||||
if (reloadInput.GetButtonDown())
|
||||
if (inputReader.ConsumeReload())
|
||||
{
|
||||
shootCountA = 0;
|
||||
_aimTiming = 0f;
|
||||
@@ -903,7 +878,7 @@ namespace Invector.vCharacterController
|
||||
if (IsAiming) shooterManager.ReloadWeapon();
|
||||
break;
|
||||
case vShooterWeapon.AutoReloadStyle.WhenShot:
|
||||
if (shotInput.GetButtonDown()) shooterManager.ReloadWeapon();
|
||||
if (inputReader.ConsumeAttack()) shooterManager.ReloadWeapon();
|
||||
break;
|
||||
case vShooterWeapon.AutoReloadStyle.WhenAmmoAvailable:
|
||||
shooterManager.ReloadWeapon();
|
||||
@@ -919,12 +894,12 @@ namespace Invector.vCharacterController
|
||||
/// </summary>
|
||||
public virtual void SwitchCameraSideInput()
|
||||
{
|
||||
if (tpCamera == null)
|
||||
if (tpCamera == null || inputReader == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (switchCameraSideInput.GetButtonDown())
|
||||
if (inputReader.ConsumeSwitchSide())
|
||||
{
|
||||
SwitchCameraSide();
|
||||
}
|
||||
@@ -968,7 +943,7 @@ namespace Invector.vCharacterController
|
||||
return;
|
||||
}
|
||||
|
||||
if (isAimingByInput && aimConditions && (scopeViewInput.GetButtonDown() || CurrentActiveWeapon.onlyUseScopeUIView))
|
||||
if (isAimingByInput && aimConditions && (inputReader.ConsumeScopeView() || CurrentActiveWeapon.onlyUseScopeUIView))
|
||||
{
|
||||
if (controlAimCanvas && CurrentActiveWeapon.scopeTarget)
|
||||
{
|
||||
|
||||
@@ -70,13 +70,13 @@ namespace Invector.vShooter
|
||||
|
||||
protected virtual bool DrawShooterWeaponImmediateConditions()
|
||||
{
|
||||
if (!shooter || !shooter.shooterManager || shooter.cc.customAction || !shooter.shooterManager.CurrentWeapon || shooter.lockInput)
|
||||
if (!shooter || shooter.inputReader == null || !shooter.shooterManager || shooter.cc.customAction || !shooter.shooterManager.CurrentWeapon || shooter.lockInput)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (shooter.CurrentActiveWeapon == null && ((shooter.aimInput.GetButtonDown() && aim) ||
|
||||
(shooter.shooterManager.hipfireShot && shooter.shotInput.GetButtonDown() && hipFire) || (shooter.shotInput.GetButtonDown() && shoot)))
|
||||
if (shooter.CurrentActiveWeapon == null && ((shooter.inputReader.IsAimHeld && aim) ||
|
||||
(shooter.shooterManager.hipfireShot && shooter.inputReader.ConsumeAttack() && hipFire) || (shooter.inputReader.ConsumeAttack() && shoot)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user