Reorganize scripts into subfolders by responsibility
Move scripts under Assets/Scripts/ into Components, GameMode, Helper, Network, Enum, Struct and ScriptableObject folders. Pure file moves (plus folder .meta files); no code changes. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
382bfb36df
commit
e23fae0c50
126 files changed
+112
No files matched your search
@@ -0,0 +1,122 @@
|
||||
using UnityEngine;
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
using UnityEngine.InputSystem;
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Shared low-level input reads used by the camera rigs, the paint controller and the modes. Each
|
||||
/// method preserves its original per-backend behaviour (new Input System when present, legacy Input
|
||||
/// Manager otherwise). Sensitivity scaling stays at the call sites.
|
||||
/// </summary>
|
||||
public static class InputUtil
|
||||
{
|
||||
/// <summary>Raw mouse delta this frame (pixels); the legacy path scales GetAxisRaw by 10 to match.</summary>
|
||||
public static Vector2 ReadMouseDelta()
|
||||
{
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
return Mouse.current != null ? Mouse.current.delta.ReadValue() : Vector2.zero;
|
||||
#else
|
||||
return new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y")) * 10f;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>Raw mouse-wheel delta this frame (usually only its sign is used).</summary>
|
||||
public static float ReadScroll()
|
||||
{
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
if (Mouse.current != null) return Mouse.current.scroll.ReadValue().y;
|
||||
#endif
|
||||
#if ENABLE_LEGACY_INPUT_MANAGER
|
||||
return Input.GetAxis("Mouse ScrollWheel");
|
||||
#else
|
||||
return 0f;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>Locks+hides or frees+shows the hardware cursor.</summary>
|
||||
public static void SetCursorLocked(bool locked)
|
||||
{
|
||||
Cursor.lockState = locked ? CursorLockMode.Locked : CursorLockMode.None;
|
||||
Cursor.visible = !locked;
|
||||
}
|
||||
|
||||
public static bool ShiftHeld()
|
||||
{
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
var kb = Keyboard.current;
|
||||
if (kb != null) return kb.leftShiftKey.isPressed || kb.rightShiftKey.isPressed;
|
||||
#endif
|
||||
#if ENABLE_LEGACY_INPUT_MANAGER
|
||||
return Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
public static bool CtrlHeld()
|
||||
{
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
var kb = Keyboard.current;
|
||||
if (kb != null) return kb.leftCtrlKey.isPressed || kb.rightCtrlKey.isPressed;
|
||||
#endif
|
||||
#if ENABLE_LEGACY_INPUT_MANAGER
|
||||
return Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl);
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
public static bool LeftMouseHeld()
|
||||
{
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
return Mouse.current != null && Mouse.current.leftButton.isPressed;
|
||||
#else
|
||||
return Input.GetMouseButton(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static bool RightMouseHeld()
|
||||
{
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
return Mouse.current != null && Mouse.current.rightButton.isPressed;
|
||||
#else
|
||||
return Input.GetMouseButton(1);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static bool MiddleMouseHeld()
|
||||
{
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
return Mouse.current != null && Mouse.current.middleButton.isPressed;
|
||||
#else
|
||||
return Input.GetMouseButton(2);
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>Left mouse button pressed on this exact frame (edge, not held).</summary>
|
||||
public static bool LeftClickedThisFrame()
|
||||
{
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
return Mouse.current != null && Mouse.current.leftButton.wasPressedThisFrame;
|
||||
#else
|
||||
return Input.GetMouseButtonDown(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>Key pressed on this exact frame (edge), regardless of UI focus. The parameter type
|
||||
/// follows the active input backend, matching how the callers' serialized key fields are declared.</summary>
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
public static bool KeyPressedThisFrame(Key key)
|
||||
=> Keyboard.current != null && Keyboard.current[key].wasPressedThisFrame;
|
||||
#else
|
||||
public static bool KeyPressedThisFrame(KeyCode key) => Input.GetKeyDown(key);
|
||||
#endif
|
||||
|
||||
/// <summary>Gameplay key pressed on this exact frame (edge), suppressed while a UI text field is
|
||||
/// focused so typing never triggers gameplay bindings.</summary>
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
public static bool GameplayKeyPressed(Key key) => !TypingGuard.IsTyping && KeyPressedThisFrame(key);
|
||||
#else
|
||||
public static bool GameplayKeyPressed(KeyCode key) => !TypingGuard.IsTyping && KeyPressedThisFrame(key);
|
||||
#endif
|
||||
}
|
||||
Reference in new issue
Block a user