Esempio n. 1
0
        public void LoadModule()
        {
            IUsesPointerMethods.getPointerLength = GetPointerLength;

            var moduleLoaderCore = ModuleLoaderCore.instance;

            m_IntersectionModule = moduleLoaderCore.GetModule <IntersectionModule>();
            m_MiniWorldModule    = moduleLoaderCore.GetModule <EditorXRMiniWorldModule>();
            m_RayModule          = moduleLoaderCore.GetModule <EditorXRRayModule>();
            m_SceneObjectModule  = moduleLoaderCore.GetModule <SceneObjectModule>();
            m_ViewerModule       = moduleLoaderCore.GetModule <EditorXRViewerModule>();
            m_ToolModule         = moduleLoaderCore.GetModule <EditorXRToolModule>();
        }
Esempio n. 2
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;
        }