public void Initialize() { var eventSystem = FindObjectOfType <EventSystem>(); if (eventSystem) { m_InputModule = eventSystem.GetComponent <MultipleRayInputModule>(); if (!m_InputModule) { m_NewInputModule = eventSystem.gameObject.AddComponent <MultipleRayInputModule>(); m_InputModule = m_NewInputModule; } } else { m_NewEventSystem = new GameObject("EventSystem"); m_InputModule = m_NewEventSystem.AddComponent <MultipleRayInputModule>(); } #if UNITY_EDITOR m_InputModule.StartRunInEditMode(); #endif var moduleLoaderCore = ModuleLoaderCore.instance; var activeIsland = m_FIModule.activeIsland; activeIsland.AddProviders(new List <IFunctionalityProvider> { m_InputModule }); moduleLoaderCore.InjectFunctionalityInModules(activeIsland); this.InjectFunctionalitySingle(m_InputModule); this.ConnectInterfaces(m_InputModule); var customPreviewCamera = m_ViewerModule.customPreviewCamera; if (customPreviewCamera != null) { m_InputModule.layerMask |= customPreviewCamera.hmdOnlyLayerMask; } var rayModule = moduleLoaderCore.GetModule <EditorXRRayModule>(); if (rayModule != null) { m_InputModule.preProcessRaycastSource = rayModule.PreProcessRaycastSource; } m_EventCamera = EditorXRUtils.Instantiate(m_EventCameraPrefab.gameObject, m_ModuleParent).GetComponent <Camera>(); m_EventCamera.enabled = false; m_InputModule.eventCamera = m_EventCamera; }
private void CreateEventSystem() { // Create event system, input module, and event camera U.Object.AddComponent <EventSystem>(gameObject); m_InputModule = U.Object.AddComponent <MultipleRayInputModule>(gameObject); m_InputModule.getPointerLength = GetPointerLength; m_EventCamera = U.Object.Instantiate(m_EventCameraPrefab.gameObject, transform).GetComponent <Camera>(); m_EventCamera.enabled = false; m_InputModule.eventCamera = m_EventCamera; foreach (var proxy in m_AllProxies) { foreach (var rayOriginBase in proxy.rayOrigins) { foreach (var device in InputSystem.devices) // Find device tagged with the node that matches this RayOrigin node { var node = GetDeviceNode(device); if (node.HasValue && node.Value == rayOriginBase.Key) { DeviceData deviceData; if (m_DeviceData.TryGetValue(device, out deviceData)) { // Create ui action map input for device. if (deviceData.uiInput == null) { deviceData.uiInput = CreateActionMapInput(m_InputModule.actionMap, device); } // Add RayOrigin transform, proxy and ActionMapInput references to input module list of sources m_InputModule.AddRaycastSource(proxy, rayOriginBase.Key, deviceData.uiInput); } break; } } } } UpdatePlayerHandleMaps(); }