using InfinityCode.uPano; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.InputSystem.EnhancedTouch; using Touch = UnityEngine.InputSystem.EnhancedTouch.Touch; namespace InfinityCode.uPanoSupport { public class NewInputSystemAdapter : MonoBehaviour { public InputAction axisAction; private float OnGetAxis(string axisName) { if (axisName == "Horizontal") return axisAction.ReadValue().x; if (axisName == "Vertical") return axisAction.ReadValue().y; if (axisName == "Mouse ScrollWheel") return Mouse.current.scroll.ReadValue().y / 120; return 0; } private bool OnGetKey(KeyCode keyCode) { int iKey = (int)keyCode; if (keyCode == KeyCode.KeypadPlus) iKey = (int)Key.NumpadPlus; else if (keyCode == KeyCode.Plus) iKey = (int)Key.Equals; else if (keyCode == KeyCode.KeypadMinus) iKey = (int)Key.NumpadMinus; else if (keyCode == KeyCode.Minus) iKey = (int)Key.Minus; return Keyboard.current[(Key)iKey].isPressed; } private bool OnGetMouseButton(int button) { if (button == 0) return Mouse.current.leftButton.isPressed; if (button == 1) return Mouse.current.rightButton.isPressed; if (button == 2) return Mouse.current.middleButton.isPressed; return false; } private bool OnGetMouseButtonUp(int button) { if (button == 0) return Mouse.current.leftButton.wasReleasedThisFrame; if (button == 1) return Mouse.current.rightButton.wasReleasedThisFrame; if (button == 2) return Mouse.current.middleButton.wasReleasedThisFrame; return false; } private bool OnGetMouseButtonDown(int button) { if (button == 0) return Mouse.current.leftButton.wasPressedThisFrame; if (button == 1) return Mouse.current.rightButton.wasPressedThisFrame; if (button == 2) return Mouse.current.middleButton.wasPressedThisFrame; return false; } private UnityEngine.Touch OnGetTouch(int index) { Touch newTouch = Touch.activeTouches[index]; UnityEngine.Touch touch = new UnityEngine.Touch { position = newTouch.screenPosition }; return touch; } private Vector2 OnMousePosition() { return Mouse.current.position.ReadValue(); } private int OnTouchCount() { return Touch.activeTouches.Count; } private void Start() { InputManager.OnMousePosition += OnMousePosition; InputManager.OnGetAxis += OnGetAxis; InputManager.OnGetMouseButton += OnGetMouseButton; InputManager.OnGetMouseButtonDown += OnGetMouseButtonDown; InputManager.OnGetMouseButtonUp += OnGetMouseButtonUp; InputManager.OnGetKey += OnGetKey; InputManager.OnTouchCount += OnTouchCount; InputManager.OnGetTouch += OnGetTouch; axisAction.Enable(); EnhancedTouchSupport.Enable(); } } }