/// <summary>
        /// Draw our inspector
        /// </summary>
        public override void OnInspectorGUI()
        {
            serializedObject.Update();
            sceneConfig = (MultiSceneLoader)target;

            EditorGUILayout.Space();
            GUILayout.Label(Loc.WindowTitle, EditorStyles.boldLabel);

            GUILayout.Label(Loc.TopDesc, EditorStyles.helpBox);

            GUILayout.Space(15f);

            topToggle = EditorGUILayout.Foldout(topToggle, Loc.ConfigList);
            if (topToggle)
            {
                topScroll = GUILayout.BeginScrollView(topScroll, false, true);
                {
                    GUILayout.BeginVertical();
                    {
                        GUILayout.BeginHorizontal();
                        {
                            GUILayout.Space(15f);

                            GUILayout.BeginVertical();
                            {
                                // Render our config editors
                                for (var j = 0; j < sceneConfig.config.Count; j++)
                                {
                                    var entry = sceneConfig.config[j];
                                    if (foldoutState.ContainsKey(entry))
                                    {
                                        foldoutState[entry] = EditorGUILayout.Foldout(foldoutState[entry], entry.name);
                                    }
                                    else
                                    {
                                        foldoutState.Add(entry, false);
                                        foldoutState[entry] = EditorGUILayout.Foldout(foldoutState[entry], entry.name);
                                    }

                                    if (foldoutState[entry])
                                    {
                                        GUILayout.BeginHorizontal();
                                        {
                                            GUILayout.Space(10f);
                                            GUILayout.BeginVertical();
                                            {
                                                GUILayout.BeginHorizontal();
                                                {
                                                    GUILayout.Label(Loc.ConfigName, GUILayout.Width(120f));
                                                    entry.name = GUILayout.TextField(entry.name);
                                                }
                                                GUILayout.EndHorizontal();
                                                // scene list
                                                for (var i = 0; i < entry.sceneList.Count; i++)
                                                {
                                                    GUILayout.BeginHorizontal();
                                                    {
                                                        entry.sceneList[i] = EditorGUILayout.ObjectField(Loc.SceneName, entry.sceneList[i], typeof(Object), false);
                                                        if (GUILayout.Button("-", GUILayout.Width(35f)))
                                                        {
                                                            entry.sceneList.Remove(entry.sceneList[i]);
                                                        }
                                                    }
                                                    GUILayout.EndHorizontal();
                                                }

                                                if (GUILayout.Button(Loc.AddNewScene))
                                                {
                                                    entry.sceneList.Add(new Object());
                                                }
                                                GUILayout.Space(15f);
                                                if (sceneConfig.config.Count > 1)
                                                {
                                                    GUILayout.Label(Loc.MoveConfig, EditorStyles.helpBox);
                                                    GUILayout.BeginHorizontal();
                                                    {
                                                        if (GUILayout.Button(Loc.MoveTop))
                                                        {
                                                            ReorderListEntry(entry, ListSort.MovetoTop);
                                                        }
                                                        if (GetConfigIndex(entry) != 0)
                                                        {
                                                            if (GUILayout.Button(Loc.MoveUp))
                                                            {
                                                                ReorderListEntry(entry, ListSort.MoveUp);
                                                            }
                                                        }
                                                        if (GetConfigIndex(entry) != sceneConfig.config.Count - 1)
                                                        {
                                                            if (GUILayout.Button(Loc.MoveDown))
                                                            {
                                                                ReorderListEntry(entry, ListSort.MoveDown);
                                                            }
                                                        }
                                                        if (GUILayout.Button(Loc.MoveBottom))
                                                        {
                                                            ReorderListEntry(entry, ListSort.MoveToBottom);
                                                        }
                                                    }
                                                    GUILayout.EndHorizontal();
                                                }
                                                if (GUILayout.Button(Loc.RemoveConfig))
                                                {
                                                    sceneConfig.config.Remove(entry);
                                                    foldoutState.Remove(entry);
                                                }
                                                GUILayout.Space(15f);
                                            }
                                            GUILayout.EndVertical();
                                        }
                                        GUILayout.EndHorizontal();
                                    }
                                }
                            }
                            GUILayout.EndVertical();
                        }
                        GUILayout.EndHorizontal();
                    }
                    GUILayout.EndVertical();

                    if (GUILayout.Button(Loc.AddNewConfig))
                    {
                        var newConfig = new SceneConfig()
                        {
                            name = Loc.NewConfigName
                        };
                        sceneConfig.config.Add(newConfig);
                    }
                }
                GUILayout.Space(5f);
                GUILayout.EndScrollView();
            }

            EditorGUILayout.Space(10f);

            botToggle = EditorGUILayout.Foldout(botToggle, Loc.SceneLoading);
            if (botToggle)
            {
                botScroll = GUILayout.BeginScrollView(botScroll, false, true);
                {
                    EditorGUILayout.Space(5);
                    GUILayout.Label(Loc.LoadAllScenes, EditorStyles.boldLabel);
                    EditorGUILayout.Space(5);
                    if (GUILayout.Button(Loc.LoadAllScenes, GUILayout.MinHeight(100), GUILayout.Height(35)))
                    {
                        sceneConfig.LoadAllScenes();
                    }
                    GUILayout.Label(Loc.LoadAllScenesDesc, EditorStyles.helpBox);

                    EditorGUILayout.Space(5);
                    GUILayout.Label(Loc.LoadSubScenes, EditorStyles.boldLabel);
                    GUILayout.Label(Loc.LoadSubScenesDesc, EditorStyles.helpBox);

                    foreach (var entry in sceneConfig.config)
                    {
                        EditorGUILayout.Space(5);
                        var buttonText = string.Format(Loc.LoadXScenes, entry.name);
                        if (GUILayout.Button(buttonText, GUILayout.MinHeight(100), GUILayout.Height(35)))
                        {
                            sceneConfig.LoadSceneConfig(entry, true);
                        }
                        GUILayout.Label(Loc.LoadOnlyScenes + entry.name + ".", EditorStyles.helpBox);
                    }
                }
                GUILayout.EndScrollView();
                GUILayout.Space(5f);
            }

            EditorGUILayout.Space();

            if (GUI.changed)
            {
                needToSave = true;
            }

            if (GUILayout.Button("Save Changes", GUILayout.Height(35f)))
            {
                if (needToSave)
                {
                    SaveChanges(serializedObject);
                }
            }
        }
Beispiel #2
0
 private void OnEnable()
 {
     sceneConfig = (MultiSceneLoader)target;
 }