Ejemplo n.º 1
0
        protected override void Awake()
        {
#if UNITY_2020_2_OR_NEWER
            m_IsOculus = true; // TODO: Use XR Management
#else
#pragma warning disable 618
            m_IsOculus = XRDevice.model.IndexOf("oculus", StringComparison.OrdinalIgnoreCase) >= 0;
#pragma warning restore 618
#endif

            if (m_IsOculus)
            {
                m_LeftHandProxyPrefab  = m_LeftHandTouchProxyPrefab;
                m_RightHandProxyPrefab = m_RightHandTouchProxyPrefab;
            }

            base.Awake();
            m_InputToEvents = EditorXRUtils.AddComponent <ViveInputToEvents>(gameObject);

            var proxyHelper = m_LeftHand.GetComponent <ViveProxyHelper>();
            if (proxyHelper)
            {
                foreach (var placementOverride in proxyHelper.leftPlacementOverrides)
                {
                    placementOverride.tooltip.placements = placementOverride.placements;
                }
            }
        }
Ejemplo n.º 2
0
        public void AddComponent_AddsToObject_TypeAsArg()
        {
            var instance = EditorXRUtils.AddComponent(typeof(MeshRenderer), m_Other);
            var onObject = m_Other.GetComponent <MeshRenderer>();

            Assert.IsInstanceOf <Component>(instance);
            Assert.AreEqual((MeshRenderer)instance, onObject);
            AssertRunInEditModeSet(m_Other, true);
        }
Ejemplo n.º 3
0
        internal IMenu SpawnMenu(Type menuType, Transform rayOrigin)
        {
            var spawnedMenu = (IMenu)EditorXRUtils.AddComponent(menuType, gameObject);

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

            return(spawnedMenu);
        }
Ejemplo n.º 4
0
        void SpawnActions()
        {
            m_SpatialMenuData.Clear();
            var spatialMenuActions = new List <SpatialMenu.SpatialMenuElementContainer>();
            var spatialMenuData    = new SpatialMenu.SpatialMenuData("Actions", "Perform actions on selected object", spatialMenuActions);

            m_SpatialMenuData.Add(spatialMenuData);

            m_MenuActions.Clear();
            var actionTypes = CollectionPool <List <Type>, Type> .GetCollection();

            typeof(IAction).GetImplementationsOfInterface(actionTypes);
            foreach (var actionType in actionTypes)
            {
                // Don't treat vanilla actions or tool actions as first class actions
                if (actionType.IsNested || !typeof(MonoBehaviour).IsAssignableFrom(actionType))
                {
                    continue;
                }

                var action = EditorXRUtils.AddComponent(actionType, gameObject) as IAction;
                this.ConnectInterfaces(action);
                this.InjectFunctionalitySingle(action);

                var defaultActionAttribute = (ActionMenuItemAttribute)actionType.GetCustomAttributes(typeof(ActionMenuItemAttribute), false).FirstOrDefault();
                if (defaultActionAttribute != null)
                {
                    var actionMenuData = new ActionMenuData()
                    {
                        name        = defaultActionAttribute.name,
                        sectionName = defaultActionAttribute.sectionName,
                        priority    = defaultActionAttribute.priority,
                        action      = action,
                    };

                    m_MenuActions.Add(actionMenuData);
                }

                var spatialMenuAttribute = (SpatialMenuItemAttribute)actionType.GetCustomAttributes(typeof(SpatialMenuItemAttribute), false).FirstOrDefault();
                if (spatialMenuAttribute != null)
                {
                    spatialMenuActions.Add(new SpatialMenu.SpatialMenuElementContainer(spatialMenuAttribute.name, spatialMenuAttribute.description, (node) => action.ExecuteAction()));
                }

                m_Actions.Add(action);
            }

            CollectionPool <List <Type>, Type> .RecycleCollection(actionTypes);

            m_MenuActions.Sort((x, y) => y.priority.CompareTo(x.priority));
        }
Ejemplo n.º 5
0
        private void OnEnable()
        {
            if (!referenceTransform)
            {
                referenceTransform        = EditorXRUtils.CreateEmptyGameObject("MiniWorldReference").transform;
                referenceTransform.parent = ModuleLoaderCore.instance.GetModuleParent().transform;
            }

            m_MiniWorldRenderer             = EditorXRUtils.AddComponent <MiniWorldRenderer>(CameraUtils.GetMainCamera().gameObject);
            m_MiniWorldRenderer.miniWorld   = this;
            m_MiniWorldRenderer.cullingMask = m_RendererCullingMask;

            Transform rig = CameraUtils.GetCameraRig();

            referenceTransform.position = rig.transform.position;
        }
Ejemplo n.º 6
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
            });
        }
Ejemplo n.º 7
0
        internal void SpawnDefaultTools(IProxy proxy)
        {
            var defaultTools = EditorXR.DefaultTools;

            if (defaultTools == null)
            {
                return;
            }

            var moduleLoaderCore  = ModuleLoaderCore.instance;
            var menuModule        = moduleLoaderCore.GetModule <EditorXRMenuModule>();
            var lockModule        = moduleLoaderCore.GetModule <LockModule>();
            var deviceInputModule = moduleLoaderCore.GetModule <DeviceInputModule>();
            var vacuumablesModule = moduleLoaderCore.GetModule <EditorXRVacuumableModule>();
            var vacuumables       = vacuumablesModule != null ? vacuumablesModule.vacuumables : new List <IVacuumable>();

            foreach (var device in deviceData)
            {
                var      inputDevice       = device.inputDevice;
                ToolData selectionToolData = null;

                if (device.proxy != proxy)
                {
                    continue;
                }

                var rayOrigin = device.rayOrigin;
                foreach (var toolType in defaultTools)
                {
                    HashSet <InputDevice> devices;
                    var toolData = SpawnTool(toolType, out devices, inputDevice, rayOrigin, deviceInputModule);
                    AddToolToDeviceData(toolData, devices);

                    var tool          = toolData.tool;
                    var selectionTool = tool as SelectionTool;
                    if (selectionTool)
                    {
                        selectionToolData = toolData;
                        if (lockModule != null)
                        {
                            selectionTool.hovered += lockModule.OnHovered;
                        }
                    }

                    var vacuumTool = tool as VacuumTool;
                    if (vacuumTool)
                    {
                        vacuumTool.defaultOffset = WorkspaceModule.DefaultWorkspaceOffset;
                        vacuumTool.defaultTilt   = WorkspaceModule.DefaultWorkspaceTilt;
                        vacuumTool.vacuumables   = vacuumables;
                    }
                }

                IMainMenu mainMenu;
                var       menuHideData = device.menuHideData;
                if (EditorXR.DefaultMenu != null)
                {
                    mainMenu               = (IMainMenu)menuModule.SpawnMenu(EditorXR.DefaultMenu, rayOrigin);
                    device.mainMenu        = mainMenu;
                    menuHideData[mainMenu] = new MenuHideData();
                }

                if (EditorXR.DefaultAlternateMenu != null)
                {
                    var alternateMenu = (IAlternateMenu)menuModule.SpawnMenu(EditorXR.DefaultAlternateMenu, rayOrigin);
                    menuHideData[alternateMenu] = new MenuHideData();
                    var radialMenu = alternateMenu as RadialMenu;
                    if (radialMenu)
                    {
                        radialMenu.itemWasSelected += menuModule.UpdateAlternateMenuOnSelectionChanged;
                    }
                }

                var undoMenu = menuModule.SpawnMenu <UndoMenu>(rayOrigin);
                var hideData = new MenuHideData();
                menuHideData[undoMenu] = hideData;
                hideData.hideFlags     = 0;

                // Setup ToolsMenu
                ToolsMenu toolsMenu  = null;
                var       toolsMenus = gameObject.GetComponents <ToolsMenu>();
                foreach (var m in toolsMenus)
                {
                    if (!m.enabled)
                    {
                        toolsMenu = m;
                        break;
                    }
                }

                if (!toolsMenu)
                {
                    toolsMenu = EditorXRUtils.AddComponent <ToolsMenu>(gameObject);
                }

                toolsMenu.enabled = true;
                this.ConnectInterfaces(toolsMenu, rayOrigin);
                this.InjectFunctionalitySingle(toolsMenu);
                device.toolsMenu    = toolsMenu;
                toolsMenu.rayOrigin = rayOrigin;
                toolsMenu.setButtonForType(typeof(IMainMenu), null);
                toolsMenu.setButtonForType(typeof(SelectionTool), selectionToolData != null ? selectionToolData.icon : null);

                var spatialMenu = EditorXRUtils.AddComponent <SpatialMenu>(gameObject);
                this.ConnectInterfaces(spatialMenu, rayOrigin);
                this.InjectFunctionalitySingle(spatialMenu);
                spatialMenu.Setup();
                device.spatialMenu = spatialMenu;
            }

            if (deviceInputModule != null)
            {
                deviceInputModule.UpdatePlayerHandleMaps();
            }
        }
Ejemplo n.º 8
0
        public static void CreateCameraRig(ref Camera camera, out Transform cameraRig)
        {
            const float nearClipPlane = 0.01f;
            const float farClipPlane  = 1000f;

            // Redundant assignment for player builds
            // ReSharper disable once RedundantAssignment
            GameObject rigGO = null;

            var debugSettings = ModuleLoaderDebugSettings.instance;
            var hideFlags     = debugSettings.moduleHideFlags;

            if (Application.isPlaying)
            {
                camera.nearClipPlane        = nearClipPlane;
                camera.farClipPlane         = farClipPlane;
                camera.gameObject.hideFlags = hideFlags;

                rigGO = new GameObject("VRCameraRig")
                {
                    hideFlags = hideFlags
                };
            }
#if UNITY_EDITOR
            else
            {
                s_ExistingSceneMainCamera = Camera.main;

                // TODO: Copy camera settings when changing contexts
                var defaultContext = EditingContextManager.defaultContext;
                if (defaultContext.copyMainCameraSettings && s_ExistingSceneMainCamera && s_ExistingSceneMainCamera.enabled)
                {
                    GameObject cameraGO = EditorUtility.CreateGameObjectWithHideFlags(k_CameraName, hideFlags);
                    camera = EditorXRUtils.CopyComponent(s_ExistingSceneMainCamera, cameraGO);

                    if (camera.nearClipPlane > nearClipPlane)
                    {
                        Debug.LogWarning("Copying settings from scene camera that is tagged 'MainCamera'." + Environment.NewLine +
                                         " Clipping issues may occur with NearClipPlane values is greater than " + nearClipPlane);

                        camera.nearClipPlane = nearClipPlane;
                    }

                    // TODO: Support multiple cameras
                    if (camera.clearFlags == CameraClearFlags.Nothing)
                    {
                        camera.clearFlags = CameraClearFlags.SolidColor;
                    }

                    camera.stereoTargetEye = StereoTargetEyeMask.Both;

                    // Force HDR on because of a bug in the mirror view
                    camera.allowHDR = true;
                }
                else
                {
                    GameObject cameraGO = EditorUtility.CreateGameObjectWithHideFlags(k_CameraName, hideFlags, typeof(Camera));
                    camera = cameraGO.GetComponent <Camera>();

                    camera.nearClipPlane = nearClipPlane;
                    camera.farClipPlane  = farClipPlane;
                }

                camera.enabled             = false;
                camera.cameraType          = CameraType.VR;
                camera.useOcclusionCulling = false;

                if (s_ExistingSceneMainCamera && defaultContext.copyMainCameraImageEffectsToHMD)
                {
                    CopyImagesEffectsToCamera(viewerCamera);

                    s_ExistingSceneMainCameraEnabledState = s_ExistingSceneMainCamera.enabled;
                    s_ExistingSceneMainCamera.enabled     = false; // Disable existing MainCamera in the scene
                }

                rigGO = EditorUtility.CreateGameObjectWithHideFlags("VRCameraRig", hideFlags);
            }
#endif

            EditorXRUtils.AddComponent <EditorMonoBehaviour>(rigGO);
            cameraRig = rigGO.transform;
            camera.transform.parent = cameraRig;

            if (Application.isPlaying)
            {
                var tpd = camera.GetComponent <TrackedPoseDriver>();
                if (!tpd)
                {
                    tpd = camera.gameObject.AddComponent <TrackedPoseDriver>();
                }

                tpd.UseRelativeTransform = false;
            }
            else
            {
                cameraRig.rotation = Quaternion.identity;
                cameraRig.position = headCenteredOrigin;
            }
        }
Ejemplo n.º 9
0
 protected override void Awake()
 {
     base.Awake();
     m_InputToEvents = EditorXRUtils.AddComponent <OVRTouchInputToEvents>(gameObject);
 }