public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(position, label, property); // Limit valid characters. // TODO: This might not be necessary since name will need to be sanitized for different needs later (as an enum entry, pre-processor define, etc.) //char chr = Event.current.character; //if ((chr < 'a' || chr > 'z') && (chr < 'A' || chr > 'Z') && (chr < '0' || chr > '9') && chr != '-' && chr != '_' && chr != ' ') //{ // Event.current.character = '\0'; //} bool show = property.isExpanded; UnityBuildGUIUtility.DropdownHeader(property.FindPropertyRelative("typeName").stringValue, ref show, false); property.isExpanded = show; if (show) { EditorGUILayout.BeginVertical(UnityBuildGUIUtility.dropdownContentStyle); GUILayout.Label("Basic Info", UnityBuildGUIUtility.midHeaderStyle); SerializedProperty typeName = property.FindPropertyRelative("typeName"); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Type Name"); typeName.stringValue = BuildProject.SanitizeFolderName(GUILayout.TextArea(typeName.stringValue)); EditorGUILayout.EndHorizontal(); EditorGUILayout.PropertyField(property.FindPropertyRelative("bundleIdentifier")); EditorGUILayout.PropertyField(property.FindPropertyRelative("productName")); EditorGUILayout.PropertyField(property.FindPropertyRelative("companyName")); GUILayout.Space(20); GUILayout.Label("Build Options", UnityBuildGUIUtility.midHeaderStyle); EditorGUILayout.PropertyField(property.FindPropertyRelative("customDefines")); SerializedProperty buildOptions = property.FindPropertyRelative("buildOptions"); bool enableHeadlessMode = ((BuildOptions)buildOptions.intValue & BuildOptions.EnableHeadlessMode) == BuildOptions.EnableHeadlessMode; bool developmentBuild = ((BuildOptions)buildOptions.intValue & BuildOptions.Development) == BuildOptions.Development; bool allowDebugging = ((BuildOptions)buildOptions.intValue & BuildOptions.AllowDebugging) == BuildOptions.AllowDebugging; enableHeadlessMode = EditorGUILayout.ToggleLeft(" Server Build", enableHeadlessMode); if (enableHeadlessMode) { buildOptions.intValue |= (int)BuildOptions.EnableHeadlessMode; } else { buildOptions.intValue &= ~(int)BuildOptions.EnableHeadlessMode; } developmentBuild = EditorGUILayout.ToggleLeft(" Development Build", developmentBuild); if (developmentBuild) { buildOptions.intValue |= (int)BuildOptions.Development; } else { buildOptions.intValue &= ~(int)BuildOptions.Development; } EditorGUI.BeginDisabledGroup(!developmentBuild); allowDebugging = EditorGUILayout.ToggleLeft(" Script Debugging", allowDebugging); EditorGUI.EndDisabledGroup(); if (allowDebugging) { buildOptions.intValue |= (int)BuildOptions.AllowDebugging; } else { buildOptions.intValue &= ~(int)BuildOptions.AllowDebugging; } GUILayout.Space(15); buildOptions.intValue = (int)(BuildOptions)EditorGUILayout.EnumFlagsField("Advanced Options", (BuildOptions)buildOptions.intValue); EditorGUILayout.PropertyField(property.FindPropertyRelative("sceneList")); if (GUILayout.Button("Delete", GUILayout.ExpandWidth(true))) { BuildReleaseType[] types = BuildSettings.releaseTypeList.releaseTypes; for (int i = 0; i < types.Length; i++) { if (types[i].typeName == property.FindPropertyRelative("typeName").stringValue) { ArrayUtility.RemoveAt <BuildReleaseType>(ref BuildSettings.releaseTypeList.releaseTypes, i); GUIUtility.keyboardControl = 0; break; } } } property.serializedObject.ApplyModifiedProperties(); EditorGUILayout.EndVertical(); } EditorGUI.EndProperty(); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(position, GUIContent.none, property); bool show = property.isExpanded; UnityBuildGUIUtility.DropdownHeader(property.FindPropertyRelative("platformName").stringValue, ref show, false); property.isExpanded = show; if (show) { EditorGUILayout.BeginVertical(UnityBuildGUIUtility.dropdownContentStyle); SerializedProperty archList = property.FindPropertyRelative("architectures"); if (archList.arraySize > 1) { GUILayout.Label("Architectures", UnityBuildGUIUtility.midHeaderStyle); for (int i = 0; i < archList.arraySize; i++) { SerializedProperty archProperty = archList.GetArrayElementAtIndex(i); SerializedProperty archName = archProperty.FindPropertyRelative("name"); SerializedProperty archEnabled = archProperty.FindPropertyRelative("enabled"); archEnabled.boolValue = GUILayout.Toggle(archEnabled.boolValue, archName.stringValue); archProperty.serializedObject.ApplyModifiedProperties(); } } SerializedProperty variantList = property.FindPropertyRelative("variants"); if (variantList.arraySize > 0) { GUILayout.Label("Variant Options", UnityBuildGUIUtility.midHeaderStyle); for (int i = 0; i < variantList.arraySize; i++) { SerializedProperty variantProperty = variantList.GetArrayElementAtIndex(i); SerializedProperty variantName = variantProperty.FindPropertyRelative("variantName"); SerializedProperty variantValues = variantProperty.FindPropertyRelative("values"); SerializedProperty selectedVariantIndex = variantProperty.FindPropertyRelative("selectedIndex"); List <string> valueNames = new List <string>(variantValues.arraySize); for (int j = 0; j < variantValues.arraySize; j++) { valueNames.Add(variantValues.GetArrayElementAtIndex(j).stringValue); } GUILayout.BeginHorizontal(); EditorGUILayout.LabelField(variantName.stringValue); selectedVariantIndex.intValue = EditorGUILayout.Popup(selectedVariantIndex.intValue, valueNames.ToArray(), UnityBuildGUIUtility.popupStyle, GUILayout.ExpandWidth(false), GUILayout.MaxWidth(250)); GUILayout.EndHorizontal(); } } SerializedProperty distList = property.FindPropertyRelative("distributionList.distributions"); if (distList.arraySize > 0) { GUILayout.Label("Distributions", UnityBuildGUIUtility.midHeaderStyle); for (int i = 0; i < distList.arraySize; i++) { SerializedProperty dist = distList.GetArrayElementAtIndex(i); SerializedProperty distEnabled = dist.FindPropertyRelative("enabled"); SerializedProperty distName = dist.FindPropertyRelative("distributionName"); GUILayout.BeginHorizontal(); distEnabled.boolValue = GUILayout.Toggle(distEnabled.boolValue, GUIContent.none, GUILayout.ExpandWidth(false)); distName.stringValue = BuildProject.SanitizeFolderName(GUILayout.TextField(distName.stringValue)); if (GUILayout.Button("X", UnityBuildGUIUtility.helpButtonStyle)) { distList.DeleteArrayElementAtIndex(i); } dist.serializedObject.ApplyModifiedProperties(); GUILayout.EndHorizontal(); } } GUILayout.Space(10); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.BeginVertical(); if (GUILayout.Button("Add Distribution", GUILayout.MaxWidth(150))) { int addedIndex = distList.arraySize; distList.InsertArrayElementAtIndex(addedIndex); SerializedProperty addedProperty = distList.GetArrayElementAtIndex(addedIndex); addedProperty.FindPropertyRelative("enabled").boolValue = true; addedProperty.FindPropertyRelative("distributionName").stringValue = "DistributionName"; addedProperty.serializedObject.ApplyModifiedProperties(); distList.serializedObject.ApplyModifiedProperties(); property.serializedObject.ApplyModifiedProperties(); GUIUtility.keyboardControl = 0; } if (GUILayout.Button("Delete Platform", GUILayout.MaxWidth(150))) { property.FindPropertyRelative("enabled").boolValue = false; } GUILayout.EndVertical(); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); } property.serializedObject.ApplyModifiedProperties(); EditorGUI.EndProperty(); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(position, label, property); EditorGUILayout.BeginHorizontal(); bool show = property.isExpanded; UnityBuildGUIUtility.DropdownHeader("Scene List", ref show, false, GUILayout.ExpandWidth(true)); property.isExpanded = show; EditorGUILayout.EndHorizontal(); // Refresh all scene lists. for (int i = 0; i < BuildSettings.releaseTypeList.releaseTypes.Length; i++) { BuildReleaseType rt = BuildSettings.releaseTypeList.releaseTypes[i]; rt.sceneList.Refresh(); } list = property.FindPropertyRelative("enabledScenes"); if (show) { EditorGUILayout.BeginVertical(UnityBuildGUIUtility.dropdownContentStyle); SerializedProperty platformProperty; string fileGUID; string filePath; string sceneName = "N/A"; if (list.arraySize > 0) { platformProperty = list.GetArrayElementAtIndex(0); fileGUID = platformProperty.FindPropertyRelative("fileGUID").stringValue; filePath = AssetDatabase.GUIDToAssetPath(fileGUID); sceneName = Path.GetFileNameWithoutExtension(filePath); } EditorGUILayout.BeginHorizontal(); show = list.isExpanded; UnityBuildGUIUtility.DropdownHeader(string.Format("Scenes ({0}) (First Scene: {1})", list.arraySize, sceneName), ref show, false, GUILayout.ExpandWidth(true)); list.isExpanded = show; EditorGUILayout.EndHorizontal(); if (show) { for (int i = 0; i < list.arraySize; i++) { platformProperty = list.GetArrayElementAtIndex(i); fileGUID = platformProperty.FindPropertyRelative("fileGUID").stringValue; filePath = AssetDatabase.GUIDToAssetPath(fileGUID); sceneName = Path.GetFileNameWithoutExtension(filePath); EditorGUILayout.BeginHorizontal(); EditorGUILayout.TextArea(sceneName + " (" + filePath + ")"); EditorGUI.BeginDisabledGroup(i == 0); if (GUILayout.Button("↑↑", UnityBuildGUIUtility.helpButtonStyle)) { list.MoveArrayElement(i, 0); } if (GUILayout.Button("↑", UnityBuildGUIUtility.helpButtonStyle)) { list.MoveArrayElement(i, i - 1); } EditorGUI.EndDisabledGroup(); EditorGUI.BeginDisabledGroup(i == list.arraySize - 1); if (GUILayout.Button("↓", UnityBuildGUIUtility.helpButtonStyle)) { list.MoveArrayElement(i, i + 1); } EditorGUI.EndDisabledGroup(); if (GUILayout.Button("X", UnityBuildGUIUtility.helpButtonStyle)) { list.DeleteArrayElementAtIndex(i); } property.serializedObject.ApplyModifiedProperties(); EditorGUILayout.EndHorizontal(); } } GUILayout.Space(20); Rect dropArea = GUILayoutUtility.GetRect(0, 50.0f, GUILayout.ExpandWidth(true)); GUI.Box(dropArea, "Drag and Drop scene files here to add to list.", UnityBuildGUIUtility.dragDropStyle); Event currentEvent = Event.current; switch (currentEvent.type) { case EventType.DragUpdated: case EventType.DragPerform: if (dropArea.Contains(currentEvent.mousePosition)) { DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if (currentEvent.type == EventType.DragPerform) { DragAndDrop.AcceptDrag(); foreach (Object obj in DragAndDrop.objectReferences) { if (obj.GetType() == typeof(SceneAsset)) { string objFilepath = AssetDatabase.GetAssetPath(obj); string objGUID = AssetDatabase.AssetPathToGUID(objFilepath); AddScene(objGUID); } } if (list.arraySize >= AUTO_COLLAPSE_SIZE) { list.isExpanded = false; } } } break; } if (GUILayout.Button("Clear Scene List", GUILayout.ExpandWidth(true))) { list.ClearArray(); } if (GUILayout.Button("Add Scene Files from Build Settings", GUILayout.ExpandWidth(true))) { GetSceneFilesFromBuildSettings(); } if (GUILayout.Button("Add Scene File Directory", GUILayout.ExpandWidth(true))) { GetSceneFileDirectory("Add Scene Files"); } if (GUILayout.Button("Set First Scene by File", GUILayout.ExpandWidth(true))) { SetFirstSceneByFile(); } list.serializedObject.ApplyModifiedProperties(); property.serializedObject.ApplyModifiedProperties(); EditorGUILayout.EndVertical(); } EditorGUI.EndProperty(); }
private void DrawWarnings() { int warningCount = 0; int clearableCount = 0; for (int i = 0; i < BuildNotificationList.instance.warnings.Count; i++) { BuildNotification notification = BuildNotificationList.instance.warnings[i]; if (notification.valid == null || notification.valid()) { ++warningCount; } if (notification.clearable) { ++clearableCount; } } if (warningCount == 0) { return; } Color defaultBackgroundColor = GUI.backgroundColor; EditorGUILayout.BeginHorizontal(); GUI.backgroundColor = Color.yellow; UnityBuildGUIUtility.DropdownHeader( "Warnings (" + warningCount + ")", ref show, true, GUILayout.ExpandWidth(true)); if (clearableCount > 0) { if (GUILayout.Button(clearButtonContent, UnityBuildGUIUtility.helpButtonStyle)) { BuildNotificationList.instance.RefreshWarnings(); } } GUI.backgroundColor = defaultBackgroundColor; EditorGUILayout.EndHorizontal(); if (show) { EditorGUILayout.BeginVertical(UnityBuildGUIUtility.dropdownContentStyle); for (int i = 0; i < BuildNotificationList.instance.warnings.Count; i++) { BuildNotification notification = BuildNotificationList.instance.warnings[i]; if (notification.valid == null || notification.valid()) { EditorGUILayout.HelpBox(notification.title + "\n" + notification.details, MessageType.Warning); } } EditorGUILayout.EndVertical(); } GUILayout.Space(15); }
protected static string[] EnumNamesToArray <T>(bool toWords = false) { return(Enum.GetNames(typeof(T)) .Select(item => toWords ? UnityBuildGUIUtility.ToWords(item) : item) .ToArray()); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { showViewOptions = property.FindPropertyRelative("showViewOptions"); showConfigs = property.FindPropertyRelative("showConfigs"); showBuildInfo = property.FindPropertyRelative("showBuildInfo"); hideDisabled = property.FindPropertyRelative("hideDisabled"); treeView = property.FindPropertyRelative("treeView"); selectedKeyChain = property.FindPropertyRelative("selectedKeyChain"); EditorGUI.BeginProperty(position, label, property); EditorGUILayout.BeginHorizontal(); show = property.isExpanded; UnityBuildGUIUtility.DropdownHeader("Build Configurations", ref show, false, GUILayout.ExpandWidth(true)); property.isExpanded = show; UnityBuildGUIUtility.HelpButton("Parameter-Details#build-configurations"); EditorGUILayout.EndHorizontal(); Color defaultBackgroundColor = GUI.backgroundColor; if (show) { EditorGUILayout.BeginVertical(UnityBuildGUIUtility.dropdownContentStyle); EditorGUILayout.BeginHorizontal(); show = showViewOptions.isExpanded; UnityBuildGUIUtility.DropdownHeader("View Options", ref show, false, GUILayout.ExpandWidth(true)); showViewOptions.isExpanded = show; EditorGUILayout.EndHorizontal(); if (show) { EditorGUILayout.BeginVertical(UnityBuildGUIUtility.dropdownContentStyle); hideDisabled.boolValue = EditorGUILayout.ToggleLeft("Hide disabled configurations", hideDisabled.boolValue); treeView.boolValue = EditorGUILayout.ToggleLeft("Show full configurations tree", treeView.boolValue); EditorGUILayout.EndVertical(); } GUILayout.Space(5); EditorGUILayout.BeginHorizontal(); show = showConfigs.isExpanded; UnityBuildGUIUtility.DropdownHeader("Configurations", ref show, false, GUILayout.ExpandWidth(true)); showConfigs.isExpanded = show; EditorGUILayout.EndHorizontal(); if (show) { EditorGUILayout.BeginVertical(UnityBuildGUIUtility.dropdownContentStyle); if (BuildSettings.projectConfigurations.configSet.Keys.Count > 0) { BuildReleaseType[] releaseTypes = BuildSettings.releaseTypeList.releaseTypes; for (int i = 0; i < releaseTypes.Length; i++) { string key = releaseTypes[i].typeName; Configuration config = BuildSettings.projectConfigurations.configSet[key]; DisplayConfigTree(key, config, 0); } } else { EditorGUILayout.HelpBox("No Configuration info. Please add a Release Type.", MessageType.Error); } EditorGUILayout.EndVertical(); } GUILayout.Space(5); EditorGUILayout.BeginHorizontal(); show = showBuildInfo.isExpanded; UnityBuildGUIUtility.DropdownHeader("Build Info", ref show, false, GUILayout.ExpandWidth(true)); showBuildInfo.isExpanded = show; EditorGUILayout.EndHorizontal(); if (show) { EditorGUILayout.BeginVertical(UnityBuildGUIUtility.dropdownContentStyle); if (string.IsNullOrEmpty(selectedKeyChain.stringValue)) { EditorGUILayout.HelpBox("Click a build configuration above in \"Configurations\" to view full details.", MessageType.Info); } else { BuildReleaseType releaseType; BuildPlatform platform; BuildArchitecture arch; BuildDistribution dist; BuildOptions buildOptions = BuildOptions.None; bool parseSuccess = BuildSettings.projectConfigurations.ParseKeychain(selectedKeyChain.stringValue, out releaseType, out platform, out arch, out dist); if (parseSuccess) { string defines = BuildProject.GenerateDefaultDefines(releaseType, platform, arch, dist); EditorGUILayout.LabelField("Misc Info", UnityBuildGUIUtility.midHeaderStyle); EditorGUILayout.LabelField("Defines:"); EditorGUILayout.LabelField(defines, EditorStyles.wordWrappedLabel); if (releaseType != null) { buildOptions = releaseType.buildOptions; EditorGUILayout.LabelField("Release Type", UnityBuildGUIUtility.midHeaderStyle); EditorGUILayout.LabelField("Type Name:\t" + releaseType.typeName); if (!string.IsNullOrEmpty(releaseType.bundleIdentifier)) { EditorGUILayout.LabelField("Bundle Identifier:\t" + releaseType.bundleIdentifier); } EditorGUILayout.LabelField("Product Name:\t" + releaseType.productName); } if (platform != null) { EditorGUILayout.LabelField("Platform", UnityBuildGUIUtility.midHeaderStyle); EditorGUILayout.LabelField("Name:\t\t" + platform.platformName); } if (arch != null) { EditorGUILayout.LabelField("Architecture", UnityBuildGUIUtility.midHeaderStyle); EditorGUILayout.LabelField("Name:\t\t" + arch.name); } if (dist != null) { EditorGUILayout.LabelField("Distribution", UnityBuildGUIUtility.midHeaderStyle); EditorGUILayout.LabelField("Name:\t\t" + dist.distributionName); } GUILayout.Space(20); GUI.backgroundColor = Color.green; if (GUILayout.Button("Build", GUILayout.ExpandWidth(true))) { EditorApplication.delayCall += () => BuildProject.BuildSingle(selectedKeyChain.stringValue, buildOptions); } if (GUILayout.Button("Build and Run", GUILayout.ExpandWidth(true))) { buildOptions |= BuildOptions.AutoRunPlayer; BuildOptions finalBuildOptions = buildOptions; EditorApplication.delayCall += () => BuildProject.BuildSingle(selectedKeyChain.stringValue, finalBuildOptions); } EditorGUI.BeginDisabledGroup((buildOptions & BuildOptions.Development) != BuildOptions.Development); if (GUILayout.Button("Build and Run with Profiler", GUILayout.ExpandWidth(true))) { buildOptions |= BuildOptions.AutoRunPlayer; buildOptions |= BuildOptions.ConnectWithProfiler; BuildOptions finalBuildOptions = buildOptions; EditorApplication.delayCall += () => BuildProject.BuildSingle(selectedKeyChain.stringValue, finalBuildOptions); } EditorGUI.EndDisabledGroup(); GUI.backgroundColor = defaultBackgroundColor; if (GUILayout.Button(new GUIContent("Configure Editor Environment", "Switches platform, refreshes BuildConstants, applies scripting defines and variant settings and sets Build Settings scene list to match the selected build configuration"), GUILayout.ExpandWidth(true))) { // Update Editor environment settings to match selected build configuration BuildProject.ConfigureEditor(selectedKeyChain.stringValue, buildOptions); // Apply scene list BuildProject.SetEditorBuildSettingsScenes(releaseType); } } else { EditorGUILayout.HelpBox("Could not parse selected configuration. It may no longer be valid due to a change. Select again.", MessageType.Info); } } EditorGUILayout.EndVertical(); } property.serializedObject.ApplyModifiedProperties(); EditorGUILayout.EndVertical(); } EditorGUI.EndProperty(); }