示例#1
0
        void SpawnActions()
        {
            IEnumerable <Type> actionTypes = ObjectUtils.GetImplementationsOfInterface(typeof(IAction));

            foreach (Type 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    = ObjectUtils.AddComponent(actionType, gameObject) as IAction;
                var attribute = (ActionMenuItemAttribute)actionType.GetCustomAttributes(typeof(ActionMenuItemAttribute), false).FirstOrDefault();

                this.ConnectInterfaces(action);

                if (attribute != null)
                {
                    var actionMenuData = new ActionMenuData()
                    {
                        name        = attribute.name,
                        sectionName = attribute.sectionName,
                        priority    = attribute.priority,
                        action      = action,
                    };

                    m_MenuActions.Add(actionMenuData);
                }

                m_Actions.Add(action);
            }

            m_MenuActions.Sort((x, y) => y.priority.CompareTo(x.priority));
        }
示例#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
                });
            }
示例#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>
            /// <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
                });
            }
示例#4
0
        T AddModule <T>() where T : MonoBehaviour
        {
            MonoBehaviour module;
            var           type = typeof(T);

            if (!m_Modules.TryGetValue(type, out module))
            {
                module = ObjectUtils.AddComponent <T>(gameObject);
                m_Modules.Add(type, module);

                foreach (var nested in m_NestedModules.Values)
                {
                    var lateBinding = nested as ILateBindInterfaceMethods <T>;
                    if (lateBinding != null)
                    {
                        lateBinding.LateBindInterfaceMethods((T)module);
                    }
                }

                this.ConnectInterfaces(module);
                m_Interfaces.AttachInterfaceConnectors(module);
            }

            return((T)module);
        }
示例#5
0
        T AddModule <T>() where T : Component
        {
            T module = ObjectUtils.AddComponent <T>(gameObject);

            m_Interfaces.ConnectInterfaces(module);
            return(module);
        }
示例#6
0
            internal IMenu SpawnMenu(Type menuType, Transform rayOrigin)
            {
                var spawnedMenu = (IMenu)ObjectUtils.AddComponent(menuType, evr.gameObject);

                this.ConnectInterfaces(spawnedMenu, rayOrigin);

                return(spawnedMenu);
            }
示例#7
0
            internal T SpawnMenu <T>(Transform rayOrigin) where T : Component, IMenu
            {
                var mainMenu = ObjectUtils.AddComponent <T>(evr.gameObject);

                this.ConnectInterfaces(mainMenu, rayOrigin);

                return(mainMenu);
            }
示例#8
0
        public override void Awake()
        {
            base.Awake();
            m_InputToEvents = ObjectUtils.AddComponent <ViveInputToEvents>(gameObject);
#if !ENABLE_STEAMVR_INPUT
            enabled = false;
#endif
        }
示例#9
0
        public void AddComponent_AddsToObject_TypeAsArg()
        {
            var instance = ObjectUtils.AddComponent(typeof(MeshRenderer), m_Other);
            var onObject = m_Other.GetComponent <MeshRenderer>();

            Assert.IsInstanceOf <Component>(instance);
            Assert.AreEqual((MeshRenderer)instance, onObject);
            AssertRunInEditModeSet(m_Other, true);
        }
            internal IToolsMenu SpawnToolsMenu(Type type, Transform rayOrigin)
            {
                if (!typeof(IToolsMenu).IsAssignableFrom(type))
                {
                    return(null);
                }

                var menu = (IToolsMenu)ObjectUtils.AddComponent(type, evr.gameObject);

                this.ConnectInterfaces(menu, rayOrigin);

                return(menu);
            }
示例#11
0
        public override void Awake()
        {
            if (VRDevice.model.IndexOf("oculus", StringComparison.OrdinalIgnoreCase) >= 0)
            {
                m_LeftHandProxyPrefab  = m_LeftHandTouchProxyPrefab;
                m_RightHandProxyPrefab = m_RightHandTouchProxyPrefab;
            }

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

#if !ENABLE_STEAMVR_INPUT
            enabled = false;
#endif
        }
示例#12
0
        private void OnEnable()
        {
            if (!referenceTransform)
            {
                referenceTransform = ObjectUtils.CreateEmptyGameObject("MiniWorldReference").transform;
            }

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

            Transform rig = CameraUtils.GetCameraRig();

            referenceTransform.position = rig.transform.position;
        }
示例#13
0
            internal static IToolsMenu SpawnToolsMenu(Type type, InputDevice device, out ActionMapInput input)
            {
                input = null;

                if (!typeof(IToolsMenu).IsAssignableFrom(type))
                {
                    return(null);
                }

                var menu = (IToolsMenu)ObjectUtils.AddComponent(type, evr.gameObject);

                input = evr.GetModule <DeviceInputModule>().CreateActionMapInputForObject(menu, device);
                evr.m_Interfaces.ConnectInterfaces(menu, device);

                return(menu);
            }
示例#14
0
            internal IAlternateMenu SpawnAlternateMenu(Type type, InputDevice device, out ActionMapInput input)
            {
                input = null;

                if (!typeof(IAlternateMenu).IsAssignableFrom(type))
                {
                    return(null);
                }

                var alternateMenu = ObjectUtils.AddComponent(type, evr.gameObject) as IAlternateMenu;

                input = evr.m_DeviceInputModule.CreateActionMapInputForObject(alternateMenu, device);
                evr.m_Interfaces.ConnectInterfaces(alternateMenu, device);
                alternateMenu.visible = false;

                return(alternateMenu);
            }
示例#15
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);

            IEnumerable <Type> actionTypes = ObjectUtils.GetImplementationsOfInterface(typeof(IAction));

            foreach (Type 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 = ObjectUtils.AddComponent(actionType, gameObject) as IAction;
                this.ConnectInterfaces(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);
            }

            m_MenuActions.Sort((x, y) => y.priority.CompareTo(x.priority));
        }
示例#16
0
            internal static IMainMenu SpawnMainMenu(Type type, InputDevice device, bool visible, out ActionMapInput input)
            {
                input = null;

                if (!typeof(IMainMenu).IsAssignableFrom(type))
                {
                    return(null);
                }

                var mainMenu = (IMainMenu)ObjectUtils.AddComponent(type, evr.gameObject);

                input = evr.GetModule <DeviceInputModule>().CreateActionMapInputForObject(mainMenu, device);
                evr.m_Interfaces.ConnectInterfaces(mainMenu, device);
                mainMenu.menuHideFlags = visible ? 0 : MenuHideFlags.Hidden;

                return(mainMenu);
            }
示例#17
0
            internal void Initialize()
            {
                // Create event system, input module, and event camera
                ObjectUtils.AddComponent <EventSystem>(evr.gameObject);

                var inputModule = evr.AddModule <MultipleRayInputModule>();

                var customPreviewCamera = evr.GetNestedModule <Viewer>().customPreviewCamera;

                if (customPreviewCamera != null)
                {
                    inputModule.layerMask |= customPreviewCamera.hmdOnlyLayerMask;
                }

                m_EventCamera           = ObjectUtils.Instantiate(evr.m_EventCameraPrefab.gameObject, evr.transform).GetComponent <Camera>();
                m_EventCamera.enabled   = false;
                inputModule.eventCamera = m_EventCamera;

                inputModule.preProcessRaycastSource = evr.GetNestedModule <Rays>().PreProcessRaycastSource;
            }
示例#18
0
            internal void Initialize()
            {
                // Create event system, input module, and event camera
                ObjectUtils.AddComponent <EventSystem>(evr.gameObject);

                var inputModule = evr.AddModule <MultipleRayInputModule>();

                evr.m_InputModule = inputModule;
                evr.m_InputModule.getPointerLength = evr.m_DirectSelection.GetPointerLength;

                if (evr.m_CustomPreviewCamera != null)
                {
                    evr.m_InputModule.layerMask |= evr.m_CustomPreviewCamera.hmdOnlyLayerMask;
                }

                eventCamera             = ObjectUtils.Instantiate(evr.m_EventCameraPrefab.gameObject, evr.transform).GetComponent <Camera>();
                eventCamera.enabled     = false;
                inputModule.eventCamera = eventCamera;

                inputModule.preProcessRaycastSource = evr.m_Rays.PreProcessRaycastSource;
            }
示例#19
0
        protected override void Awake()
        {
            m_IsOculus = XRDevice.model.IndexOf("oculus", StringComparison.OrdinalIgnoreCase) >= 0;

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

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

            var proxyHelper = m_LeftHand.GetComponent <ViveProxyHelper>();

            if (proxyHelper)
            {
                foreach (var placementOverride in proxyHelper.leftPlacementOverrides)
                {
                    placementOverride.tooltip.placements = placementOverride.placements;
                }
            }
        }
示例#20
0
 public override void Awake()
 {
     base.Awake();
     transform.position = CameraUtils.GetCameraRig().position;             // Reference position should be the camera rig root, so remove any offsets
     m_InputToEvents    = ObjectUtils.AddComponent <SixenseInputToEvents>(gameObject);
 }
示例#21
0
            internal void SpawnDefaultTools(IProxy proxy)
            {
                var vacuumables  = evr.GetNestedModule <Vacuumables>();
                var lockModule   = evr.GetModule <LockModule>();
                var defaultTools = evr.m_DefaultTools;

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

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

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

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

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

                    IMainMenu mainMenu     = null;
                    var       menus        = evr.GetNestedModule <Menus>();
                    var       menuHideData = deviceData.menuHideData;
                    if (DefaultMenu != null)
                    {
                        mainMenu               = (IMainMenu)menus.SpawnMenu(DefaultMenu, rayOrigin);
                        deviceData.mainMenu    = mainMenu;
                        menuHideData[mainMenu] = new Menus.MenuHideData();
                    }

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

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

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

                    if (!toolsMenu)
                    {
                        toolsMenu = ObjectUtils.AddComponent <Experimental.EditorVR.Menus.ToolsMenu>(evr.gameObject);
                    }

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

                    var spatialMenu = ObjectUtils.AddComponent <SpatialMenu>(evr.gameObject);
                    this.ConnectInterfaces(spatialMenu, rayOrigin);
                    spatialMenu.Setup();
                }

                evr.GetModule <DeviceInputModule>().UpdatePlayerHandleMaps();
            }
示例#22
0
 protected override void Awake()
 {
     base.Awake();
     m_InputToEvents = ObjectUtils.AddComponent <OVRTouchInputToEvents>(gameObject);
 }