protected override void OnDisable() { base.OnDisable(); // clear lines m_HitCount = 0; if (m_EnableUIInteraction) { m_InputModule.UnregisterInteractable(this); } m_InputModule = null; }
protected override void OnDisable() { base.OnDisable(); // clear lines m_NoSamplePoints = -1; if (m_EnableUIInteraction) { m_InputModule.UnregisterInteractable(this); } m_InputModule = null; }
void FindOrCreateXRUIInputModule() { var eventSystem = UnityEngine.Object.FindObjectOfType <EventSystem>(); if (eventSystem == null) { eventSystem = new GameObject("Event System", typeof(EventSystem)).GetComponent <EventSystem>(); } m_InputModule = eventSystem.GetComponent <XRUIInputModule>(); if (m_InputModule == null) { m_InputModule = eventSystem.gameObject.AddComponent <XRUIInputModule>(); } }
static void CreateXRUICanvas() { var vrCamera = Object.FindObjectOfType <Camera>(); // Ensure there is at least one EventSystem setup properly XRUIInputModule inputModule = Object.FindObjectOfType <XRUIInputModule>(); if (inputModule == null) { EventSystem eventSystem = Object.FindObjectOfType <EventSystem>(); GameObject eventSystemGo; if (eventSystem == null) { eventSystemGo = new GameObject("EventSystem", typeof(EventSystem), typeof(XRUIInputModule)); } else { eventSystemGo = eventSystem.gameObject; } //Remove the Standalone Input Module if already implemented, since it will block the XRUIInputModule StandaloneInputModule standaloneInputModule = eventSystemGo.GetComponent <StandaloneInputModule>(); if (standaloneInputModule != null) { Object.Destroy(standaloneInputModule); } inputModule = eventSystemGo.AddComponent <XRUIInputModule>(); } inputModule.uiCamera = vrCamera; GameObject canvasGo = new GameObject("Canvas", typeof(Canvas), typeof(CanvasScaler), typeof(GraphicRaycaster), typeof(TrackedDeviceGraphicRaycaster)); Canvas canvas = canvasGo.GetComponent <Canvas>(); canvas.renderMode = RenderMode.WorldSpace; canvas.worldCamera = vrCamera; }
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); }
void Awake() { m_InputSystemUIInputModule = GetComponent <InputSystemUIInputModule>(); m_XRUIInputModule = GetComponent <XRUIInputModule>(); m_VREnableSelector = UISelectorFactory.createSelector <bool>(VRContext.current, nameof(IVREnableDataProvider.VREnable), OnVREnableChanged); }
void Awake() { UIStateManager.stateChanged += OnStateDataChanged; m_InputSystemUIInputModule = GetComponent <InputSystemUIInputModule>(); m_XruiInputModule = GetComponent <XRUIInputModule>(); }