Oculus Connect 4 will feature more than 30 sessions across four tracks: Develop, Design, Distribute, and Future.

We kick things off with a keynote address on October 11!
New To The Forum? Click Here To Read The How To Guide. -- Developers Click Here.

Oculus Touch and UI how to guide for Unity.

spyderbytespyderbyte Posts: 3
Virtual Boy (or Girl)
edited August 24 in Unity
Hey, guys! So I'm having a little trouble understanding and setting up the Oculus touch UI in my own game. I'm not new to Unity and I've downloaded and studied the Oculus Sample Frmwrk, yet I can't seem to understand the steps on how to implement the pointer scene sample in my own game to be able to click on the UI. I've tried a few things and managed to get the reticle working but not able to click on any world buttons. A walkthrough or explanation for the touch UI would be EXTREMELY appreciated. Thanks in advance! :-)

Comments

  • spyderbytespyderbyte Posts: 3
    Virtual Boy (or Girl)
    Figured it out. I followed this link but I will still explain what I did. https://developer.oculus.com/blog/unitys-ui-system-in-vr/. I'm sure many did this but it doesn't explain how to use it for touch. Its just a simple fix.

    SUMMARY
    This tutorial is basically the same as the above link I provided, All I did was change the ray transform variable in the Event system and GazePointer to righthandAnchor but here are the steps anyway. Also make sure to set the Canvas event camera to CenterEyeAnchor. Hope it works and helps you. Feel free to make any corrections and/or mistakes. I'm no means a VR expert but this is what I did to get it up and working.


    INSTALL OVR
    1. Go to asset store and download the Oculus integration and the Oculus sample framework. You can alternatively download it from the Oculus dev site. 

    POINTER SCENE
    2. Navigate to Assets/SampleScenes/UI/ and click on the Pointer Scene and open it up. Here you can basically see get the jist if you follow along with the like I gave up above, but I'll still walk you through.

    SAVE PREFABS FROM SCENE
    3. I couldn't find a OVR camera rig prefab with touch controllers so I saved it as a prefab. (you can test it in another scene and you have touch controller movement.).
    4. Also, find the GazePointerRing in the hierarchy and save that as a prefab. Maybe it's there already as a prefab but I didn't see it in the given prefabs so I made my own prefab.

    NEW SCENE SETUP
    5. Create a new scene and drag the prefabs you just saved into the scene(OVRCameraRig and GazePointerRing)
    6.add a button to the scene
    7. Set Canvas render mode to world Space

    SCRIPTS and setup 
    8. add OvrPhysicsRaycaster script to the OVRCamera 
    -the event mask is there to interact with all layers or just UI elements. 
    9. In the Hierarchy, navigate to your OVRCameraRig/TrackingSpace/CenterEyeAnchor. Drag the CenterEyeAnchor Gameobject to the EventCamera slot located in the Canvas.I think this allows you to see where you are pointing.
    10. Add a script to the canvas called OVRRaycaster
    -I want my ray cast to interact with all objects so I set Blocking Objects to all and Blocking  Mask I left as "everything" and left the others as default. 
    11. in the OVRCAmeraRig find the RightHandAnchor game object and drag it to the following.
    -Find the GazePointerRing and drag the RightHandAnchor to the Ray Transform variable.
    -Find the EventSystem in the Hierarchy and drag the RightHandAnchor to the Ray transform in the OvrInputModule Script and if not set already set the JoypadClick button to "One". This is the "a" button on the Touch Controller and leaves all other variables alone.  
    IMPORTANT! DELETE A FEW THINGS 
    12. Make sure you Only have OVRCameraRig as your camera. Delete the default camera if you haven't already. You don't need it. 
    13. In the event,system, make sure you delete the StandaloneInputModule component. OVRInputModule script replaces this. 
    14. Remove the graphic raycaster component in Canvas. OVRRaycaster replaces this.
    15. I think that's it! Press play and It should work :D



  • idrezidrez Posts: 2
    Virtual Boy (or Girl)
    I'm having one issue. How do you set the GazePointer to righthandAnchor locator if the variable type is OVRCameraRig


  • idrezidrez Posts: 2
    Virtual Boy (or Girl)
    Wow, ok. So the scripts in https://developer.oculus.com/blog/unitys-ui-system-in-vr/ are not the same as the ones you can reference in "Oculus Sample Framework 1.15" on the unity store. The unity store version has the transform value time.

    Also, bit of cool script in there, you can switch it on the fly for better controller support:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.EventSystems;
    
    public class ControlSwitch : MonoBehaviour {
    
    	// Input module
    	private OVRInputModule inputModule;
    	public OVRCameraRig cameraRig;
    
    	// Use this for initialization
    	void Start () {
    		AssignCameraRig ();
    	}
    	
    	// Update is called once per frame
    	void Update () {
    		inputModule.rayTransform = OVRGazePointer.instance.rayTransform =
    			(OVRInput.GetActiveController() == OVRInput.Controller.Touch) ? cameraRig.rightHandAnchor :
    			(OVRInput.GetActiveController() == OVRInput.Controller.RTouch) ? cameraRig.rightHandAnchor :
    			(OVRInput.GetActiveController() == OVRInput.Controller.LTouch) ? cameraRig.leftHandAnchor :
    			cameraRig.centerEyeAnchor;
    	}
    	public void AssignCameraRig()
    	{
    		EventSystem eventSystem = GameObject.FindObjectOfType<EventSystem>();
    		inputModule = eventSystem.GetComponent<OVRInputModule>();
    	}
    }
    
    I just cranked that out for a prototype. Works great.

  • spyderbytespyderbyte Posts: 3
    Virtual Boy (or Girl)
    idrez said:
    I'm having one issue. How do you set the GazePointer to righthandAnchor locator if the variable type is OVRCameraRig


    Hey idrez. Cool script. Glad you got it. I think you may have an older version.  I'm using Unity 2017 and  Oculus sample framework v1.15. I just checked for an update and it seems I have the latest framework version. This is what I have:
Sign In or Register to comment.