////////////////////////////////////////////////////////////////////////
        // Public Static Methods
        ////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Enables the zSpace XR Overlay.
        /// </summary>
        public static void Enable()
        {
            EditorWindow gameViewWindow =
                EditorWindowExtensions.GetGameViewWindow();

            // Update the Game View window's title text as an indicator
            // that the zSpace XR Overlay is enabled.
            gameViewWindow.titleContent.text = "Game zSpace";

            // Parent the GameView window to the XR Overlay.
            // NOTE: A side effect of calling GetWindowHandle() will
            //       place the associated Editor Window in focus.
            ZPlugin.SetXROverlayParentWindowHandle(
                gameViewWindow.GetWindowHandle());

            // Register XR Overlay callbacks.
            ZPlugin.SetXROverlayOnDestroyCallback(
                Marshal.GetFunctionPointerForDelegate(s_onDestroyedCallback));

            // Initialize the XR Overlay's position and size.
            RectInt rect = gameViewWindow.GetClientRect();

            ZPlugin.SetXROverlayDimensions(
                rect.x, rect.y, rect.width, rect.height);

            // Create the XR Overlay.
            ZPlugin.CreateXROverlay();
            ZPlugin.SetXROverlayEnabled(true);

            // Force the application to run in the background while the XR
            // Overlay is enabled. This is necessary since upon creation, the
            // XR Overlay steals focus from the GameView window and causes
            // the application to pause.
            Application.runInBackground = true;
        }
        private static void CacheSettings()
        {
            EditorWindow gameViewWindow =
                EditorWindowExtensions.GetGameViewWindow();

            s_gameViewName = gameViewWindow.titleContent.text;

            s_runInBackground = Application.runInBackground;
        }
        /// <summary>
        /// Disables the zSpace XR Overlay.
        /// </summary>
        public static void Disable()
        {
            // Restore the Game View window's title text.
            EditorWindow gameViewWindow =
                EditorWindowExtensions.GetGameViewWindow();

            gameViewWindow.titleContent.text = s_gameViewName;

            // Restore whether the application was original set to run in
            // the background.
            Application.runInBackground = s_runInBackground;

            // Shut down and destroy the XR Overlay.
            ZPlugin.DestroyXROverlay();
        }
Exemple #4
0
        public void OnGUI()
        {
            EditorWindowExtensions.SetTitle(this, "Utility");
            GUILayout.Label("--------------------------------------------------------------");
            this.DrawMeshCombiner();
            GUILayout.Label("--------------------------------------------------------------");
            this.DrawMaterialReplacer();
            GUILayout.Label("--------------------------------------------------------------");
            this.DrawPrefaber();
            GUILayout.Label("--------------------------------------------------------------");
            this.DrawMaterialSelector();
            GUILayout.Label("--------------------------------------------------------------");
            this.DrawSelector();
            GUILayout.Label("--------------------------------------------------------------");
            this.DrawShaderSelector();
            //GUILayout.Label("--------------------------------------------------------------");
            //this.DrawAssigner();
            GUILayout.Label("--------------------------------------------------------------");
            this.DrawRenamer();
            GUILayout.Label("--------------------------------------------------------------");
            this.DrawSelectorRow(this.optionA, "Replace");
            this.DrawSelectorRow(this.optionB, "With");
            bool ready = this.optionA.found.Count > 0 && this.optionB.found.Count > 0;

            if (!ready)
            {
                return;
            }
            if (this.optionA.type == ReplaceOption.Prefab && this.optionA.targetPath == "")
            {
                GUI.skin.label.normal.textColor = Colors.names["chestnut"];
                string warning = "Actual .prefab source must exist to perform replacement.";
                GUI.Label(new Rect(5, 55, 400, 20), warning);
                GUI.skin.label.normal.textColor = Color.white;
            }
            else
            {
                GUILayout.BeginHorizontal("");
                if (GUILayout.Button("Apply", GUILayout.Width(100)))
                {
                    this.PerformReplace();
                }
                this.preserveScale = GUILayout.Toggle(this.preserveScale, "Preserve Scale", GUILayout.Width(120));
                GUILayout.EndHorizontal();
            }
        }
        ////////////////////////////////////////////////////////////////////////
        // Private Static Methods
        ////////////////////////////////////////////////////////////////////////

        private static void OnUpdate()
        {
            if (!Application.isPlaying ||
                !EditorPrefs.GetBool(ZMenu.EnableXROverlayMenuItem))
            {
                return;
            }

            // Check if there is a pending recreate request and if
            // so, recreate the XR Overlay.
            if (s_recreateRequest)
            {
                Enable();

                s_recreateRequest = false;
            }

            // If the XR Overlay is active, update it.
            if (ZPlugin.IsXROverlayActive())
            {
                EditorWindow gameViewWindow =
                    EditorWindowExtensions.GetGameViewWindow();

                // Update the XR Overlay's position and size.
                RectInt rect = gameViewWindow.GetClientRect();

                ZPlugin.SetXROverlayDimensions(
                    rect.x, rect.y, rect.width, rect.height);

                // Update whether the XR Overlay is enabled based on whether
                // it is currently overlapped.
                bool isGameViewFocused    = gameViewWindow.IsFocused();
                bool isGameViewOverlapped = gameViewWindow.IsOverlappedBy(
                    EditorWindow.focusedWindow);

                if (isGameViewFocused)
                {
                    ZPlugin.SetXROverlayEnabled(true);
                }
                else if (isGameViewOverlapped)
                {
                    ZPlugin.SetXROverlayEnabled(false);
                }
            }
        }
        //public void OnDestroy(){this.OnDisable();}
        //==================
        // Interface
        //==================
        public void OnGUI()
        {
            EditorUI.Reset();
            EditorUI.SetFieldSize(-1, 175, false);
            var width        = (Screen.width * 0.25f).Clamp(100, 250).ToInt();
            var mergeStyle   = EditorStyles.miniButtonLeft.FixedHeight(0);
            var flattenStyle = EditorStyles.miniButtonRight.FixedHeight(0);

            if (this.operationMode == OperationMode.Merge)
            {
                mergeStyle = mergeStyle.UseState("onNormal", "*");
            }
            if (this.operationMode == OperationMode.Flatten)
            {
                flattenStyle = flattenStyle.UseState("onNormal", "*");
            }
            EditorGUILayout.BeginVertical(new GUIStyle().Margin(8, 8, 15, 8));
            EditorGUILayout.BeginHorizontal(new GUIStyle().Margin(0, 0, 0, 10).Center(width * 2));
            if ("Merge".ToLabel().Layout(width, 20).DrawButton(mergeStyle))
            {
                this.operationMode = OperationMode.Merge;
            }
            if ("Flatten".ToLabel().Layout(width, 20).DrawButton(flattenStyle))
            {
                this.operationMode = OperationMode.Flatten;
            }
            EditorGUILayout.EndHorizontal();
            if (this.operationMode.Has("Merge"))
            {
                EditorWindowExtensions.SetTitle(this, "Mesh");
                //"Vertex".DrawLabel(EditorStyles.boldLabel);
                this.vertexMode          = this.vertexMode.Draw("Vertex Mode").As <VertexMode>();
                this.vertexDisplay       = this.vertexDisplay.DrawMask("Vertex Display").As <VertexDisplay>();
                this.vertexColor         = this.vertexColor.Draw("Vertex Color");
                this.vertexDistanceColor = this.vertexDistanceColor.Draw("Vertex Distance Color");
                this.vertexOverlapColor  = this.vertexOverlapColor.Draw("Vertex Overlap Color");
                this.distance            = this.distance.DrawSlider(0, 1f, "Vertex Overlap Distance");
                this.size          = this.size.DrawSlider(0, 1, "Vertex Size");
                this.scaleFactor   = this.scaleFactor.DrawSlider(1, 10, "Vertex Display Scale");
                this.scale         = (0.0625f * Mathf.Pow(2, this.scaleFactor - 1));
                this.alwaysDisplay = this.alwaysDisplay.Draw("Always Display");
                var lockText = this.lockSelection ? "Unlock Selection" : "Lock Selection";
                GUI.enabled = this.lockSelection || this.cached.Count > 0;
                if (lockText.ToLabel().Layout(150, 25).DrawButton() && (this.lockSelection || this.cached.Count > 0))
                {
                    this.lockSelection = !this.lockSelection;
                }
                GUI.enabled = true;
            }
            else if (this.operationMode.Has("Flatten"))
            {
            }
            if (EditorUI.anyChanged)
            {
                ProxyEditor.RegisterUndo(this, "Mesh Operation Changes");
                this.Repaint();
                this.RefreshSceneView();
            }
            EditorGUILayout.EndVertical();
            this.visible = true;
        }