Пример #1
0
        private void CopyConfiguration()
        {
            if (this._currentConfiguration == null)
            {
                return;
            }
            var obj = new JObject();

            this._currentConfiguration.ToJson(obj);

            string nameBase = this._currentConfiguration.name;
            string name     = nameBase;
            string path     = null;
            int    i        = 0;

            while (true)
            {
                path = BuildConfigurationsDir + name + ".json";
                if (!File.Exists(path))
                {
                    break;
                }

                name = nameBase + (++i).ToString();
            }

            var config = new BuilderConfiguration();

            config.name = name;
            config.FromJson(obj);
            File.WriteAllText(path, obj.ToString(Newtonsoft.Json.Formatting.Indented), Encoding.UTF8);

            this._currentConfigurationName  = name;
            this._currentConfiguration      = config;
            this._currentConfigurationDirty = false;
        }
Пример #2
0
        private void OnEnable()
        {
            ClearCache();

            if (!this._initialized)
            {
                this._currentConfigurationName = BuilderPreferences.lastConfiguration;
                this._initialized = true;
                return;
            }

            if (!string.IsNullOrEmpty(this._currentConfigurationSerialized))
            {
                this._currentConfiguration      = new BuilderConfiguration();
                this._currentConfiguration.name = this._currentConfigurationName;
                this._currentConfiguration.FromJson(JObject.Parse(this._currentConfigurationSerialized));
            }
            else
            {
                this._currentConfiguration = null;
            }

            this._currentConfigurationSerialized = null;
        }
Пример #3
0
        private void OnGUI()
        {
            var options = GetOptions();

            if (options.Length > 0)
            {
                for (int i = 0; i < options.Length; i++)
                {
                    this.OnOptionGUI(options[i]);
                }
                EditorGUILayout.Space();
            }


            var configs = GetConfigurations();

            int oldConfigIndex = this._currentConfigurationName != null?System.Array.IndexOf(configs, this._currentConfigurationName) : -1;

            int newConfigIndex = EditorGUILayout.Popup(
                oldConfigIndex,
                configs
                );

            if (newConfigIndex != oldConfigIndex)
            {
                this._currentConfigurationName = newConfigIndex != -1 ? configs[newConfigIndex] : null;
                this._currentConfiguration     = null;
            }

            BuilderPreferences.lastConfiguration = this._currentConfigurationName;

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("New"))
            {
                this.CreateNewConfiguration();
            }
            if (GUILayout.Button("Copy"))
            {
                this.CopyConfiguration();
            }

            var bg = GUI.backgroundColor;

            if (this._currentConfiguration != null && this._currentConfigurationDirty)
            {
                GUI.backgroundColor = Color.yellow;
            }
            if (GUILayout.Button(this._currentConfiguration != null && this._currentConfigurationDirty ? "Save*" : "Save"))
            {
                this.SaveCurrentConfiguration();
            }
            GUI.backgroundColor = bg;

            EditorGUILayout.EndHorizontal();

            if (this._currentConfiguration == null && this._currentConfigurationName != null)
            {
                this._currentConfiguration      = this.LoadConfiguration(this._currentConfigurationName);
                this._currentConfigurationDirty = false;
            }

            if (this._currentConfiguration != null)
            {
                bg = GUI.backgroundColor;
                GUI.backgroundColor = Color.green;
                if (GUILayout.Button("Build " + this._currentConfiguration.name))
                {
                    if (this._currentConfigurationDirty)
                    {
                        this.SaveCurrentConfiguration();
                    }
                    Debug.ClearDeveloperConsole();

                    var currentOptions = this.GetCurrentOptions();
                    EditorApplication.delayCall += () => {
                        this._currentConfiguration.Build(currentOptions);
                    };
                }
                GUI.backgroundColor = bg;
            }

            this._scrollPos = EditorGUILayout.BeginScrollView(this._scrollPos);
            if (this._currentConfiguration != null)
            {
                this._currentConfigurationDirty |= this._currentConfiguration.OnGUI();
            }
            EditorGUILayout.EndScrollView();

            if (this._currentConfiguration != null)
            {
                var modules     = BuilderModule.GetModules();
                int moduleIndex = EditorGUILayout.Popup("Add Module", -1, modules.ConvertAll(x => x.description).ToArray());
                var module      = moduleIndex >= 0 ? modules[moduleIndex] : null;

                if (module != null)
                {
                    this._currentConfiguration.AddModule(module);
                    this._currentConfigurationDirty = true;
                }
            }

            if (GUILayout.Button("Player Settings"))
            {
                EditorApplication.ExecuteMenuItem("Edit/Project Settings/Player");
            }
        }