Example #1
0
        static void CreateXRUIPointer()
        {
            GameObject selectedGo = Selection.activeGameObject;

            if (selectedGo == null)
            {
                selectedGo = new GameObject("Controller", typeof(XRController), typeof(XRUIPointer));
            }

            XRController controller = selectedGo.GetComponent <XRController>();

            if (controller == null)
            {
                GameObject controllerGo = new GameObject("Controller", typeof(XRController), typeof(XRUIPointer));
                controller = selectedGo.GetComponent <XRController>();
                Undo.SetTransformParent(controllerGo.transform, selectedGo.transform, "Parent Controller to Selected GameObject");
                selectedGo = controllerGo;
            }

            XRUIPointer pointer = selectedGo.GetComponent <XRUIPointer>();

            if (pointer == null)
            {
                selectedGo.AddComponent <XRUIPointer>();
            }

            Selection.activeGameObject = selectedGo;
        }
Example #2
0
 void Awake()
 {
     m_Interactor = GetComponent <XRBaseInteractor>();
     if (m_Interactor)
     {
         m_Interactor.onSelectEnter.AddListener(OnSelectEnter);
         m_Interactor.onSelectExit.AddListener(OnSelectExit);
     }
     SetupReticlePrefab();
     m_XRUIPointer = GetComponent <XRUIPointer>();
     reticleActive = false;
 }
Example #3
0
        internal static TestObjects SetupUIScene()
        {
            TestObjects testObjects = new TestObjects();

            // Set up camera and canvas on which we can perform raycasts.
            GameObject cameraGo = new GameObject("Camera");
            Camera     camera   = cameraGo.AddComponent <Camera>();

            camera.stereoTargetEye = StereoTargetEyeMask.None;
            camera.pixelRect       = new Rect(0, 0, 640, 480);

            GameObject eventSystemGo = new GameObject("EventSystem", typeof(TestEventSystem), typeof(XRUIInputModule));

            testObjects.eventSystem = eventSystemGo.GetComponent <TestEventSystem>();
            testObjects.eventSystem.UpdateModules();
            testObjects.eventSystem.InvokeUpdate(); // Initial update only sets current module.
            XRUIInputModule inputModule = eventSystemGo.GetComponent <XRUIInputModule>();

            inputModule.uiCamera = camera;

            GameObject pointerGo = new GameObject("XR UI Pointer", typeof(XRUIPointer), typeof(XRController), typeof(XRControllerRecorder));

            testObjects.controllerRecorder            = pointerGo.GetComponent <XRControllerRecorder>();
            testObjects.controllerRecorder.controller = pointerGo.GetComponent <XRController>();
            testObjects.controllerRecorder.recording  = ScriptableObject.CreateInstance <XRControllerRecording>();
            XRUIPointer pointer = pointerGo.GetComponent <XRUIPointer>();

            pointer.controller = pointerGo.GetComponent <XRController>();

            GameObject canvasGo = new GameObject("Canvas", typeof(Canvas), typeof(CanvasScaler), typeof(GraphicRaycaster), typeof(TrackedDeviceGraphicRaycaster));
            Canvas     canvas   = canvasGo.GetComponent <Canvas>();

            canvas.renderMode  = RenderMode.ScreenSpaceCamera;
            canvas.worldCamera = camera;

            // Set up a GameObject hierarchy that we send events to. In a real setup,
            // this would be a hierarchy involving UI components.
            var parentGameObject = new GameObject("Parent");
            var parentTransform  = parentGameObject.AddComponent <RectTransform>();

            parentGameObject.AddComponent <UICallbackReceiver>();

            var leftChildGameObject = new GameObject("Left Child");
            var leftChildTransform  = leftChildGameObject.AddComponent <RectTransform>();

            leftChildGameObject.AddComponent <Image>();
            testObjects.leftUIReceiver = leftChildGameObject.AddComponent <UICallbackReceiver>();

            var rightChildGameObject = new GameObject("Right Child");
            var rightChildTransform  = rightChildGameObject.AddComponent <RectTransform>();

            rightChildGameObject.AddComponent <Image>();
            testObjects.rightUIReceiver = rightChildGameObject.AddComponent <UICallbackReceiver>();;

            parentTransform.SetParent(canvas.transform, worldPositionStays: false);
            leftChildTransform.SetParent(parentTransform, worldPositionStays: false);
            rightChildTransform.SetParent(parentTransform, worldPositionStays: false);

            // Parent occupies full space of canvas.
            parentTransform.sizeDelta = new Vector2(640, 480);

            // Left child occupies left half of parent.
            leftChildTransform.anchoredPosition = new Vector2(-(640 / 4), 0);
            leftChildTransform.sizeDelta        = new Vector2(320, 480);

            // Right child occupies right half of parent.
            rightChildTransform.anchoredPosition = new Vector2(640 / 4, 0);
            rightChildTransform.sizeDelta        = new Vector2(320, 480);

            return(testObjects);
        }