Example #1
0
            /// <summary>
            /// Spawn a tool on a tool stack for a specific device (e.g. right hand).
            /// </summary>
            /// <param name="toolType">The tool to spawn</param>
            /// <param name="usedDevices">A list of the used devices coming from the action map</param>
            /// <param name="device">The input device whose tool stack the tool should be spawned on (optional). If not
            /// specified, then it uses the action map to determine which devices the tool should be spawned on.</param>
            /// <returns> Returns tool that was spawned or null if the spawn failed.</returns>
            ToolData SpawnTool(Type toolType, out HashSet <InputDevice> usedDevices, InputDevice device, Transform rayOrigin)
            {
                usedDevices = new HashSet <InputDevice>();
                if (!typeof(ITool).IsAssignableFrom(toolType))
                {
                    return(null);
                }

                var deviceSlots    = new HashSet <DeviceSlot>();
                var tool           = ObjectUtils.AddComponent(toolType, evr.gameObject) as ITool;
                var actionMapInput = evr.GetModule <DeviceInputModule>().CreateActionMapInputForObject(tool, device);

                if (actionMapInput != null)
                {
                    usedDevices.UnionWith(actionMapInput.GetCurrentlyUsedDevices());
                    InputUtils.CollectDeviceSlotsFromActionMapInput(actionMapInput, ref deviceSlots);

                    actionMapInput.Reset(false);
                }

                if (usedDevices.Count == 0)
                {
                    usedDevices.Add(device);
                }

                this.ConnectInterfaces(tool, rayOrigin);

                var icon = tool as IMenuIcon;

                return(new ToolData {
                    tool = tool, input = actionMapInput, icon = icon != null ? icon.icon : null
                });
            }
Example #2
0
            /// <summary>
            /// Spawn a tool on a tool stack for a specific device (e.g. right hand).
            /// </summary>
            /// <param name="toolType">The tool to spawn</param>
            /// <param name="usedDevices">A list of the used devices coming from the action map</param>
            /// <param name="device">The input device whose tool stack the tool should be spawned on (optional). If not
            /// specified, then it uses the action map to determine which devices the tool should be spawned on.</param>
            /// <returns> Returns tool that was spawned or null if the spawn failed.</returns>
            static ToolData SpawnTool(Type toolType, out HashSet <InputDevice> usedDevices, InputDevice device = null)
            {
                usedDevices = new HashSet <InputDevice>();
                if (!typeof(ITool).IsAssignableFrom(toolType))
                {
                    return(null);
                }

                var deviceSlots = new HashSet <DeviceSlot>();
                var tool        = ObjectUtils.AddComponent(toolType, evr.gameObject) as ITool;

                var actionMapInput = evr.GetModule <DeviceInputModule>().CreateActionMapInputForObject(tool, device);

                if (actionMapInput != null)
                {
                    usedDevices.UnionWith(actionMapInput.GetCurrentlyUsedDevices());
                    InputUtils.CollectDeviceSlotsFromActionMapInput(actionMapInput, ref deviceSlots);
                }

                if (usedDevices.Count == 0)
                {
                    usedDevices.Add(device);
                }

                evr.m_Interfaces.ConnectInterfaces(tool, device);

                return(new ToolData {
                    tool = tool, input = actionMapInput
                });
            }
Example #3
0
        /// <summary>
        /// Spawn a tool on a tool stack for a specific device (e.g. right hand).
        /// </summary>
        /// <param name="toolType">The tool to spawn</param>
        /// <param name="usedDevices">A list of the used devices coming from the action map</param>
        /// <param name="device">The input device whose tool stack the tool should be spawned on (optional). If not
        /// specified, then it uses the action map to determine which devices the tool should be spawned on.</param>
        /// <param name="rayOrigin">The ray origin on which to spawn th tool</param>
        /// <param name="deviceInputModule">The device input module, if it exists</param>
        /// <returns> Returns tool that was spawned or null if the spawn failed.</returns>
        ToolData SpawnTool(Type toolType, out HashSet <InputDevice> usedDevices, InputDevice device, Transform rayOrigin,
                           DeviceInputModule deviceInputModule)
        {
            usedDevices = new HashSet <InputDevice>();
            if (!typeof(ITool).IsAssignableFrom(toolType))
            {
                Debug.LogWarningFormat("Cannot spawn {0} which is not an ITool", toolType.Name);
                return(null);
            }

            var            deviceSlots    = new HashSet <DeviceSlot>();
            var            tool           = EditorXRUtils.AddComponent(toolType, gameObject) as ITool;
            ActionMapInput actionMapInput = null;

            if (deviceInputModule != null)
            {
                actionMapInput = deviceInputModule.CreateActionMapInputForObject(tool, device);
                if (actionMapInput != null)
                {
                    usedDevices.UnionWith(actionMapInput.GetCurrentlyUsedDevices());
                    InputUtils.CollectDeviceSlotsFromActionMapInput(actionMapInput, ref deviceSlots);

                    actionMapInput.Reset(false);
                }
            }

            if (usedDevices.Count == 0)
            {
                usedDevices.Add(device);
            }

            this.InjectFunctionalitySingle(tool);
            this.ConnectInterfaces(tool, rayOrigin);

            var icon = tool as IMenuIcon;

            return(new ToolData {
                tool = tool, input = actionMapInput, icon = icon != null ? icon.icon : null
            });
        }