/// <summary>
        /// Set a scene bundle list has current in the application
        /// </summary>
        /// <param name="list"></param>
        public static void SetSceneBundleListHasCurrent(SceneBundleList list)
        {
            Type       sceneBundleListType       = typeof(EnhancedSceneManager);
            MethodInfo setCurrentSceneListMethod = sceneBundleListType.GetMethod("SetCurrentSceneList", BindingFlags.NonPublic | BindingFlags.Static);

            setCurrentSceneListMethod.Invoke(null, new object[] { list });
            EnhancedSceneBuildManager.UpdateBuildScenes();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Update levels in build settings
        /// </summary>
        private void UpdateBuildSettings()
        {
            CheckBundles();

            if (!hasNullReferences)
            {
                EnhancedSceneBuildManager.UpdateBuildScenes();
            }
        }
        /// <summary>
        /// Add scenes to the list, check if there are scenes in the selection to automaticaly add it to the list
        /// </summary>
        private void AddScene()
        {
            //Check if Scene Assets are selected
            SceneAsset[] selectedAssets         = EditorUtils.GetSelectedObjectsOfType <SceneAsset>();
            bool         updateBuildSettingFlag = false;

            if (selectedAssets != null)
            {
                //Add all selected scenes in the list
                int addOffset = SceneAssets.arraySize > 0 ? 1 : 0;
                int fromIndex = SceneAssets.arraySize - addOffset;
                for (int i = 0; i < selectedAssets.Length; i++)
                {
                    if (selectedAssets[i].IsPersistantScene())
                    {
                        continue;                                       //Cannot add persistant scenes
                    }
                    SceneAssets.InsertArrayElementAtIndex(fromIndex + i);
                    SceneAssets.GetArrayElementAtIndex(fromIndex + addOffset + i).objectReferenceValue = selectedAssets[i];
                    if (!EnhancedSceneBuildManager.IsSceneInBuild(selectedAssets[i]) && !updateBuildSettingFlag)
                    {
                        updateBuildSettingFlag = true;
                    }
                }
            }
            else
            {
                if (SceneAssets.arraySize > 0)
                {
                    SceneAssets.InsertArrayElementAtIndex(SceneAssets.arraySize - 1);
                }
                else
                {
                    SceneAssets.InsertArrayElementAtIndex(0);
                }
            }

            if (updateBuildSettingFlag)
            {
                EnhancedSceneBuildManager.UpdateBuildScenes();
            }

            UpdateScenesLabels();
        }
        /// <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();
                }
            };
        }