Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to use "OVRTouchpad.cs" interface to a Touchpad?

Discussion in 'AR/VR (XR) Discussion' started by SanSolo, Nov 2, 2015.

  1. SanSolo

    SanSolo

    Joined:
    Feb 25, 2014
    Posts:
    85
    I downloaded the latest unity integration package (0.0.13). I want to implement OVR touchpad inputs for movement. There's a file "OVRTouchpad.cs " in the package which defines some properties for Touch input.
    However, this class is Static and non monobehavior. So I cannot attach it to a GameObject or create an instance of it.
    So how do I use this file to handle Touch Input?
     
  2. SanSolo

    SanSolo

    Joined:
    Feb 25, 2014
    Posts:
    85
    I have to use it from some other Monoscript as follows:
    Code (csharp):
    1.  
    2. public class SomeOtherClass : MonoBehaviour {
    3.     void Start()
    4.        {
    5.            
    6. OVRTouchpad.Create ();
    7.         OVRTouchpad.TouchHandler += HandleTouchHandler;
    8.        }
    9.  
    10. }
    HandleTouchHandler is the event listener for touch input.
     
  3. 67688FEA

    67688FEA

    Joined:
    Nov 11, 2015
    Posts:
    4
    We have the same problem as you asked as the above, have you solved this problem? Maybe you can help us please.: )
     
  4. SanSolo

    SanSolo

    Joined:
    Feb 25, 2014
    Posts:
    85
    @67688FEA yes I have solved the issue. What I did was, created a script to add the OVRTOuchpad.cs into the scene. This creates a TouchPadHelper object in the scene. Sensing the touch input is handled by this helper class. My script receives the touch info provided by this helper. Based on that info, I overloaded the OVRPLayerController's UpDateMovement method to handle the touch based movement.

    Here's the TouchPadMovement script :

    Code (csharp):
    1.  
    2. public class TouchpadMovement : MonoBehaviour {
    3.     public Transform forwardDirection;
    4.     OVRPlayerController oVPC;
    5.     // Use this for initialization
    6.     void Start () {
    7.         oVPC=GetComponent<OVRPlayerController>();
    8.         OVRTouchpad.Create ();
    9.         OVRTouchpad.TouchHandler += HandleTouchHandler;
    10.     }
    11.  
    12.     void HandleTouchHandler (object sender, System.EventArgs e)
    13.     {
    14.         OVRTouchpad.TouchArgs touchArgs = (OVRTouchpad.TouchArgs)e;
    15.         OVRTouchpad.TouchEvent touchEvent = touchArgs.TouchType;
    16.         /*if(touchArgs.TouchType == OVRTouchpad.TouchEvent.SingleTap)
    17.         {
    18.             //TODO: Insert code here to handle a single tap.  Note that there are other TouchTypes you can check for like directional swipes, but double tap is not currently implemented I believe.
    19.         }*/
    20.  
    21.         switch (touchEvent) {
    22.         case OVRTouchpad.TouchEvent.SingleTap :
    23.             //Do something for Single Tap
    24.             break;
    25.  
    26.         case OVRTouchpad.TouchEvent.Left :
    27.             oVPC.UpdateMovement(Vector3.left);
    28.             break;
    29.  
    30.         case OVRTouchpad.TouchEvent.Right :
    31.             oVPC.UpdateMovement(Vector3.right);
    32.             break;
    33.  
    34.         case OVRTouchpad.TouchEvent.Up :
    35.             oVPC.UpdateMovement(Vector3.forward);
    36.             break;
    37.  
    38.         case OVRTouchpad.TouchEvent.Down :
    39.             //oVPC.UpdateMovement(Vector3.back);
    40.             break;
    41.         }
    42.     }
    43.  
     
  5. 67688FEA

    67688FEA

    Joined:
    Nov 11, 2015
    Posts:
    4
    Thanks!
     
  6. sdwww

    sdwww

    Joined:
    Mar 19, 2017
    Posts:
    1
    thx,I have the same problem!