using System; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.InputSystem.HID; public static class InputController { private const string NameHID = nameof(HID); private static float _maxLeftX; private static float _minLeftX; private static float _maxLeftY; private static float _minLeftY; private static float _maxRightX; private static float _minRightX; private static float _maxRightY; private static float _minRightY; private static InputPreset _preset; private static InputDevice _useDevice; public static InputDevice UseDevice => _useDevice; public static float LeftY => Mathf.InverseLerp(_minLeftY, _maxLeftY, _preset.GetValueInput(_useDevice, TypeValueJoystick.LeftY)); public static float LeftX => GetNormalizedValue(_minLeftX, _maxLeftX, _preset.GetValueInput(_useDevice, TypeValueJoystick.LeftX)); public static float RightY => GetNormalizedValue(_minRightY, _maxRightY, _preset.GetValueInput(_useDevice, TypeValueJoystick.RightY)); public static float RightX => GetNormalizedValue(_minRightX, _maxRightX, _preset.GetValueInput(_useDevice, TypeValueJoystick.RightX)); public static bool IsDropping => _preset.GetValueInput(_useDevice, TypeValueJoystick.Dropping) == 9; public static float AngleCamera => Mathf.InverseLerp(4, 240, _preset.GetValueInput(_useDevice, TypeValueJoystick.AngleCamera)); public static void SetDevice(InputDevice device) { _useDevice = device; } public static void SetPreset(InputPreset preset) { _preset = preset; } public static float GetÑleanValue(TypeValueJoystick direction) { return _preset.GetValueInput(_useDevice, direction); } private static float GetNormalizedValue(float minValue, float maxValue, float currentValue) { return (currentValue - minValue) / (maxValue - minValue); } public static void SetRange(float value,bool isMax, TypeValueJoystick direction) { if (isMax) { switch (direction) { case TypeValueJoystick.LeftX: _maxLeftX = value; break; case TypeValueJoystick.RightX: _maxRightX = value; break; case TypeValueJoystick.LeftY: _maxLeftY = value; break; case TypeValueJoystick.RightY: _maxRightY = value; break; } } else { switch (direction) { case TypeValueJoystick.LeftX: _minLeftX = value; break; case TypeValueJoystick.RightX: _minRightX = value; break; case TypeValueJoystick.LeftY: _minLeftY = value; break; case TypeValueJoystick.RightY: _minRightY = value; break; } } } } public enum TypeValueJoystick { LeftX, LeftY, RightX, RightY, Dropping, AngleCamera }