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>
        /// <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
            });
        }
Example #2
0
 public void ConnectDependency(DeviceInputModule dependency)
 {
     m_DeviceInputModule = dependency;
 }
Example #3
0
        void Awake()
        {
            Nested.evr = this;             // Set this once for the convenience of all nested classes

            ClearDeveloperConsoleIfNecessary();

            m_DirectSelection = new DirectSelection();
            m_Interfaces      = new Interfaces();
            m_Menus           = new Menus();
            m_MiniWorlds      = new MiniWorlds();
            m_Rays            = new Rays();
            m_Tools           = new Tools();
            m_UI          = new UI();
            m_Viewer      = new Viewer();
            m_Vacuumables = new Vacuumables();

            m_HierarchyModule     = AddModule <HierarchyModule>();
            m_ProjectFolderModule = AddModule <ProjectFolderModule>();

            VRView.cameraRig.parent    = transform;          // Parent the camera rig under EditorVR
            VRView.cameraRig.hideFlags = defaultHideFlags;
            if (VRSettings.loadedDeviceName == "OpenVR")
            {
                // Steam's reference position should be at the feet and not at the head as we do with Oculus
                VRView.cameraRig.localPosition = Vector3.zero;
            }

            var hmdOnlyLayerMask = 0;

            if (m_PreviewCameraPrefab)
            {
                var go = ObjectUtils.Instantiate(m_PreviewCameraPrefab);
                m_CustomPreviewCamera = go.GetComponentInChildren <IPreviewCamera>();
                if (m_CustomPreviewCamera != null)
                {
                    VRView.customPreviewCamera     = m_CustomPreviewCamera.previewCamera;
                    m_CustomPreviewCamera.vrCamera = VRView.viewerCamera;
                    hmdOnlyLayerMask = m_CustomPreviewCamera.hmdOnlyLayerMask;
                    m_Interfaces.ConnectInterfaces(m_CustomPreviewCamera);
                }
            }
            VRView.cullingMask = UnityEditor.Tools.visibleLayers | hmdOnlyLayerMask;

            m_DeviceInputModule = AddModule <DeviceInputModule>();
            m_DeviceInputModule.InitializePlayerHandle();
            m_DeviceInputModule.CreateDefaultActionMapInputs();
            m_DeviceInputModule.processInput           = ProcessInput;
            m_DeviceInputModule.updatePlayerHandleMaps = m_Tools.UpdatePlayerHandleMaps;

            m_UI.Initialize();

            m_KeyboardModule = AddModule <KeyboardModule>();

            m_DragAndDropModule        = AddModule <DragAndDropModule>();
            m_InputModule.rayEntered  += m_DragAndDropModule.OnRayEntered;
            m_InputModule.rayExited   += m_DragAndDropModule.OnRayExited;
            m_InputModule.dragStarted += m_DragAndDropModule.OnDragStarted;
            m_InputModule.dragEnded   += m_DragAndDropModule.OnDragEnded;

            m_TooltipModule = AddModule <TooltipModule>();
            m_Interfaces.ConnectInterfaces(m_TooltipModule);
            m_InputModule.rayEntered += m_TooltipModule.OnRayEntered;
            m_InputModule.rayExited  += m_TooltipModule.OnRayExited;

            m_PixelRaycastModule               = AddModule <PixelRaycastModule>();
            m_PixelRaycastModule.ignoreRoot    = transform;
            m_PixelRaycastModule.raycastCamera = m_UI.eventCamera;

            m_HighlightModule = AddModule <HighlightModule>();
            m_ActionsModule   = AddModule <ActionsModule>();

            m_LockModule = AddModule <LockModule>();
            m_LockModule.updateAlternateMenu = (rayOrigin, o) => m_Menus.SetAlternateMenuVisibility(rayOrigin, o != null);

            m_SelectionModule              = AddModule <SelectionModule>();
            m_SelectionModule.selected    += m_Rays.SetLastSelectionRayOrigin;          // when a selection occurs in the selection tool, call show in the alternate menu, allowing it to show/hide itself.
            m_SelectionModule.getGroupRoot = GetGroupRoot;

            m_SpatialHashModule = AddModule <SpatialHashModule>();
            m_SpatialHashModule.shouldExcludeObject = go => go.GetComponentInParent <EditorVR>();
            m_SpatialHashModule.Setup();

            m_IntersectionModule = AddModule <IntersectionModule>();
            m_Interfaces.ConnectInterfaces(m_IntersectionModule);
            m_IntersectionModule.Setup(m_SpatialHashModule.spatialHash);

            m_Menus.mainMenuTools = m_Tools.allTools.Where(t => !m_Tools.IsPermanentTool(t)).ToList();             // Don't show tools that can't be selected/toggled

            m_WorkspaceModule = AddModule <WorkspaceModule>();
            m_WorkspaceModule.workspaceCreated   += m_Vacuumables.OnWorkspaceCreated;
            m_WorkspaceModule.workspaceCreated   += m_MiniWorlds.OnWorkspaceCreated;
            m_WorkspaceModule.workspaceCreated   += (workspace) => { m_DeviceInputModule.UpdatePlayerHandleMaps(); };
            m_WorkspaceModule.workspaceDestroyed += m_Vacuumables.OnWorkspaceDestroyed;
            m_WorkspaceModule.workspaceDestroyed += (workspace) => { m_Interfaces.DisconnectInterfaces(workspace); };
            m_WorkspaceModule.workspaceDestroyed += m_MiniWorlds.OnWorkspaceDestroyed;

            UnityBrandColorScheme.sessionGradient = UnityBrandColorScheme.GetRandomGradient();

            m_SceneObjectModule = AddModule <SceneObjectModule>();
            m_SceneObjectModule.shouldPlaceObject = (obj, targetScale) =>
            {
                foreach (var miniWorld in m_MiniWorlds.worlds)
                {
                    if (!miniWorld.Contains(obj.position))
                    {
                        continue;
                    }

                    var referenceTransform = miniWorld.referenceTransform;
                    obj.transform.parent = null;
                    obj.position         = referenceTransform.position + Vector3.Scale(miniWorld.miniWorldTransform.InverseTransformPoint(obj.position), miniWorld.referenceTransform.localScale);
                    obj.rotation         = referenceTransform.rotation * Quaternion.Inverse(miniWorld.miniWorldTransform.rotation) * obj.rotation;
                    obj.localScale       = Vector3.Scale(Vector3.Scale(obj.localScale, referenceTransform.localScale), miniWorld.miniWorldTransform.lossyScale);
                    return(false);
                }

                return(true);
            };

            m_Viewer.AddPlayerModel();

            m_Rays.CreateAllProxies();

            // In case we have anything selected at start, set up manipulators, inspector, etc.
            EditorApplication.delayCall += OnSelectionChanged;
        }