Exemple #1
0
        internal void OnWorkspaceCreated(IWorkspace workspace)
        {
            var miniWorldWorkspace = workspace as MiniWorldWorkspace;

            if (miniWorldWorkspace == null)
            {
                return;
            }

            var maxBounds = this.HasProvider <IProvidesSpatialHash>() ? this.GetAggregateBounds().size.MaxComponent() : 10f;

            miniWorldWorkspace.zoomSliderMax = maxBounds / miniWorldWorkspace.contentBounds.size.MaxComponent();

            var miniWorld = miniWorldWorkspace.miniWorld;
            var worldID   = m_Worlds.Count;

            miniWorld.miniWorldTransform.name = string.Format("Miniworld {0}", worldID);
            m_Worlds.Add(miniWorld);

            m_RayModule.ForEachProxyDevice(deviceData =>
            {
                var node      = deviceData.node;
                var rayOrigin = deviceData.rayOrigin;
                var proxy     = deviceData.proxy;

                var miniWorldRayOrigin    = InstantiateMiniWorldRay();
                miniWorldRayOrigin.name   = string.Format("{0} Miniworld {1} Ray", node, worldID);
                miniWorldRayOrigin.parent = workspace.transform;

                var tester    = miniWorldRayOrigin.GetComponentInChildren <IntersectionTester>();
                tester.active = false;

                m_Rays[miniWorldRayOrigin] = new MiniWorldRay(rayOrigin, miniWorld, proxy, node, tester);

                m_IntersectionModule.AddTester(tester);

                m_HighlightModule.AddRayOriginForNode(node, miniWorldRayOrigin);

                if (proxy.active)
                {
                    if (node == Node.LeftHand)
                    {
                        miniWorldWorkspace.leftRayOrigin = rayOrigin;
                    }

                    if (node == Node.RightHand)
                    {
                        miniWorldWorkspace.rightRayOrigin = rayOrigin;
                    }
                }
            }, false);
        }
Exemple #2
0
        public bool SelectTool(Transform rayOrigin, Type toolType, bool despawnOnReselect = true, bool hideMenu = false)
        {
            var deviceInputModule = ModuleLoaderCore.instance.GetModule <DeviceInputModule>();
            var result            = false;

            m_RayModule.ForEachProxyDevice(device =>
            {
                if (device.rayOrigin == rayOrigin)
                {
                    var spawnTool                       = true;
                    var currentTool                     = device.currentTool;
                    var currentToolType                 = currentTool.GetType();
                    var currentToolIsSelect             = currentToolType == typeof(SelectionTool);
                    var setSelectAsCurrentToolOnDespawn = toolType == typeof(SelectionTool) && !currentToolIsSelect;
                    var toolsMenu                       = device.toolsMenu;

                    // If this tool was on the current device already, remove it, if it is selected while already being the current tool
                    var despawn = (!currentToolIsSelect && currentToolType == toolType && despawnOnReselect) || setSelectAsCurrentToolOnDespawn;
                    if (currentTool != null && despawn)
                    {
                        DespawnTool(device, currentTool);

                        if (!setSelectAsCurrentToolOnDespawn)
                        {
                            // Delete a button of the first type parameter
                            // Then select a button the second type param (the new current tool)
                            // Don't spawn a new tool, since we are only removing the old tool
                            toolsMenu.deleteToolsMenuButton(toolType, currentToolType);
                        }
                        else if (setSelectAsCurrentToolOnDespawn)
                        {
                            // Set the selection tool as the active tool, if select is to be the new current tool
                            toolsMenu.setButtonForType(typeof(SelectionTool), null);
                        }

                        spawnTool = false;
                    }

                    if (spawnTool && !IsDefaultTool(toolType))
                    {
                        // Spawn tool and collect all devices that this tool will need
                        HashSet <InputDevice> usedDevices;
                        var inputDevice = device.inputDevice;
                        var newTool     = SpawnTool(toolType, out usedDevices, inputDevice, rayOrigin, deviceInputModule);
                        var multiTool   = newTool.tool as IMultiDeviceTool;
                        if (multiTool != null)
                        {
                            multiTool.primary = true;
                            m_RayModule.ForEachProxyDevice(otherDeviceData =>
                            {
                                if (otherDeviceData != device)
                                {
                                    HashSet <InputDevice> otherUsedDevices;
                                    var otherToolData = SpawnTool(toolType, out otherUsedDevices, otherDeviceData.inputDevice, otherDeviceData.rayOrigin, deviceInputModule);
                                    foreach (var dd in deviceData)
                                    {
                                        if (!otherUsedDevices.Contains(dd.inputDevice))
                                        {
                                            continue;
                                        }

                                        var otherCurrentTool = otherDeviceData.currentTool;
                                        if (otherCurrentTool != null) // Remove the current tool on all devices this tool will be spawned on
                                        {
                                            DespawnTool(otherDeviceData, otherCurrentTool);
                                        }

                                        AddToolToStack(dd, otherToolData);
                                    }
                                }
                            });
                        }

                        // Exclusive mode tools always take over all tool stacks
                        if (newTool.tool is IExclusiveMode)
                        {
                            foreach (var dev in deviceData)
                            {
                                usedDevices.Add(dev.inputDevice);
                            }
                        }

                        foreach (var data in deviceData)
                        {
                            if (!usedDevices.Contains(data.inputDevice))
                            {
                                continue;
                            }

                            if (currentTool != null) // Remove the current tool on all devices this tool will be spawned on
                            {
                                DespawnTool(device, currentTool);
                            }

                            AddToolToStack(data, newTool);

                            toolsMenu.setButtonForType(toolType, newTool.icon);
                        }
                    }

                    deviceInputModule.UpdatePlayerHandleMaps();
                    result = spawnTool;
                }
                else if (hideMenu)
                {
                    device.menuHideData[device.mainMenu].hideFlags |= MenuHideFlags.Hidden;
                }
            });

#if UNITY_EDITOR
            EditorXRAnalyticsEvents.ToolSelected.Send(new SelectToolArgs {
                label = toolType.Name
            });
#endif
            return(result);
        }