Revert "Update ClientInputSender.cs"

This reverts commit 734cafed1c.
main
Hazim Bin Ijaz 4 weeks ago
parent 734cafed1c
commit c1f157103e

@ -18,7 +18,7 @@ namespace Unity.BossRoom.Gameplay.UserInput
[RequireComponent(typeof(ServerCharacter))] [RequireComponent(typeof(ServerCharacter))]
public class ClientInputSender : NetworkBehaviour public class ClientInputSender : NetworkBehaviour
{ {
const float k_MouseInputRaycastDistance = 1000f; const float k_MouseInputRaycastDistance = 100f;
//The movement input rate is capped at 40ms (or 25 fps). This provides a nice balance between responsiveness and //The movement input rate is capped at 40ms (or 25 fps). This provides a nice balance between responsiveness and
//upstream network conservation. This matters when holding down your mouse button to move. //upstream network conservation. This matters when holding down your mouse button to move.
@ -121,7 +121,6 @@ namespace Unity.BossRoom.Gameplay.UserInput
public AbilitySystem m_AbilitySystem; public AbilitySystem m_AbilitySystem;
ServerCharacter m_TargetServerCharacter; ServerCharacter m_TargetServerCharacter;
private bool IsSwapModeActive = false;
void Awake() void Awake()
{ {
@ -478,22 +477,8 @@ namespace Unity.BossRoom.Gameplay.UserInput
void Update() void Update()
{ {
// Toggle Swap Mode with E key
if (Input.GetKeyDown(KeyCode.E))
{
if (!m_AbilitySystem.IsAbilityModeActive() && m_ServerCharacter.IsOnAPlatform) // Prevent swap mode if ability mode is active
{
ToggleSwapMode();
}
else
{
Debug.Log("Cannot activate swap mode while ability mode is active.");
}
}
// Toggle Ability Mode with Q key
if (Input.GetKeyDown(KeyCode.Q)) if (Input.GetKeyDown(KeyCode.Q))
{
if (!IsSwapModeActive) // Prevent ability mode if swap mode is active
{ {
if (m_ServerCharacter.IsCrow) // Ensure only the crow can activate the ability if (m_ServerCharacter.IsCrow) // Ensure only the crow can activate the ability
{ {
@ -504,54 +489,63 @@ namespace Unity.BossRoom.Gameplay.UserInput
Debug.Log("You must be the Crow to activate this ability."); Debug.Log("You must be the Crow to activate this ability.");
} }
} }
else
if (m_AbilitySystem.IsAbilityModeActive()) return;
if (Input.GetKeyDown(KeyCode.Alpha1) && CharacterClass.Skill1)
{ {
Debug.Log("Cannot activate ability mode while swap mode is active."); RequestAction(actionState1.actionID, SkillTriggerStyle.Keyboard);
} }
else if (Input.GetKeyUp(KeyCode.Alpha1) && CharacterClass.Skill1)
{
RequestAction(actionState1.actionID, SkillTriggerStyle.KeyboardRelease);
} }
if (m_AbilitySystem.IsAbilityModeActive()) return; if (Input.GetKeyDown(KeyCode.Alpha2) && CharacterClass.Skill2)
if (!IsSwapModeActive) // Prevent other inputs if swap mode is active
{ {
if (Input.GetMouseButtonDown(0)) RequestAction(actionState2.actionID, SkillTriggerStyle.Keyboard);
}
else if (Input.GetKeyUp(KeyCode.Alpha2) && CharacterClass.Skill2)
{ {
m_MoveRequest = true; RequestAction(actionState2.actionID, SkillTriggerStyle.KeyboardRelease);
} }
if (Input.GetKeyDown(KeyCode.Alpha3) && CharacterClass.Skill3)
{
RequestAction(actionState3.actionID, SkillTriggerStyle.Keyboard);
} }
if (!EventSystem.current.IsPointerOverGameObject() && m_CurrentSkillInput == null) else if (Input.GetKeyUp(KeyCode.Alpha3) && CharacterClass.Skill3)
{ {
if (Input.GetMouseButtonDown(1)) RequestAction(actionState3.actionID, SkillTriggerStyle.KeyboardRelease);
}
if (Input.GetKeyDown(KeyCode.Alpha5))
{ {
RequestAction(CharacterClass.Skill1.ActionID, SkillTriggerStyle.MouseClick); RequestAction(GameDataSource.Instance.Emote1ActionPrototype.ActionID, SkillTriggerStyle.Keyboard);
} }
if (IsSwapModeActive && Input.GetMouseButtonDown(0)) // Left-click to request swap if (Input.GetKeyDown(KeyCode.Alpha6))
{ {
HandleSwapRequest(); RequestAction(GameDataSource.Instance.Emote2ActionPrototype.ActionID, SkillTriggerStyle.Keyboard);
} }
if (Input.GetKeyDown(KeyCode.Alpha7))
{
RequestAction(GameDataSource.Instance.Emote3ActionPrototype.ActionID, SkillTriggerStyle.Keyboard);
} }
if (Input.GetKeyDown(KeyCode.Alpha8))
{
RequestAction(GameDataSource.Instance.Emote4ActionPrototype.ActionID, SkillTriggerStyle.Keyboard);
} }
/// <summary> if (!EventSystem.current.IsPointerOverGameObject() && m_CurrentSkillInput == null)
/// Toggles swap mode on or off.
/// </summary>
private void ToggleSwapMode()
{
IsSwapModeActive = !IsSwapModeActive;
if (IsSwapModeActive)
{ {
Debug.Log("Swap mode activated. Click on a player to request a swap."); //IsPointerOverGameObject() is a simple way to determine if the mouse is over a UI element. If it is, we don't perform mouse input logic,
} //to model the button "blocking" mouse clicks from falling through and interacting with the world.
else bool isCharacterClicked = false;
if (Input.GetMouseButtonDown(1))
{ {
Debug.Log("Swap mode deactivated."); RequestAction(CharacterClass.Skill1.ActionID, SkillTriggerStyle.MouseClick);
}
} }
/// <summary> if (Input.GetMouseButtonDown(0)) // Left-click to request swap
/// Handles the swap request when in swap mode.
/// </summary>
private void HandleSwapRequest()
{ {
var ray = m_MainCamera.ScreenPointToRay(Input.mousePosition); var ray = m_MainCamera.ScreenPointToRay(UnityEngine.Input.mousePosition);
int hits = Physics.RaycastNonAlloc(ray, k_CachedHit, k_MouseInputRaycastDistance); int hits = Physics.RaycastNonAlloc(ray, k_CachedHit, k_MouseInputRaycastDistance);
if (hits > 0) if (hits > 0)
{ {
@ -566,13 +560,20 @@ namespace Unity.BossRoom.Gameplay.UserInput
// Initiate the swap // Initiate the swap
targetCharacter.NotifySwapRequestRpc(m_ServerCharacter.NetworkObjectId); targetCharacter.NotifySwapRequestRpc(m_ServerCharacter.NetworkObjectId);
Debug.Log($"Swap request sent to {targetCharacter.name}."); Debug.Log($"Swap request sent to {targetCharacter.name}.");
IsSwapModeActive = false; // Automatically deactivate swap mode after a successful request isCharacterClicked = true;
return; break; // Exit the loop after initiating the swap
}
} }
} }
} }
} }
Debug.LogWarning("No valid target found for swapping.");
if(!isCharacterClicked && Input.GetMouseButtonDown(0))
{
m_MoveRequest = true; // Set move request for holding left-click
}
}
} }

Loading…
Cancel
Save