Files
2026-03-04 09:37:33 +08:00

202 lines
5.3 KiB
C#

using UnityEngine;
namespace DebuggingEssentials
{
public static class EventInput
{
public static bool isGamePauseKeyDown;
public static bool isFocusCameraKey;
public static bool isAlignWithViewKey;
public static bool isMoveToViewKey;
public static bool isMouseButtonDown0;
public static bool isMouseButtonDown1;
public static bool isMouseButtonDown2;
public static bool isMouseButtonUp0;
public static bool isKeyW;
public static bool isKeyS;
public static bool isKeyA;
public static bool isKeyD;
public static bool isKeyQ;
public static bool isKeyE;
public static bool isKeyDownD;
public static bool isKeyDownDelete;
public static bool isKeyDownFollowCamera;
public static bool isKeyUpD = true;
public static bool isKeyUpDelete = true;
public static bool isKeyUpFollowCamera = true;
public static bool isGamePauseKeyUp = true;
public static bool isShiftKey;
public static bool isControlKey;
public static bool isAltKey;
public static float mouseScrollDelta;
public static Vector2 mousePos;
public static Vector2 mousePosInvY;
private static int oldFrame;
public static void ResetInput()
{
if (Time.frameCount != oldFrame)
{
isKeyDownD = false;
isKeyDownDelete = false;
isKeyDownFollowCamera = false;
isGamePauseKeyDown = false;
}
oldFrame = Time.frameCount;
}
public static void GetInput()
{
Event current = Event.current;
KeyCode keyCode = current.keyCode;
EventType type = current.type;
mousePos = (mousePosInvY = current.mousePosition);
mousePosInvY.y = (float)Screen.height - mousePos.y;
isShiftKey = current.shift;
isControlKey = current.control;
isAltKey = current.alt;
int button = current.button;
if (type == EventType.ScrollWheel)
{
mouseScrollDelta = current.delta.y;
}
else
{
mouseScrollDelta = 0f;
}
GetKeyDown(ref isFocusCameraKey, RuntimeInspector.instance.focusCameraKey, keyCode, type);
GetKeyDown(ref isAlignWithViewKey, RuntimeInspector.instance.alignWithViewKey, keyCode, type);
GetKeyDown(ref isMoveToViewKey, RuntimeInspector.instance.moveToViewKey, keyCode, type);
GetKeyDown(ref isKeyW, KeyCode.W, keyCode, type);
GetKeyDown(ref isKeyS, KeyCode.S, keyCode, type);
GetKeyDown(ref isKeyA, KeyCode.A, keyCode, type);
GetKeyDown(ref isKeyD, KeyCode.D, keyCode, type);
GetKeyDown(ref isKeyQ, KeyCode.Q, keyCode, type);
GetKeyDown(ref isKeyE, KeyCode.E, keyCode, type);
if (isKeyUpD)
{
GetKeyDown(ref isKeyDownD, KeyCode.D, keyCode, type);
}
if (isKeyUpDelete)
{
GetKeyDown(ref isKeyDownDelete, KeyCode.Delete, keyCode, type);
}
if (isKeyUpFollowCamera)
{
GetKeyDown(ref isKeyDownFollowCamera, RuntimeInspector.instance.followCameraKey, keyCode, type);
}
if (isGamePauseKeyUp)
{
GetKeyDown(ref isGamePauseKeyDown, RuntimeInspector.instance.gamePauseKey, keyCode, type);
}
GetKeyUp(ref isGamePauseKeyUp, RuntimeInspector.instance.gamePauseKey, keyCode, type);
GetKeyUp(ref isKeyUpD, KeyCode.D, keyCode, type);
GetKeyUp(ref isKeyUpDelete, KeyCode.Delete, keyCode, type);
GetKeyUp(ref isKeyUpFollowCamera, RuntimeInspector.instance.followCameraKey, keyCode, type);
GetMouseButtonDown(ref isMouseButtonDown0, 0, button, type);
GetMouseButtonDown(ref isMouseButtonDown1, 1, button, type);
GetMouseButtonDown(ref isMouseButtonDown2, 2, button, type);
GetMouseButtonUp(ref isMouseButtonUp0, 0, button, type);
}
private static void GetKeyDown(ref bool isKey, KeyCode keyCode, KeyCode eventKeyCode, EventType eventType)
{
if (eventType == EventType.KeyDown && eventKeyCode == keyCode)
{
isKey = true;
}
if (eventType == EventType.KeyUp && eventKeyCode == keyCode)
{
isKey = false;
}
}
private static void GetKeyDown(ref bool isKey, AdvancedKey advancedKey, KeyCode eventKeyCode, EventType eventType)
{
if (eventType == EventType.KeyDown && eventKeyCode == advancedKey.keyCode && advancedKey.GetSpecialKeys())
{
isKey = true;
}
if (eventType == EventType.KeyUp && eventKeyCode == advancedKey.keyCode)
{
isKey = false;
}
}
private static void GetKeyUp(ref bool isKey, KeyCode keyCode, KeyCode eventKeyCode, EventType eventType)
{
if (eventType == EventType.KeyDown && eventKeyCode == keyCode)
{
isKey = false;
}
if (eventType == EventType.KeyUp && eventKeyCode == keyCode)
{
isKey = true;
}
}
private static void GetKeyUp(ref bool isKey, AdvancedKey advancedKey, KeyCode eventKeyCode, EventType eventType)
{
if (eventType == EventType.KeyDown && eventKeyCode == advancedKey.keyCode && advancedKey.GetSpecialKeys())
{
isKey = false;
}
if (eventType == EventType.KeyUp && eventKeyCode == advancedKey.keyCode)
{
isKey = true;
}
}
private static void GetMouseButtonDown(ref bool isButton, int button, int eventButton, EventType eventType)
{
if (eventType == EventType.MouseDown && eventButton == button)
{
isButton = true;
}
if (eventType == EventType.MouseUp && eventButton == button)
{
isButton = false;
}
}
private static void GetMouseButtonUp(ref bool isButton, int button, int eventButton, EventType eventType)
{
if (eventType == EventType.MouseDown && eventButton == button)
{
isButton = false;
}
if (eventType == EventType.MouseUp && eventButton == button)
{
isButton = true;
}
}
}
}