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

@@ -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;
}
}
}
}