示例#1
0
        public GameObject CreateCustomButton(GameObject prefab, string sectionName)
        {
            var button = EditorXRUtils.Instantiate(prefab);

            if (string.IsNullOrEmpty(sectionName))
            {
                sectionName = k_UncategorizedFaceName;
            }

            MainMenuFace face;

            if (!m_Faces.TryGetValue(sectionName, out face))
            {
                face = CreateFace(sectionName);
            }

            if (face == null)
            {
                return(null);
            }

            face.AddButton(button.transform);

            var buttonGraphics = button.GetComponentsInChildren <Graphic>();

            if (buttonGraphics != null && buttonGraphics.Length > 0)
            {
                SetupCustomButtonMaterials(buttonGraphics, face);
            }

            return(button);
        }
示例#2
0
        public void Initialize()
        {
            var cameraRig  = CameraUtils.GetCameraRig();
            var proxyTypes = CollectionPool <List <Type>, Type> .GetCollection();

            typeof(IProxy).GetImplementationsOfInterface(proxyTypes);
            foreach (var proxyType in proxyTypes)
            {
                var proxy = (IProxy)EditorXRUtils.CreateGameObjectWithComponent(proxyType, cameraRig, false);
                this.ConnectInterfaces(proxy);
                this.InjectFunctionalitySingle(proxy);
                var trackedObjectInput = m_DeviceInputModule.trackedObjectInput;
                if (trackedObjectInput == null)
                {
                    Debug.LogError("Device Input Module not initialized--trackedObjectInput is null");
                }

                proxy.trackedObjectInput = trackedObjectInput;
                proxy.activeChanged     += () => OnProxyActiveChanged(proxy);

                m_Proxies.Add(proxy);
            }

            CollectionPool <List <Type>, Type> .RecycleCollection(proxyTypes);
        }
示例#3
0
        static void CopyImagesEffectsToCamera(Camera targetCamera)
        {
            var targetCameraGO               = targetCamera.gameObject;
            var potentialImageEffects        = s_ExistingSceneMainCamera.GetComponents <MonoBehaviour>();
            var enabledPotentialImageEffects = potentialImageEffects.Where(x => x != null && x.enabled);
            var targetMethodNames            = new[] { "OnRenderImage", "OnPreRender", "OnPostRender" };
            var bindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;

            foreach (var potentialImageEffect in enabledPotentialImageEffects)
            {
                var componentInstanceType = potentialImageEffect.GetType();
                var targetMethodFound     = false;
                for (int i = 0; i < targetMethodNames.Length; ++i)
                {
                    targetMethodFound = componentInstanceType.GetMethodRecursively(targetMethodNames[i], bindingFlags) != null;

                    if (targetMethodFound)
                    {
                        break;
                    }
                }

                // Copying of certain image effects can cause Unity to crash when copied
                if (targetMethodFound)
                {
                    EditorXRUtils.CopyComponent(potentialImageEffect, targetCameraGO);
                }
            }
        }
示例#4
0
        public void Setup()
        {
            stencilRef        = this.RequestStencilRef();
            m_RadialMenuSlots = new List <RadialMenuSlot>();
            Material slotBorderMaterial = null;

            for (int i = 0; i < k_SlotCount; ++i)
            {
                var menuSlot = EditorXRUtils.Instantiate(m_RadialMenuSlotTemplate.gameObject, m_SlotContainer, false).GetComponent <RadialMenuSlot>();
                menuSlot.stencilRef = stencilRef; // Setting from the UI so there is a single ref ID for all buttons; the buttons cleanup their own materials.
                this.ConnectInterfaces(menuSlot);
                this.InjectFunctionalitySingle(menuSlot);
                menuSlot.orderIndex = i;
                m_RadialMenuSlots.Add(menuSlot);
                menuSlot.hovered += OnButtonHovered;

                if (slotBorderMaterial == null)
                {
                    slotBorderMaterial = menuSlot.borderRendererMaterial;
                }

                // Set a new shared material for the slots in a RadialMenu.
                // This isolates shader changes in a RadialMenu's border material to only the slots in a given RadialMenu
                menuSlot.borderRendererMaterial = slotBorderMaterial;
            }
            SetupRadialSlotPositions();
        }
示例#5
0
        internal GameObject InstantiateUI(GameObject prefab, Transform parent = null, bool worldPositionStays = true, Transform rayOrigin = null)
        {
            var go = EditorXRUtils.Instantiate(prefab, parent ? parent : m_ModuleParent, worldPositionStays);

            foreach (var canvas in go.GetComponentsInChildren <Canvas>())
            {
                canvas.worldCamera = m_EventCamera;
            }

            foreach (var inputField in go.GetComponentsInChildren <InputField>())
            {
                if (inputField is NumericInputField)
                {
                    inputField.spawnKeyboard = m_KeyboardModule.SpawnNumericKeyboard;
                }
                else if (inputField is StandardInputField)
                {
                    inputField.spawnKeyboard = m_KeyboardModule.SpawnAlphaNumericKeyboard;
                }
            }

            foreach (var mb in go.GetComponentsInChildren <MonoBehaviour>(true))
            {
                this.ConnectInterfaces(mb, rayOrigin);
                this.InjectFunctionalitySingle(mb);
            }

            return(go);
        }
示例#6
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;
                }
            }
        }
示例#7
0
        public void Instantiate_InactiveClone()
        {
            var clone = EditorXRUtils.Instantiate(m_GO, null, true, true, false);

            Assert.IsFalse(clone.activeSelf);
            m_ToCleanupAfterEach.Add(clone);
        }
示例#8
0
        public MainMenuButton CreateFaceButton(ButtonData buttonData)
        {
            var button = EditorXRUtils.Instantiate(m_ButtonTemplatePrefab.gameObject);

            button.name = buttonData.name;
            var mainMenuButton = button.GetComponent <MainMenuButton>();

            if (string.IsNullOrEmpty(buttonData.sectionName))
            {
                buttonData.sectionName = k_UncategorizedFaceName;
            }

            mainMenuButton.SetData(buttonData.name, buttonData.description);
            this.ConnectInterfaces(mainMenuButton);

            MainMenuFace face;

            if (!m_Faces.TryGetValue(buttonData.sectionName, out face))
            {
                face = CreateFace(buttonData.sectionName);
            }

            if (face == null)
            {
                return(null);
            }

            face.AddButton(button.transform);
            return(mainMenuButton);
        }
示例#9
0
        void Start()
        {
            if (this.IsSharedUpdater(this) && m_Preferences == null)
            {
                m_Preferences = new Preferences();

                // Share one preferences object across all instances
                foreach (var linkedObject in linkedObjects)
                {
                    ((SelectionTool)linkedObject).m_Preferences = m_Preferences;
                }
            }

            if (this.HasProvider <IProvidesGetDefaultRayColor>())
            {
                m_NormalRayColor = this.GetDefaultRayColor(rayOrigin);
            }

            m_MultiselectRayColor = m_NormalRayColor;
            m_MultiselectRayColor = MaterialUtils.HueShift(m_MultiselectRayColor, k_MultiselectHueShift);

            tooltipTarget = EditorXRUtils.CreateEmptyGameObject("SelectionTool Tooltip Target", rayOrigin).transform;
            tooltipTarget.localPosition = this.GetDeviceType() == DeviceType.Oculus ? k_TouchTooltipPosition : k_ViveTooltipPosition;
            tooltipTarget.localRotation = k_TooltipRotation;

            m_BlockSelectCube = EditorXRUtils.Instantiate(m_BlockSelectCubePrefab, transform);
            m_BlockSelectCube.SetActive(false);
            m_BlockSelectCubeRenderer = m_BlockSelectCube.GetComponent <Renderer>();

            m_BlockSelectSphere = EditorXRUtils.Instantiate(m_BlockSelectSpherePrefab, transform);
            m_BlockSelectSphere.SetActive(false);

            InputUtils.GetBindingDictionaryFromActionMap(m_ActionMap, m_Controls);
        }
示例#10
0
        void SetupBrushUI()
        {
            m_AnnotationPointer = EditorXRUtils.Instantiate(m_AnnotationPointerPrefab, rayOrigin, false).GetComponent <AnnotationPointer>();
            m_OriginalAnnotationPointerLocalScale = m_AnnotationPointer.transform.localScale;
            var brushSize = m_Preferences.brushSize;

            m_AnnotationPointer.Resize(brushSize);

            var brushSizeUi = this.InstantiateUI(m_BrushSizePrefab, rayOrigin: rayOrigin);

            m_BrushSizeUI = brushSizeUi.GetComponent <BrushSizeUI>();

            var transform = brushSizeUi.transform;
            var scale     = transform.localScale;

            transform.SetParent(alternateMenuOrigin, false);
            transform.localPosition = Vector3.zero;
            transform.localRotation = Quaternion.Euler(-90, 0, 0);
            transform.localScale    = scale;

            m_BrushSizeUI.onValueChanged = value =>
            {
                var sliderValue = Mathf.Lerp(MinBrushSize, MaxBrushSize, value);
                m_Preferences.brushSize = sliderValue;
            };
            m_BrushSizeChanged = m_BrushSizeUI.ChangeSliderValue;
        }
示例#11
0
        public void CreateGameObjectWithComponent_SetsParent_WorldPositionStays()
        {
            var comp = EditorXRUtils.CreateGameObjectWithComponent <MeshRenderer>(m_Parent.transform);

            m_ToCleanupAfterEach.Add(comp.gameObject);
            Assert.AreEqual(m_Parent.transform, comp.transform.parent);
            Assert.AreNotEqual(m_Parent.transform.position, comp.transform.position);
        }
示例#12
0
        public void Instantiate_WithParent_WorldPositionStays()
        {
            var clone = EditorXRUtils.Instantiate(m_GO, m_Parent.transform);

            Assert.AreEqual(m_Parent.transform, clone.transform.parent);
            Assert.AreNotEqual(m_Parent.transform.position, clone.transform.position);
            m_ToCleanupAfterEach.Add(clone);
        }
示例#13
0
        public void Initialize()
        {
            m_ModuleParent = ModuleLoaderCore.instance.GetModuleParent().transform;
            m_GroundPlane  = EditorXRUtils.Instantiate(m_GroundPlanePrefab, m_ModuleParent);
            m_GroundPlane.SetActive(false);

            Reset();
        }
示例#14
0
        public void Instantiate_SetRunInEditMode(bool expected)
        {
            Assert.IsFalse(Application.isPlaying);
            var clone = EditorXRUtils.Instantiate(m_GO, null, true, expected);

            AssertRunInEditModeSet(clone, expected);
            m_ToCleanupAfterEach.Add(clone);
        }
示例#15
0
        public void Instantiate_OneArg_ClonesActiveAtOrigin()
        {
            var clone = EditorXRUtils.Instantiate(m_GO);

            Assert.IsTrue(clone.activeSelf);
            Assert.AreEqual(new Vector3(0, 0, 0), clone.transform.position);
            m_ToCleanupAfterEach.Add(clone);
        }
示例#16
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);
        }
示例#17
0
        public override void Setup()
        {
            // Initial bounds must be set before the base.Setup() is called
            minBounds = new Vector3(0.502f, MinBounds.y, 0.3f);
            m_CustomStartingBounds = new Vector3(0.502f, MinBounds.y, 0.6f);

            base.Setup();
            var content = EditorXRUtils.Instantiate(m_ContentPrefab, m_WorkspaceUI.sceneContainer, false);

            m_InspectorUI = content.GetComponent <InspectorUI>();
            foreach (var behavior in content.GetComponentsInChildren <MonoBehaviour>(true))
            {
                this.InjectFunctionalitySingle(behavior);
            }

            m_LockUI = EditorXRUtils.Instantiate(m_LockPrefab, m_WorkspaceUI.frontPanel, false).GetComponentInChildren <LockUI>();
            this.ConnectInterfaces(m_LockUI);
            m_LockUI.clicked            += OnLockButtonClicked;
            m_LockUI.hovered            += OnButtonHovered;
            EditorApplication.delayCall += m_LockUI.Setup; // Need to write stencilRef after WorkspaceButton does it

            var listView = m_InspectorUI.listView;

            this.ConnectInterfaces(listView);
            listView.data = new List <InspectorData>();

            var scrollHandle = m_InspectorUI.scrollHandle;

            scrollHandle.pointerDown  += OnScrollPointerDown;
            scrollHandle.dragging     += OnScrollDragging;
            scrollHandle.pointerUp    += OnScrollPointerUp;
            scrollHandle.hoverStarted += OnScrollHoverStarted;
            scrollHandle.hoverEnded   += OnScrollHoverEnded;

            contentBounds = new Bounds(Vector3.zero, m_CustomStartingBounds.Value);

            var scrollHandleTransform = m_InspectorUI.scrollHandle.transform;

            scrollHandleTransform.SetParent(m_WorkspaceUI.topFaceContainer);
            scrollHandleTransform.localScale    = new Vector3(1.03f, 0.02f, 1.02f); // Extra space for scrolling
            scrollHandleTransform.localPosition = new Vector3(0f, -0.012f, 0f);     // Offset from content for collision purposes

#if UNITY_EDITOR
            listView.arraySizeChanged += OnArraySizeChanged;

            if (Selection.activeGameObject)
            {
                OnSelectionChanged();
            }

            UnityEditor.Undo.postprocessModifications += OnPostprocessModifications;
            UnityEditor.Undo.undoRedoPerformed        += UpdateCurrentObject;
#endif

            // Propagate initial bounds
            OnBoundsChanged();
        }
示例#18
0
        internal IMenu SpawnMenu(Type menuType, Transform rayOrigin)
        {
            var spawnedMenu = (IMenu)EditorXRUtils.AddComponent(menuType, gameObject);

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

            return(spawnedMenu);
        }
示例#19
0
        public void CreateWorkspace(Type t, Action <IWorkspace> createdCallback = null)
        {
            if (!typeof(IWorkspace).IsAssignableFrom(t))
            {
                return;
            }

            // HACK: MiniWorldWorkspace is not working in single pass yet
#if UNITY_EDITOR
            if (t == typeof(MiniWorldWorkspace) && PlayerSettings.stereoRenderingPath != StereoRenderingPath.MultiPass)
            {
                Debug.LogWarning("The MiniWorld workspace is not working on single pass, currently.");
                return;
            }
#endif

            var cameraTransform = CameraUtils.GetMainCamera().transform;

            var workspaceComponent = EditorXRUtils.CreateGameObjectWithComponent(t, CameraUtils.GetCameraRig(), false);
            var workspace          = (IWorkspace)workspaceComponent;
            m_Workspaces.Add(workspace);
            workspace.destroyed += OnWorkspaceDestroyed;
            this.ConnectInterfaces(workspace);
            this.InjectFunctionalitySingle(workspace);

            var evrWorkspace = workspace as Workspace;
            if (evrWorkspace != null)
            {
                evrWorkspace.leftRayOrigin  = leftRayOrigin;
                evrWorkspace.rightRayOrigin = rightRayOrigin;
            }

            //Explicit setup call (instead of setting up in Awake) because we need interfaces to be hooked up first
            workspace.Setup();

            var offset = DefaultWorkspaceOffset;
            offset.z += workspace.vacuumBounds.extents.z;

            var workspaceTransform = workspace.transform;
            workspaceTransform.position = cameraTransform.TransformPoint(offset);
            ResetRotation(workspace, cameraTransform.forward);

            if (createdCallback != null)
            {
                createdCallback(workspace);
            }

            if (workspaceCreated != null)
            {
                workspaceCreated(workspace);
            }

#if UNITY_EDITOR
            EditorXRAnalyticsEvents.WorkspaceState.Send(new UiComponentArgs(t.Name, true));
#endif
        }
示例#20
0
        public void OnBehaviorUpdate()
        {
            if (m_ModuleParent == null)
            {
                return;
            }

            if (snappingEnabled)
            {
                var camera = CameraUtils.GetMainCamera();
                var shouldActivateGroundPlane = false;
                foreach (var statesForRay in m_SnappingStates)
                {
                    foreach (var kvp in statesForRay.Value)
                    {
                        var state = kvp.Value;
                        if (state.groundSnapping)
                        {
                            shouldActivateGroundPlane = true;
                        }

                        var widget = state.widget;
                        if (state.surfaceSnapping && widgetEnabled)
                        {
                            if (widget == null)
                            {
                                widget       = EditorXRUtils.Instantiate(m_Widget, m_ModuleParent).transform;
                                state.widget = widget;
                            }

                            widget.gameObject.SetActive(true);

                            var distanceToCamera = Vector3.Distance(camera.transform.position, state.snappingPosition);
                            widget.position   = state.snappingPosition;
                            widget.rotation   = state.snappingRotation;
                            widget.localScale = k_WidgetScale * distanceToCamera * Vector3.one;
                        }
                        else if (state.widget != null)
                        {
                            widget.gameObject.SetActive(false);
                        }
                    }
                }

                m_GroundPlane.SetActive(shouldActivateGroundPlane);

                if (shouldActivateGroundPlane)
                {
                    m_GroundPlane.transform.localScale = k_GroundPlaneScale * this.GetViewerScale() * Vector3.one;
                }
            }
            else
            {
                m_GroundPlane.SetActive(false);
            }
        }
示例#21
0
        void DisplayHighlightedSubMenuContents()
        {
            m_BackButton.allowInteraction = true;
            ForceClearHomeMenuElements();

            // Find any element hovered by a ray, for later comparison and selection override
            // of menu elements highlighted via other input modes
            SpatialMenu.SpatialMenuData rayHoveredElementMenuData = null;
            if (spatialInterfaceInputMode == SpatialInterfaceInputMode.Ray)
            {
                foreach (var menuElement in m_CurrentlyDisplayedMenuElements)
                {
                    if (menuElement.hoveringNode != Node.None && menuElement.parentMenuData != null)
                    {
                        rayHoveredElementMenuData = menuElement.parentMenuData;
                        break;
                    }
                }
            }

            foreach (var menuData in spatialMenuData)
            {
                // Ray-based elements that are highlighted should take precedence over elements highlighted by other means
                // (neutral, BCI, etc) when changing menu levels
                if (menuData.highlighted && (rayHoveredElementMenuData == null || rayHoveredElementMenuData == menuData))
                {
                    m_CurrentlyDisplayedMenuElements.Clear();
                    var deleteOldChildren = m_SubMenuContainer.GetComponentsInChildren <Transform>().Where(x => x != m_SubMenuContainer);
                    foreach (var child in deleteOldChildren)
                    {
                        if (child != null && child.gameObject != null)
                        {
                            UnityObjectUtils.Destroy(child.gameObject);
                        }
                    }

                    foreach (var subMenuElement in menuData.spatialMenuElements)
                    {
                        var instantiatedPrefab  = EditorXRUtils.Instantiate(m_SubMenuElementPrefab).transform as RectTransform;
                        var providerMenuElement = instantiatedPrefab.GetComponent <SpatialMenuElement>();
                        this.InjectFunctionalitySingle(providerMenuElement);
                        providerMenuElement.Setup(subMenuContainer, () => Debug.Log("Setting up SubMenu : " + subMenuElement.name), subMenuElement.name, subMenuElement.tooltipText);
                        m_CurrentlyDisplayedMenuElements.Add(providerMenuElement);
                        subMenuElement.VisualElement       = providerMenuElement;
                        providerMenuElement.parentMenuData = menuData;
                        providerMenuElement.visible        = true;
                        providerMenuElement.selected       = subMenuElement.correspondingFunction;
                    }

                    break;
                }
            }

            m_HomeSectionDescription.gameObject.SetActive(false);
            this.RestartCoroutine(ref m_HomeSectionTitlesBackgroundBordersTransitionCoroutine, AnimateTopAndBottomCenterBackgroundBorders(false));
        }
示例#22
0
 static void OnVRViewEnabled()
 {
     Resources.UnloadUnusedAssets();
     InitializeInputManager();
     if (!Application.isPlaying)
     {
         instance = EditorXRUtils.CreateGameObjectWithComponent <EditingContextManager>();
         instance.transform.SetParent(ModuleLoaderCore.instance.GetModuleParent().transform);
     }
 }
示例#23
0
        public void SpawnKeyboardMallet(Transform rayOrigin)
        {
            var malletTransform = EditorXRUtils.Instantiate(m_KeyboardMalletPrefab.gameObject, rayOrigin).transform;

            malletTransform.position = rayOrigin.position;
            malletTransform.rotation = rayOrigin.rotation;
            var mallet = malletTransform.GetComponent <KeyboardMallet>();

            mallet.gameObject.SetActive(false);
            m_KeyboardMallets.Add(rayOrigin, mallet);
        }
示例#24
0
        void OnEnable()
        {
            var moduleParent = ModuleLoaderCore.instance.GetModuleParent();

            m_MiniCamera = (Camera)EditorXRUtils.CreateGameObjectWithComponent(typeof(Camera), moduleParent.transform);
            var go = m_MiniCamera.gameObject;

            go.name = "MiniWorldCamera";
            go.tag  = k_MiniWorldCameraTag;
            go.SetActive(false);
            Camera.onPostRender += RenderMiniWorld;
        }
示例#25
0
        public void CreateGameObjectWithComponent_OneArg_TypeAsGeneric()
        {
            var renderer = EditorXRUtils.CreateGameObjectWithComponent <MeshRenderer>();

            m_ToCleanupAfterEach.Add(renderer.gameObject);

            // the object name assigned is based on the component's type name
            var foundObject = GameObject.Find(typeof(MeshRenderer).Name);

            Assert.IsInstanceOf <MeshRenderer>(renderer);
            Assert.IsInstanceOf <MeshRenderer>(foundObject.GetComponent <MeshRenderer>());
        }
示例#26
0
        void SetupCategoryFilterUI()
        {
            m_CategoryFilterUI = EditorXRUtils.Instantiate(m_FilterUIPrefab, m_WorkspaceUI.frontPanel, false).GetComponent <FilterUI>();
            m_CategoryFilterUI.transform.localPosition += Vector3.right * k_FilterUIWidth * 3;
            foreach (var mb in m_CategoryFilterUI.GetComponentsInChildren <MonoBehaviour>())
            {
                this.ConnectInterfaces(mb);
            }

            m_CategoryFilterUI.filterChanged += () =>
            {
                var gridView    = m_PolyUI.gridView;
                var searchQuery = m_CategoryFilterUI.searchQuery;
                if (string.IsNullOrEmpty(searchQuery))
                {
                    gridView.category = PolyCategory.UNSPECIFIED;
                }
                else
                {
                    gridView.category = (PolyCategory)Enum.Parse(typeof(PolyCategory), searchQuery.ToUpper());
                }

                gridView.RequestAssetList();
                UpdateComplexityFilterUI();
            };

            m_CategoryFilterUI.buttonClicked += handle =>
            {
                m_SortingUI.SetListVisibility(false);
                m_FormatFilterUI.SetListVisibility(false);
                m_ComplexityFilterUI.SetListVisibility(false);
            };

            var categoryList = new List <string>();
            var textInfo     = Thread.CurrentThread.CurrentCulture.TextInfo;

            foreach (var category in Enum.GetNames(typeof(PolyCategory)))
            {
                if (category == "UNSPECIFIED")
                {
                    continue;
                }

                categoryList.Add(textInfo.ToTitleCase(category.ToLower()));
            }

            m_CategoryFilterUI.filterList = categoryList;

            m_CategoryFilterUI.GetComponentInChildren <Tooltip>().tooltipText = "Filter by Category";

            UpdateCategoryFilterUI();
        }
示例#27
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));
        }
示例#28
0
        public void Initialize()
        {
            m_ModuleParent  = ModuleLoaderCore.instance.GetModuleParent();
            m_TooltipCanvas = EditorXRUtils.Instantiate(m_TooltipCanvasPrefab).transform;
            m_TooltipCanvas.SetParent(m_ModuleParent.transform);

            m_Tooltips.Clear();
            m_TooltipPool.Clear();
            m_TooltipDataPool.Clear();

            this.SubscribeToRayEntered(OnRayEntered);
            this.SubscribeToRayHovering(OnRayHovering);
            this.SubscribeToRayExited(OnRayExited);
        }
示例#29
0
        void Setup()
        {
            m_CubeTransforms = new Transform[m_TargetTransforms.Length];
            for (var i = 0; i < m_CubeTransforms.Length; i++)
            {
                m_CubeTransforms[i] = EditorXRUtils.Instantiate(m_CubePrefab, m_TargetTransforms[i], false).transform;
            }

            m_HighlightCubeTransforms = new Transform[m_TargetHighlightTransforms.Length];
            for (var i = 0; i < m_TargetHighlightTransforms.Length; i++)
            {
                m_HighlightCubeTransforms[i] = EditorXRUtils.Instantiate(m_HighlightCubePrefab, m_TargetHighlightTransforms[i], false).transform;
            }
        }
示例#30
0
        public void Initialize()
        {
            var eventSystem = FindObjectOfType <EventSystem>();

            if (eventSystem)
            {
                m_InputModule = eventSystem.GetComponent <MultipleRayInputModule>();
                if (!m_InputModule)
                {
                    m_NewInputModule = eventSystem.gameObject.AddComponent <MultipleRayInputModule>();
                    m_InputModule    = m_NewInputModule;
                }
            }
            else
            {
                m_NewEventSystem = new GameObject("EventSystem");
                m_InputModule    = m_NewEventSystem.AddComponent <MultipleRayInputModule>();
            }

#if UNITY_EDITOR
            m_InputModule.StartRunInEditMode();
#endif

            var moduleLoaderCore = ModuleLoaderCore.instance;
            var activeIsland     = m_FIModule.activeIsland;
            activeIsland.AddProviders(new List <IFunctionalityProvider> {
                m_InputModule
            });
            moduleLoaderCore.InjectFunctionalityInModules(activeIsland);

            this.InjectFunctionalitySingle(m_InputModule);
            this.ConnectInterfaces(m_InputModule);

            var customPreviewCamera = m_ViewerModule.customPreviewCamera;
            if (customPreviewCamera != null)
            {
                m_InputModule.layerMask |= customPreviewCamera.hmdOnlyLayerMask;
            }

            var rayModule = moduleLoaderCore.GetModule <EditorXRRayModule>();
            if (rayModule != null)
            {
                m_InputModule.preProcessRaycastSource = rayModule.PreProcessRaycastSource;
            }

            m_EventCamera             = EditorXRUtils.Instantiate(m_EventCameraPrefab.gameObject, m_ModuleParent).GetComponent <Camera>();
            m_EventCamera.enabled     = false;
            m_InputModule.eventCamera = m_EventCamera;
        }