コード例 #1
0
ファイル: ScenePackageGUI.cs プロジェクト: Driiade/Match3
        static void OnSceneGUI(SceneView sceneview)
        {
            ScriptableGUIStyle.LoadAllGUIStyle();

            ScriptableScenePackage[] scenePackages = FindAssetExtension.GetAllInstances <ScriptableScenePackage>();

            for (int i = scenePackages.Length - 1; i >= 0; i--)
            {
                if (!scenePackages[i].showOnGUI)
                {
                    ArrayUtility.RemoveAt(ref scenePackages, i);
                }
            }

            Array.Sort(scenePackages, (x, y) => { return(x.name.CompareTo(y.name)); });

            string[] scenePackageNames = new string[scenePackages.Length];
            for (int i = 0; i < scenePackages.Length; i++)
            {
                scenePackageNames[i] = scenePackages[i].folderName + scenePackages[i].name;
            }

            Rect screenRect       = sceneview.camera.pixelRect;
            Rect scenePackageRect = new Rect(screenRect.x + screenRect.width - 150, screenRect.y + 150, 150, 50);

#if UNITY_2019
            GUILayout.Window(0, scenePackageRect, (id) =>
            {
#else
            GUILayout.BeginArea(scenePackageRect);
            {
#endif
                GUILayoutExtension.CenterLayout(() =>
                {
                    EditorGUILayout.BeginVertical("box");
                    {
                        GUILayout.Label("Scene Package", "ScenePackageTitle");
                        GUILayout.Space(5);

                        EditorGUI.BeginChangeCheck();
                        {
                            currentIndex = EditorGUILayout.Popup(currentIndex, scenePackageNames);
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            scenePackages[currentIndex].EditorLoadScenePackage();
                        }
                    }
                    EditorGUILayout.EndVertical();
                });
#if UNITY_2019
            }, "");
#else
            }
コード例 #2
0
        public override void OnInspectorGUI()
        {
            ScriptableScenePackage scenePackage = (ScriptableScenePackage)target;

            Undo.RecordObject(scenePackage, "ScenePackage");
            EditorGUI.BeginChangeCheck();
            {
                SceneAsset[] scenes = FindAssetExtension.GetAllInstances <SceneAsset>();

                string[] sceneNames = new string[scenes.Length];
                for (int i = 0; i < scenes.Length; i++)
                {
                    sceneNames[i] = scenes[i].name;
                }

                sceneNames = sceneNames.OrderBy(x => x).ToArray();

                int currentIndex = 0;

                for (int i = 0; i < scenes.Length; i++)
                {
                    if (sceneNames[i] == scenePackage.activeScene)
                    {
                        currentIndex = i;
                        break;
                    }
                }

                scenePackage.activeScene = sceneNames[EditorGUILayout.Popup("Active Scene", currentIndex, sceneNames)];
                GUILayout.Space(10);

                EditorGUILayout.BeginVertical("box");
                {
                    scenePackage.startScenePackages = (ScriptableScenePackage[])AutoClassInspectorExtension.GenericField("Start Scene package", scenePackage.startScenePackages, typeof(ScriptableScenePackage[]));
                }
                EditorGUILayout.EndVertical();

                GUILayout.Space(10);

                DisplayArray("Scenes", ref scenePackage.scenes, sceneNames);
                GUILayout.Space(5);
                DisplayArray("Cheat Scenes", ref scenePackage.cheatScenes, sceneNames);

                GUILayout.Space(10);

                EditorGUILayout.BeginVertical("box");
                {
                    scenePackage.endScenePackages = (ScriptableScenePackage[])AutoClassInspectorExtension.GenericField("End Scene package", scenePackage.endScenePackages, typeof(ScriptableScenePackage[]));
                }
                EditorGUILayout.EndVertical();

                DisplayArray("Optional Scenes", ref scenePackage.optionalScenes, sceneNames);

                GUILayout.Space(20);
                scenePackage.folderName = EditorGUILayout.TextField("Folder Name", scenePackage.folderName);
                scenePackage.showOnGUI  = EditorGUILayout.Toggle("Show on GUI", scenePackage.showOnGUI);
                scenePackage.participateToOptimization = EditorGUILayout.Toggle("Participate to optimization", scenePackage.participateToOptimization);
            }
            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(scenePackage);
            }

            GUILayout.Space(20);
            if (GUILayout.Button("Load it"))
            {
                EditorScenePackageExtension.EditorLoadScenePackage(scenePackage);
            }
        }
コード例 #3
0
        public static void EditorLoadScenePackage(this ScriptableScenePackage scriptableScenePackage, bool askSaveToUser = true, bool removeScene = true)
        {
            if (askSaveToUser)
            {
                EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo();
            }

            EditorApplication.isPaused  = false;
            EditorApplication.isPlaying = false;

            for (int i = 0; i < scriptableScenePackage.startScenePackages.Length; i++)
            {
                scriptableScenePackage.startScenePackages[i].EditorLoadScenePackage(false, false);
            }

            SceneAsset[] sceneAssets = FindAssetExtension.GetAllInstances <SceneAsset>();

            for (int i = 0; i < scriptableScenePackage.scenes.Length; i++)
            {
                Scene s = EditorSceneManager.GetSceneByName(scriptableScenePackage.scenes[i]);

                if (!s.isLoaded)
                {
                    EditorSceneManager.OpenScene(AssetDatabase.GetAssetPath(Array.Find(sceneAssets, (x) => { return(x.name == scriptableScenePackage.scenes[i]); })), OpenSceneMode.Additive);
                }

                EditorSceneManager.SetActiveScene(EditorSceneManager.GetSceneByName(scriptableScenePackage.scenes[i]));
            }

            for (int i = 0; i < scriptableScenePackage.cheatScenes.Length; i++)
            {
                Scene s = EditorSceneManager.GetSceneByName(scriptableScenePackage.cheatScenes[i]);
                if (!s.isLoaded)
                {
                    EditorSceneManager.OpenScene(AssetDatabase.GetAssetPath(Array.Find(sceneAssets, (x) => { return(x.name == scriptableScenePackage.cheatScenes[i]); })), OpenSceneMode.Additive);
                }
            }

            for (int i = 0; i < scriptableScenePackage.endScenePackages.Length; i++)
            {
                scriptableScenePackage.endScenePackages[i].EditorLoadScenePackage(false, false);
            }

            if (removeScene)
            {
                for (int i = EditorSceneManager.sceneCount - 1; i >= 0; i--)
                {
                    Scene s = EditorSceneManager.GetSceneAt(i);

                    if (ScriptableScenePackage.SceneHasToBeRemoved(scriptableScenePackage, s.name))
                    {
                        EditorSceneManager.CloseScene(s, true);
                    }
                }
            }


            if (!String.IsNullOrEmpty(scriptableScenePackage.activeScene) && EditorSceneManager.GetSceneByName(scriptableScenePackage.activeScene).IsValid())
            {
                EditorSceneManager.SetActiveScene(EditorSceneManager.GetSceneByName(scriptableScenePackage.activeScene));
            }
        }