コード例 #1
0
        private void CreateSceneEditObject()
        {
            bool          focusObject = true;
            MeshHideAsset source      = target as MeshHideAsset;

            if (source.asset == null)
            {
                return;
            }

            if (GeometrySelectorWindow.IsOpen)
            {
                return;
            }

            if (GeometrySelectorExists())
            {
                GameObject.DestroyImmediate(GameObject.Find("GeometrySelector").gameObject);
            }

            bool hasDirtyScenes = false;

            for (int i = 0; i < EditorSceneManager.sceneCount; i++)
            {
                Scene sc = EditorSceneManager.GetSceneAt(i);
                if (sc.isDirty)
                {
                    hasDirtyScenes = true;
                }
            }
            if (hasDirtyScenes)
            {
                int saveChoice = EditorUtility.DisplayDialogComplex("Modified scenes detected", "Opening the Mesh Hide Editor will close all scenes and create a new blank scene. Any current scene changes will be lost unless saved.", "Save and Continue", "Continue without saving", "Cancel");

                switch (saveChoice)
                {
                case 0:                         // Save and continue
                {
                    if (!EditorSceneManager.SaveOpenScenes())
                    {
                        return;
                    }
                    break;
                }

                case 1:                         // don't save and continue
                    break;

                case 2:                         // cancel
                    return;
                }
            }

            SceneView sceneView = SceneView.lastActiveSceneView;

            if (sceneView == null)
            {
                EditorUtility.DisplayDialog("Error", "A Scene View must be open and active", "OK");
                return;
            }

            SceneView.lastActiveSceneView.Focus();

            List <GeometrySelector.SceneInfo> currentscenes = new List <GeometrySelector.SceneInfo>();

            for (int i = 0; i < EditorSceneManager.sceneCount; i++)
            {
                Scene sc = EditorSceneManager.GetSceneAt(i);
                GeometrySelector.SceneInfo si = new GeometrySelector.SceneInfo();
                si.path = sc.path;
                si.name = sc.name;
                if (i == 0)
                {
                    // first scene should clear the temp scene.
                    si.mode = OpenSceneMode.Single;
                }
                else
                {
                    si.mode = sc.isLoaded ? OpenSceneMode.Additive : OpenSceneMode.AdditiveWithoutLoading;
                }
                currentscenes.Add(si);
            }

#if UNITY_2019_1_OR_NEWER
            Scene s = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
#else
            Scene s = EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects, NewSceneMode.Single);
#endif
            EditorSceneManager.SetActiveScene(s);
            GameObject       obj      = EditorUtility.CreateGameObjectWithHideFlags("GeometrySelector", HideFlags.DontSaveInEditor);
            GeometrySelector geometry = obj.AddComponent <GeometrySelector>();

            // Restore the camera position.
            string CamKey = source.name + "_MHA_Cam";
            if (EditorPrefs.HasKey(CamKey))
            {
                string   xform = EditorPrefs.GetString(CamKey);
                CamSaver cs    = CamSaver.FromString(xform);
                sceneView.camera.transform.position      = cs.position;
                sceneView.camera.transform.localRotation = cs.rotation;
                focusObject = false;
            }

            if (geometry != null)
            {
                Selection.activeGameObject = obj;
                if (focusObject)
                {
                    SceneView.lastActiveSceneView.FrameSelected(true);
                }

                // sceneView.camera.transform;
                geometry.meshAsset        = source;
                geometry.restoreScenes    = currentscenes;
                geometry.currentSceneView = sceneView;

#if UNITY_2019_1_OR_NEWER
                geometry.SceneviewLightingState = sceneView.sceneLighting;
                sceneView.sceneLighting         = false;
#else
                geometry.SceneviewLightingState = sceneView.m_SceneLighting;
                sceneView.m_SceneLighting       = false;
#endif
                geometry.InitializeFromMeshData(source.asset.meshData);


                geometry.selectedTriangles = new BitArray(source.triangleFlags[source.asset.subMeshIndex]);

                geometry.UpdateSelectionMesh();
                if (focusObject)
                {
                    SceneView.FrameLastActiveSceneView();
                    SceneView.lastActiveSceneView.FrameSelected();
                }
            }
        }
コード例 #2
0
        void SceneWindow(int WindowID)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label("Selection", GUILayout.Width(100));
            if (GUILayout.Button("Clear"))
            {
                ClearAll();
            }
            if (GUILayout.Button("Select All"))
            {
                SelectAll();
            }
            if (GUILayout.Button("Invert"))
            {
                Invert();
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Selection Mode", GUILayout.Width(100));
            selectionSelected = GUILayout.SelectionGrid(selectionSelected, selectionOptions, selectionOptions.Length);
            if (selectionSelected == 0)
            {
                setSelectedOn = true;
            }
            else
            {
                setSelectedOn = false;
            }

            GUILayout.EndHorizontal();

            GUILayout.Space(10);

            GUILayout.BeginHorizontal();
            GUILayout.Label("Options", GUILayout.Width(100));
            bool toggled = GUILayout.Toggle(showWireframe, new GUIContent("Wireframe", "Toggle showing the Wireframe"), "Button");

            if (toggled != showWireframe)
            {
                UpdateShadingMode(toggled);
            }
            showWireframe = toggled;
            backfaceCull  = GUILayout.Toggle(backfaceCull, new GUIContent("Backface Cull", "Toggle whether to select back faces"), "Button");
            isMirroring   = GUILayout.Toggle(isMirroring, new GUIContent("X Symmetry", "Mirror Selection on X axis"), "Button");
            GUILayout.EndHorizontal();
            if (!isMirroring)
            {
                GUILayout.Space(18);
            }
            else
            {
                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                GUILayout.Label("Symmetry not supported in area select");
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
            }

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Focus Mesh"))
            {
                Selection.activeGameObject   = _Source.gameObject;
                EditorApplication.delayCall += ForceFrame;
            }
            GUILayout.Space(100);
            if (GUILayout.Button("Save & Return"))
            {
                doneEditing = true;
                /* save location and orientation of camera */
                string   CamKey = _Source.meshAsset.name + "_MHA_Cam";
                CamSaver cs     = new CamSaver(_Source.currentSceneView.camera.transform);
                EditorPrefs.SetString(CamKey, cs.ToString());
            }
            if (GUILayout.Button("Cancel Edits"))
            {
                doneEditing = true;
                cancelSave  = true;
            }
            GUILayout.EndHorizontal();
        }