using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.InputSystem.LowLevel; namespace NightclubArcadia.Core { /// /// Which input device was most recently active, globally. /// /// InteractionPrompt — and anything else that shows a button glyph — reads Current /// to decide between "[F]", "(X)" and "(✕)". /// /// Requires the Input System package, with Active Input Handling set to /// "Input System Package (New)" or "Both". /// public static class InputDeviceTracker { public enum DeviceType { Keyboard, Xbox, PlayStation, Generic } public static DeviceType Current { get; private set; } = DeviceType.Keyboard; [RuntimeInitializeOnLoadMethod] static void Init() { InputSystem.onEvent += OnEvent; } static void OnEvent(InputEventPtr eventPtr, InputDevice device) { // Only actual state changes — button, stick, key — not every event. if (!eventPtr.IsA() && !eventPtr.IsA()) { return; } switch (device) { case Keyboard: case Mouse: Current = DeviceType.Keyboard; break; case Gamepad pad: var name = pad.displayName.ToLowerInvariant(); if (name.Contains("dualshock") || name.Contains("dualsense") || name.Contains("playstation")) { Current = DeviceType.PlayStation; } else if (name.Contains("xbox") || name.Contains("xinput")) { Current = DeviceType.Xbox; } else { Current = DeviceType.Generic; } break; } } } }