public State(BuilderConfiguration config, Dictionary <string, string> options) { this._options = options; this.modules = new List <BuilderModule>(config.modules.Count); foreach (var m in config.modules) { var info = BuilderModule.GetModule(m.name); if (info == null) { continue; } var module = info.Instantiate(); var o = new JObject(); m.ToJson(o); module.FromJson(o); this.modules.Add(module); } }
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"); } }
public bool OnGUI() { EditorGUI.BeginChangeCheck(); this.name = EditorGUILayout.TextField("Name", this.name); this.option = EditorGUILayout.TextField("Option", this.option); GUI.backgroundColor = Color.gray; this.buildPath = EditorGUILayout.TextField("Path", this.buildPath); this.buildTarget = (BuildTarget)EditorGUILayout.EnumPopup("Type", this.buildTarget); this.productName = EditorGUILayout.TextField("Product Name", this.productName); this.bundleIdentifier = EditorGUILayout.TextField("Bundle Identifier", this.bundleIdentifier); this.version = EditorGUILayout.TextField("Version", this.version); this.buildOptions = (BuilderBuildOptions)EditorGUILayout.EnumMaskField("Options", this.buildOptions); bool dirty = EditorGUI.EndChangeCheck(); dirty |= this.PackagesGUI(); EditorGUILayout.Separator(); BuilderModule moduleToRemove = null; BuilderModule moduleUp = null; BuilderModule moduleDown = null; foreach (var m in this._modules) { var info = BuilderModule.GetModule(m.name); EditorGUILayout.BeginHorizontal(); if (info == null) { EditorGUILayout.LabelField(m.name != null ? "Missing module: " + m.name : "Missing module"); } else { m.isCollapsed = !EditorGUILayout.Foldout(!m.isCollapsed, info.description); } EditorGUI.BeginChangeCheck(); if (GUILayout.Button("Up", GUILayout.ExpandWidth(false))) { moduleUp = m; } if (GUILayout.Button("Down", GUILayout.ExpandWidth(false))) { moduleDown = m; } if (GUILayout.Button("Delete", GUILayout.ExpandWidth(false))) { moduleToRemove = m; } EditorGUILayout.EndHorizontal(); if (info != null && !m.isCollapsed) { EditorGUI.indentLevel++; m.OnGUI(); EditorGUI.indentLevel--; } dirty |= EditorGUI.EndChangeCheck(); } if (moduleToRemove != null) { this._modules.Remove(moduleToRemove); } if (moduleUp != null) { int i = this._modules.IndexOf(moduleUp); if (i > 0) { this._modules.RemoveAt(i); this._modules.Insert(i - 1, moduleUp); } } if (moduleDown != null) { int i = this._modules.IndexOf(moduleDown); if (i >= 0 && i < this._modules.Count - 1) { this._modules.RemoveAt(i); this._modules.Insert(i + 1, moduleDown); } } return(dirty); }
public void FromJson(JObject json) { this.option = null; this.buildPath = null; this.buildTarget = (BuildTarget)0; this.buildOptions = 0; if (json == null) { return; } JToken obj; if (json.TryGetValue("option", out obj)) { this.option = (string)obj; } if (json.TryGetValue("path", out obj)) { this.buildPath = (string)obj; } if (json.TryGetValue("buildTarget", out obj)) { try { this.buildTarget = (BuildTarget)System.Enum.Parse(typeof(BuildTarget), (string)obj, true); } catch { this.buildTarget = (BuildTarget)0; } } if (json.TryGetValue("productName", out obj)) { this.productName = (string)obj; } if (json.TryGetValue("bundleIdentifier", out obj)) { this.bundleIdentifier = (string)obj; } if (json.TryGetValue("version", out obj)) { this.version = (string)obj; } if (json.TryGetValue("buildOptions", out obj)) { var options = (JObject)obj; foreach (var p in options) { if ((bool)p.Value) { try { this.buildOptions |= (BuilderBuildOptions)System.Enum.Parse(typeof(BuilderBuildOptions), p.Key, true); } catch { } } } } this.packages.Clear(); if (json.TryGetValue("packages", out obj)) { foreach (var o in (JArray)obj) { if (o == null || o.Type != JTokenType.String) { continue; } string name = (string)o; if (string.IsNullOrEmpty(name)) { continue; } if (!this.packages.Contains(name)) { this.packages.Add(name); } } } this._modules.Clear(); if (json.TryGetValue("modules", out obj)) { foreach (JObject o in (JArray)obj) { string guid = (string)o["_guid"]; o.Remove("_guid"); string name = (string)o["_name"]; o.Remove("_name"); var info = BuilderModule.GetModule(guid ?? name); var module = (info != null) ? info.Instantiate() : new BuilderMissingModule(name); module.FromJson(o); this._modules.Add(module); } } }