void CheckDirectSelection(DeviceData deviceData, Dictionary <IMenu, MenuHideData> menuHideData, bool alternateMenuVisible) { if (m_DirectSelectionModule == null) { return; } var viewerScale = this.GetViewerScale(); var rayOrigin = deviceData.rayOrigin; var rayOriginPosition = rayOrigin.position; var heldObjects = m_DirectSelectionModule.GetHeldObjects(rayOrigin); // If this hand is holding any objects, hide its menus var hasDirectSelection = heldObjects != null && heldObjects.Count > 0; if (hasDirectSelection) { foreach (var kvp in menuHideData) { // Only set if hidden--value is reset every frame kvp.Value.hideFlags |= MenuHideFlags.HasDirectSelection; } foreach (var otherDeviceData in k_ActiveDeviceData) { if (otherDeviceData == deviceData) { continue; } var otherRayOrigin = otherDeviceData.rayOrigin; if (alternateMenuVisible) { SetAlternateMenuVisibility(otherRayOrigin, true); } // If other hand is within range to do a two-handed scale, hide its menu as well if (m_DirectSelectionModule.IsHovering(otherRayOrigin) || m_DirectSelectionModule.IsScaling(otherRayOrigin) || Vector3.Distance(otherRayOrigin.position, rayOriginPosition) < k_TwoHandHideDistance * viewerScale) { foreach (var kvp in otherDeviceData.menuHideData) { // Only set if hidden--value is reset every frame kvp.Value.hideFlags |= MenuHideFlags.HasDirectSelection; } break; } } } }
void OnProxyActiveChanged(IProxy proxy) { proxy.hidden = !proxy.active; if (proxy.active) { var deviceData = m_ToolModule.deviceData; if (!deviceData.Any(dd => dd.proxy == proxy)) { var moduleLoaderCore = ModuleLoaderCore.instance; var keyboardModule = moduleLoaderCore.GetModule <KeyboardModule>(); var highlightModule = moduleLoaderCore.GetModule <HighlightModule>(); foreach (var rayOriginPair in proxy.rayOrigins) { var node = rayOriginPair.Key; var rayOrigin = rayOriginPair.Value; var systemDevices = m_DeviceInputModule.GetSystemDevices(); for (int j = 0; j < systemDevices.Count; j++) { var device = systemDevices[j]; // Find device tagged with the node that matches this RayOrigin node var deviceNode = m_DeviceInputModule.GetDeviceNode(device); if (deviceNode == node) { var newDeviceData = new DeviceData(); deviceData.Add(newDeviceData); newDeviceData.proxy = proxy; newDeviceData.node = node; newDeviceData.rayOrigin = rayOrigin; newDeviceData.inputDevice = device; if (!this.HasProvider <IProvidesAddRaycastSource>()) { continue; } // Add RayOrigin transform, proxy and ActionMapInput references to input module list of sources this.AddRaycastSource(proxy, node, rayOrigin, source => { // Do not invalidate UI raycasts in the middle of a drag operation var eventData = source.eventData; if (!eventData.pointerDrag) { var sourceRayOrigin = source.rayOrigin; if (m_DirectSelectionModule != null && m_DirectSelectionModule.IsHovering(sourceRayOrigin)) { return(false); } var currentRaycast = eventData.pointerCurrentRaycast; var hoveredObject = currentRaycast.gameObject; // The manipulator needs rays to go through scene objects in order to work var isManipulator = hoveredObject && hoveredObject.GetComponentInParent <IManipulator>() != null; float sceneObjectDistance; var raycastObject = m_IntersectionModule.GetFirstGameObject(sourceRayOrigin, out sceneObjectDistance); var uiDistance = currentRaycast.distance; // If the distance to a scene object is less than the distance to the hovered UI, invalidate the UI raycast if (!isManipulator && raycastObject && sceneObjectDistance < uiDistance && !ignoreList.Contains(raycastObject)) { return(false); } } if (m_MenuModule != null && !m_MenuModule.IsValidHover(source)) { return(false); } // Proceed only for raycast sources that haven't been blocked via IBlockUIInteraction if (source.blocked) { return(false); } return(true); }); } } rayOrigin.name = string.Format("{0} Ray Origin", node); var rayTransform = EditorXRUtils.Instantiate(m_ProxyRayPrefab.gameObject, rayOrigin, false).transform; rayTransform.position = rayOrigin.position; rayTransform.rotation = rayOrigin.rotation; var dpr = rayTransform.GetComponent <DefaultProxyRay>(); this.InjectFunctionalitySingle(dpr); m_DefaultRays.Add(rayOrigin, dpr); if (highlightModule != null) { dpr.SetColor(highlightModule.highlightColor); highlightModule.AddRayOriginForNode(node, rayOrigin); } if (keyboardModule != null) { keyboardModule.SpawnKeyboardMallet(rayOrigin); } var proxyExtras = m_ProxyExtras; if (proxyExtras) { var extraData = proxyExtras.data; List <GameObject> prefabs; if (extraData.TryGetValue(rayOriginPair.Key, out prefabs)) { foreach (var prefab in prefabs) { var go = this.InstantiateUI(prefab); go.transform.SetParent(rayOriginPair.Value, false); } } } var tester = rayOriginPair.Value.GetComponentInChildren <IntersectionTester>(); tester.active = proxy.active; m_IntersectionModule.AddTester(tester); if (m_WorkspaceModule != null) { switch (node) { case Node.LeftHand: m_WorkspaceModule.leftRayOrigin = rayOrigin; break; case Node.RightHand: m_WorkspaceModule.rightRayOrigin = rayOrigin; break; } } } if (m_ToolModule != null) { m_ToolModule.SpawnDefaultTools(proxy); } if (m_SerializedPreferences != null) { m_SerializedPreferences.DeserializePreferences(); } if (m_WorkspaceModule != null) { m_WorkspaceModule.CreateSerializedWorkspaces(); } } } }