/// <summary>
        /// Return true if the scene belongs to the persistant scene bundle
        /// </summary>
        /// <param name="scene"></param>
        /// <returns></returns>
        public static bool IsPersistantScene(this SceneAsset scene)
        {
            if (scene == null)
            {
                return(false);
            }
            SceneBundleList currentList = EnhancedSceneManager.GetCurrentSceneList();

            if (currentList == null)
            {
                return(false);
            }
            if (currentList.PersistantScenesBundle == null)
            {
                return(false);
            }

            for (int i = 0; i < currentList.PersistantScenesBundle.ScenesCount; i++)
            {
                if (currentList.PersistantScenesBundle.ContainsScene(scene.name))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #2
0
        /// <summary>
        /// Setup the the behaviour and displayed parameters of the levels reorderable list
        /// </summary>
        private void SetupSceneBundleReorderableList()
        {
            sceneBundleList = new ReorderableList(serializedObject, serializedObject.FindProperty("scenesBundles"), true, true, true, true)
            {
                drawHeaderCallback = rect => {
                    EditorGUI.LabelField(rect, "Scene Bundles");
                },

                //Draw the inspector and fields of a level bundle container
                drawElementCallback = (rect, index, a, h) => {
                    Rect propertyRect = rect;
                    rect.height = EditorGUIUtility.singleLineHeight;
                    GUIContent label = new GUIContent();

                    if (index == 0)
                    {
                        label.text = "Default Bundle";
                        EditorUtils.BeginColorField(EditorUtils.validColor);
                    }
                    else
                    {
                        label.text = "Bundle " + index;
                    }

                    EditorGUI.PropertyField(rect, sceneBundleList.serializedProperty.GetArrayElementAtIndex(index), label);

                    if (index == 0)
                    {
                        EditorUtils.EndColorField();
                    }
                },

                //
                //Filter if scene bundles are selected to automaticaly add it
                onAddCallback = list => {
                    AddSceneBundle(list.serializedProperty);
                },

                //Check if there are more than one level to enable delete button
                onCanRemoveCallback = list => {
                    return(list.count > 1);
                },

                //Delete the entire slot when remove
                onRemoveCallback = list => {
                    if (list.serializedProperty.GetArrayElementAtIndex(list.index) != null)
                    {
                        list.serializedProperty.DeleteArrayElementAtIndex(list.index);
                    }
                    list.serializedProperty.DeleteArrayElementAtIndex(list.index);

                    //Update build scenes
                    if (target == EnhancedSceneManager.GetCurrentSceneList())
                    {
                        updateBuildSettingsFlag = true;
                    }
                }
            };
        }
Exemple #3
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            if (updateBuildSettingsFlag)
            {
                updateBuildSettingsFlag = false;
            }

            EditorGUILayout.PropertyField(persistantSceneBundle);

            GUILayout.Space(8f);
            EditorGUI.BeginChangeCheck();
            sceneBundleList.DoLayoutList();
            if (EditorGUI.EndChangeCheck())
            {
                updateBuildSettingsFlag = true;
            }

            EditorGUILayout.Separator();

            if (hasSimilarReferences)
            {
                EditorGUILayout.HelpBox("Similar references! There will be automatically removed once you stop editing this object", MessageType.Warning);
            }

            if (hasNullReferences)
            {
                EditorGUILayout.HelpBox("Null references! There will be automatically removed once you stop editing this object", MessageType.Error);
            }

            if (EnhancedSceneManager.GetCurrentSceneList() == target)
            {
                EditorGUILayout.HelpBox("Current Scene Bundle List", MessageType.None);
            }
            else
            {
                if (GUILayout.Button("Set as current"))
                {
                    EditorEnhancedSceneManager.SetSceneBundleListHasCurrent(target as SceneBundleList);
                }
            }

            serializedObject.ApplyModifiedProperties();
            if (updateBuildSettingsFlag)
            {
                UpdateBuildSettings();
            }
        }
        /// <summary>
        /// Check the scene data and scene bundles
        /// </summary>
        /// <returns></returns>
        private static void CheckDatas()
        {
            SceneBundleList           currentSceneList  = EnhancedSceneManager.GetCurrentSceneList();
            List <SerializedProperty> propertiesToCheck = new List <SerializedProperty>();

            if (currentSceneList.PersistantScenesBundle != null)
            {
                SerializedObject sceneBundleObject = new SerializedObject(currentSceneList.PersistantScenesBundle);
                sceneBundleObject.FindProperty("sceneAssets").CleanNullOrSimilarRefs();
            }

            SerializedObject   sceneListSO          = new SerializedObject(currentSceneList);
            SerializedProperty sceneBundlesProperty = sceneListSO.FindProperty("scenesBundles");

            for (int i = 0; i < sceneBundlesProperty.arraySize; i++)
            {
                SceneBundleEditor.GenerateSceneLabels(new SerializedObject(sceneBundlesProperty.GetArrayElementAtIndex(i).objectReferenceValue));
            }

            //Reupdate the build scenes
            UpdateBuildScenes();
        }
Exemple #5
0
        /// <summary>
        /// Add a scene bundle to the current list
        /// </summary>
        private void AddSceneBundle(SerializedProperty listArray)
        {
            SceneBundle[] selectedBundles = EditorUtils.GetSelectedObjectsOfType <SceneBundle>();
            if (selectedBundles != null)
            {
                for (int i = 0; i < selectedBundles.Length; i++)
                {
                    if (listArray.arraySize > 0)
                    {
                        listArray.InsertArrayElementAtIndex(listArray.arraySize - 1);
                    }
                    else
                    {
                        listArray.InsertArrayElementAtIndex(0);
                    }
                    listArray.GetArrayElementAtIndex(listArray.arraySize - 1).objectReferenceValue = selectedBundles[i];
                }

                //Update build scenes only if new scenes are added
                if (target == EnhancedSceneManager.GetCurrentSceneList())
                {
                    updateBuildSettingsFlag = true;
                }
            }
            else
            {
                //Just add an element
                if (listArray.arraySize > 0)
                {
                    listArray.InsertArrayElementAtIndex(listArray.arraySize - 1);
                }
                else
                {
                    listArray.InsertArrayElementAtIndex(0);
                }
            }

            CheckBundles();
        }
        private void OnGUI()
        {
            EditorGUILayout.Space();
            scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
            var sceneList = EnhancedSceneManager.GetCurrentSceneList();

            if (sceneList)
            {
                DisplaySceneBundles(sceneList);
            }
            else
            {
                EditorGUILayout.HelpBox("Any current scene list is currently existing. Create a new one", MessageType.Warning);
                if (GUILayout.Button("Create Scene Bundle List"))
                {
                    CreateSceneBundleList();
                }
            }

            EditorGUILayout.Separator();

            DisplayCurrentSceneList();
            EditorGUILayout.EndScrollView();
        }
        /// <summary>
        /// Update all build scenes, check if
        /// </summary>
        public static void UpdateBuildScenes()
        {
            SceneBundleList currentSceneList = EnhancedSceneManager.GetCurrentSceneList();

            if (currentSceneList == null)
            {
                return;
            }

            //Create the container of build scenes
            var buildSettingsScenes = new List <EditorBuildSettingsScene>();

            //Add Startup Scene
            SceneAsset startupSceneAsset = Resources.Load <SceneAsset>("StartupScene");
            var        startupScene      = new EditorBuildSettingsScene(AssetDatabase.GetAssetPath(startupSceneAsset), true);

            buildSettingsScenes.Add(startupScene);

            bool BuildContainsScene(string path)
            {
                for (int i = 0; i < buildSettingsScenes.Count; i++)
                {
                    if (buildSettingsScenes[i].path == path)
                    {
                        return(true);
                    }
                }
                return(false);
            }

            //Add persistant scenes
            if (currentSceneList.PersistantScenesBundle != null)
            {
                SceneAsset[] peristantScenes = SceneBundleEditor.GetBundleScenesAssets(currentSceneList.PersistantScenesBundle);
                foreach (SceneAsset sceneAsset in peristantScenes)
                {
                    var persistantBuildScene = new EditorBuildSettingsScene(AssetDatabase.GetAssetPath(sceneAsset), true);

                    if (!BuildContainsScene(persistantBuildScene.path))
                    {
                        buildSettingsScenes.Add(persistantBuildScene);
                    }
                }
            }

            //Add scenes
            foreach (SceneBundle bundle in currentSceneList.ScenesBundles)
            {
                SceneAsset[] sceneAssets = SceneBundleEditor.GetBundleScenesAssets(bundle);
                foreach (SceneAsset sceneAsset in sceneAssets)
                {
                    var buildScene = new EditorBuildSettingsScene(AssetDatabase.GetAssetPath(sceneAsset), true);

                    if (!BuildContainsScene(buildScene.path))
                    {
                        buildSettingsScenes.Add(buildScene);
                    }
                }
            }

            //Replace the current build setting scenes with new list
            EditorBuildSettings.scenes = buildSettingsScenes.ToArray();
        }
        /// <summary>
        /// Setup the scene assets reorderable list display and callbacks
        /// </summary>
        private void SetupSceneAssetsReorderableList()
        {
            sceneAssetsList = new ReorderableList(serializedObject, serializedObject.FindProperty("sceneAssets"), true, true, true, true)
            {
                drawHeaderCallback = rect => {
                    EditorGUI.LabelField(rect, "Scenes");
                },

                drawElementCallback = (rect, index, a, h) => {
                    Rect propertyRect = rect;
                    propertyRect.height = EditorGUIUtility.singleLineHeight;
                    GUIContent label = new GUIContent();

                    if (index == 0)
                    {
                        label.text = "Active Scene";
                        EditorUtils.BeginColorField(EditorUtils.validColor);
                    }
                    else
                    {
                        label.text = "Scene " + index;
                    }

                    SceneBundleList currentSceneList = EnhancedSceneManager.GetCurrentSceneList();

                    EditorGUI.BeginChangeCheck();
                    SerializedProperty property = sceneAssetsList.serializedProperty.GetArrayElementAtIndex(index);
                    EditorGUI.PropertyField(propertyRect, property, label);

                    if (EditorGUI.EndChangeCheck())
                    {
                        if (currentSceneList.PersistantScenesBundle != target && (property.objectReferenceValue as SceneAsset).IsPersistantScene())
                        {
                            Debug.LogWarning("Cannot register persistant scenes");
                            property.objectReferenceValue = null;
                        }
                        else
                        {
                            //Update the generated labels
                            UpdateScenesLabels();

                            //If this scene doesn't exist in the build settings, refresh it
                            if (property.objectReferenceValue != null && !EnhancedSceneBuildManager.IsSceneInBuild(property.objectReferenceValue as SceneAsset))
                            {
                                EnhancedSceneBuildManager.UpdateBuildScenes();
                            }
                        }
                    }

                    if (index == 0)
                    {
                        EditorUtils.EndColorField();
                    }
                },

                onReorderCallback = list => {
                    UpdateScenesLabels();
                },

                onAddCallback = list => {
                    AddScene();
                },

                onCanRemoveCallback = list => {
                    return(list.index != 0);
                },

                onRemoveCallback = list => {
                    SerializedProperty prop = list.serializedProperty;
                    if (prop.GetArrayElementAtIndex(list.index) != null)
                    {
                        prop.DeleteArrayElementAtIndex(list.index);
                    }
                    prop.DeleteArrayElementAtIndex(list.index);
                    UpdateScenesLabels();
                    EnhancedSceneBuildManager.UpdateBuildScenes();
                }
            };
        }
Exemple #9
0
 /// <summary>
 /// Initalize the scene system assigning the current scene list in the Enhanced Scene Manager and loading the default Scene Bundle
 /// </summary>
 private void Initialize()
 {
     EnhancedSceneManager.LoadSceneBundle(EnhancedSceneManager.GetCurrentSceneList().DefaultSceneBundle);
 }
        /// <summary>
        /// Display the current scene list field
        /// </summary>
        private void DisplayCurrentSceneList()
        {
            EditorGUI.BeginChangeCheck();
            SceneBundleList list = EditorGUILayout.ObjectField("Current Bundle List", EnhancedSceneManager.GetCurrentSceneList(), typeof(SceneBundleList), false) as SceneBundleList;

            if (EditorGUI.EndChangeCheck() && list != null)
            {
                EditorEnhancedSceneManager.SetSceneBundleListHasCurrent(list);
            }
        }