123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- using System;
- using System.Diagnostics;
- using UnityEngine;
- public static class OVRTouchpad
- {
- [DebuggerBrowsable(DebuggerBrowsableState.Never)]
- public static event EventHandler TouchHandler;
- public static void Create()
- {
- }
- public static void Update()
- {
- if (Input.GetMouseButtonDown(0))
- {
- OVRTouchpad.moveAmountMouse = Input.mousePosition;
- OVRTouchpad.touchState = OVRTouchpad.TouchState.Down;
- }
- else if (Input.GetMouseButtonUp(0))
- {
- OVRTouchpad.moveAmountMouse -= Input.mousePosition;
- OVRTouchpad.HandleInputMouse(ref OVRTouchpad.moveAmountMouse);
- OVRTouchpad.touchState = OVRTouchpad.TouchState.Init;
- }
- }
- public static void OnDisable()
- {
- }
- private static void HandleInput(OVRTouchpad.TouchState state, ref Vector2 move)
- {
- if (move.magnitude >= OVRTouchpad.minMovMagnitude && OVRTouchpad.touchState != OVRTouchpad.TouchState.Stationary)
- {
- if (OVRTouchpad.touchState == OVRTouchpad.TouchState.Move)
- {
- move.Normalize();
- if (Mathf.Abs(move.x) > Mathf.Abs(move.y))
- {
- if (move.x > 0f)
- {
- }
- }
- else if (move.y > 0f)
- {
- }
- }
- }
- }
- private static void HandleInputMouse(ref Vector3 move)
- {
- if (move.magnitude < OVRTouchpad.minMovMagnitudeMouse)
- {
- if (OVRTouchpad.TouchHandler != null)
- {
- OVRTouchpad.TouchHandler(null, new OVRTouchpad.TouchArgs
- {
- TouchType = OVRTouchpad.TouchEvent.SingleTap
- });
- }
- }
- else
- {
- move.Normalize();
- if (Mathf.Abs(move.x) > Mathf.Abs(move.y))
- {
- if (move.x > 0f)
- {
- if (OVRTouchpad.TouchHandler != null)
- {
- OVRTouchpad.TouchHandler(null, new OVRTouchpad.TouchArgs
- {
- TouchType = OVRTouchpad.TouchEvent.Left
- });
- }
- }
- else if (OVRTouchpad.TouchHandler != null)
- {
- OVRTouchpad.TouchHandler(null, new OVRTouchpad.TouchArgs
- {
- TouchType = OVRTouchpad.TouchEvent.Right
- });
- }
- }
- else if (move.y > 0f)
- {
- if (OVRTouchpad.TouchHandler != null)
- {
- OVRTouchpad.TouchHandler(null, new OVRTouchpad.TouchArgs
- {
- TouchType = OVRTouchpad.TouchEvent.Down
- });
- }
- }
- else if (OVRTouchpad.TouchHandler != null)
- {
- OVRTouchpad.TouchHandler(null, new OVRTouchpad.TouchArgs
- {
- TouchType = OVRTouchpad.TouchEvent.Up
- });
- }
- }
- }
- private static OVRTouchpad.TouchState touchState = OVRTouchpad.TouchState.Init;
- private static Vector2 moveAmount;
- private static float minMovMagnitude = 100f;
- private static Vector3 moveAmountMouse;
- private static float minMovMagnitudeMouse = 25f;
- private static OVRTouchpadHelper touchpadHelper = new GameObject("OVRTouchpadHelper").AddComponent<OVRTouchpadHelper>();
- public enum TouchEvent
- {
- SingleTap,
- Left,
- Right,
- Up,
- Down
- }
- public class TouchArgs : EventArgs
- {
- public OVRTouchpad.TouchEvent TouchType;
- }
- private enum TouchState
- {
- Init,
- Down,
- Stationary,
- Move,
- Up
- }
- }
|