private void OnGUI() { verticalScrollPosition = GUILayout.BeginScrollView(verticalScrollPosition, false, false, GUIStyle.none, GUI.skin.verticalScrollbar); GUILayout.BeginHorizontal(); EditorGUILayout.Space(); GUILayout.BeginVertical(); EditorGUILayout.Space(); EditorGUILayout.HelpBox("一键快速导出可以按一定流程快速地执行多个导出任务。", MessageType.Info); // 全局配置 EditorGUILayout.Space(); { EditorGUILayout.BeginHorizontal(); GUIStyle sceneStyle = new GUIStyle(EditorStyles.foldout); sceneStyle.fixedWidth = 10; expandGlobalConfig = EditorGUILayout.Foldout(expandGlobalConfig, "==== 全局配置", true, sceneStyle); GUILayout.Label("", GUILayout.ExpandWidth(true)); EditorGUILayout.EndHorizontal(); if (expandGlobalConfig) { EditorGUI.indentLevel++; globalConfigEditor.OnInspectorGUI(); EditorGUI.indentLevel--; } } // 插件 EditorGUILayout.Space(); int PluginCodeFold = EditorHelper.FoldableTitleline("导出插件代码", expandPluginCodeConfig, checkPluginCodeConfig); expandPluginCodeConfig = (PluginCodeFold & 0x10) == 0x10; checkPluginCodeConfig = (PluginCodeFold & 0x1) == 0x1; if (expandPluginCodeConfig) { EditorGUI.indentLevel++; unityPluginConfigEditor.OnInspectorGUI(); EditorGUI.indentLevel--; } // 工程 EditorGUILayout.Space(); int PluginProjectFold = EditorHelper.FoldableTitleline("导出工程代码", expandProjectCodeConfig, checkProjectCodeConfig); expandProjectCodeConfig = (PluginProjectFold & 0x10) == 0x10; checkProjectCodeConfig = (PluginProjectFold & 0x1) == 0x1; if (expandProjectCodeConfig) { EditorGUI.indentLevel++; // globalConfigEditor.OnInspectorGUI(); projectScriptExportConfigEditor.OnInspectorGUI(); EditorGUI.indentLevel--; } // 场景 EditorGUILayout.Space(); int sceneFold = EditorHelper.FoldableTitleline("导出所有场景", expandSceneConfig, checkSceneConfig); expandSceneConfig = (sceneFold & 0x10) == 0x10; checkSceneConfig = (sceneFold & 0x1) == 0x1; if (expandSceneConfig) { EditorGUI.indentLevel++; hierarchyExportConfigEditor.OnInspectorGUI(); sceneExportEditor.OnInspectorGUI(); EditorGUI.indentLevel--; } // prefab EditorGUILayout.Space(); int prefabFold = EditorHelper.FoldableTitleline("导出目录下的 prefab", expandPrefabConfig, checkPrefabConfig); expandPrefabConfig = (prefabFold & 0x10) == 0x10; checkPrefabConfig = (prefabFold & 0x1) == 0x1; if (expandPrefabConfig) { EditorGUI.indentLevel++; directoryExportEditor.OnInspectorGUI(); EditorGUI.indentLevel--; } // 原始资源 EditorGUILayout.Space(); int rawFold = EditorHelper.FoldableTitleline("导出原始资源", expandRawResourceConfig, checkRawResourceConfig); expandRawResourceConfig = (rawFold & 0x10) == 0x10; checkRawResourceConfig = (rawFold & 0x1) == 0x1; if (expandRawResourceConfig) { EditorGUI.indentLevel++; rawResourceExportConfigEditor.OnInspectorGUI(); EditorGUI.indentLevel--; } EditorGUILayout.Space(); EditorGUILayout.Space(); GUIStyle exportButtonStyle = new GUIStyle(GUI.skin.button); exportButtonStyle.fontSize = 14; var isExportBtnPressed = GUILayout.Button("导出", exportButtonStyle, GUILayout.Height(40), GUILayout.Width(EditorGUIUtility.currentViewWidth - 20)); GUILayout.EndVertical(); EditorGUILayout.Space(); GUILayout.EndHorizontal(); EditorGUILayout.Space(); GUILayout.EndScrollView(); if (isExportBtnPressed) { if (checkPluginCodeConfig) { Debug.Log("导出插件代码..."); ExportPreset.GetExportPreset("plugins-script").Export(); } if (checkProjectCodeConfig) { Debug.Log("导出工程代码..."); ExportPreset.GetExportPreset("project-script").Export(); } if (checkSceneConfig) { Debug.Log("导出全部游戏场景..."); ExportAllScenes(); } if (checkPrefabConfig) { Debug.Log("导出资源文件夹..."); ExportAllResourcesDirectories(); } if (checkRawResourceConfig) { Debug.Log("导出裸资源文件..."); ExportPreset.GetExportPreset("rawres").Export(); } } }
private void OnGUI() { verticalScrollPosition = GUILayout.BeginScrollView(verticalScrollPosition, false, false, GUIStyle.none, GUI.skin.verticalScrollbar); GUILayout.BeginHorizontal(); EditorGUILayout.Space(); GUILayout.BeginVertical(); EditorGUILayout.Space(); bool createProjectButtonClicked = false; bool choosePathButtonClicked = false; bool openTargetButtonClicked = false; bool resetButtonClicked = false; bool exportButtonClicked = false; // 带文本的分割线 EditorHelper.LabeledSplitLine("1. 目标导出路径"); // 路径选择 start int pathButtonHeight = 28; GUIStyle pathLabelStyle = new GUIStyle(GUI.skin.textField); pathLabelStyle.fontSize = 12; pathLabelStyle.alignment = TextAnchor.MiddleLeft; pathLabelStyle.margin.top = 6; pathLabelStyle.margin.bottom = 6; // 如果没有设置过path,显示创建按钮 if (ExportStore.storagePath == null || ExportStore.storagePath == "") { GUILayout.BeginHorizontal(); #if UNITY_2017_1_OR_NEWER createProjectButtonClicked = GUILayout.Button("创建小游戏项目模板", GUILayout.Height(pathButtonHeight)); #endif choosePathButtonClicked = GUILayout.Button("手动选择导出路径", GUILayout.Height(pathButtonHeight)); GUILayout.EndHorizontal(); } else { GUILayout.BeginHorizontal(); // 路径框 GUILayout.Label(ExportStore.storagePath, pathLabelStyle, GUILayout.Height(pathButtonHeight - 6), GUILayout.ExpandWidth(true), GUILayout.MaxWidth(EditorGUIUtility.currentViewWidth - 106)); openTargetButtonClicked = GUILayout.Button("打开", GUILayout.Height(pathButtonHeight), GUILayout.Width(40)); resetButtonClicked = GUILayout.Button("重选", GUILayout.Height(pathButtonHeight), GUILayout.Width(40)); GUILayout.EndHorizontal(); // 路径选择 end // 带文本的分割线 EditorHelper.LabeledSplitLine("2. 导出模式"); // 模式选择 start // 确定本次导出所使用的preset List <string> presetNames = new List <string>(); List <ExportPreset> exportPresets = new List <ExportPreset>(); foreach (string key in ExportPreset.GetAllPresetKeys()) { ExportPreset preset = ExportPreset.GetExportPreset(key); if (preset.WillPresetShow()) { presetNames.Add(preset.GetChineseName()); exportPresets.Add(preset); } } // 绘制 exportModeScrollPosition = GUILayout.BeginScrollView(exportModeScrollPosition, false, false, GUILayout.Height(45)); selectingPresetIndex = GUILayout.Toolbar( selectingPresetIndex, presetNames.ToArray(), new GUIStyle(GUI.skin.button), #if UNITY_2018_1_OR_NEWER GUI.ToolbarButtonSize.Fixed, #endif GUILayout.Height(22) ); GUILayout.EndScrollView(); selectingPresetIndex = Math.Min(selectingPresetIndex, exportPresets.Count - 1); EditorGUILayout.Space(); // 模式选择 end // 模式配置 start exportPresets[selectingPresetIndex].Draw(); // 模式配置 end // 导出按钮 start // 带文本的分割线 EditorGUILayout.Space(); EditorGUILayout.Space(); EditorHelper.LabeledSplitLine("3. 最后一步"); // 样式定义 GUIStyle exportButtonStyle = new GUIStyle(GUI.skin.button); exportButtonStyle.fontSize = 14; exportButtonClicked = GUILayout.Button("导出", exportButtonStyle, GUILayout.Height(40), GUILayout.Width(EditorGUIUtility.currentViewWidth - 20)); // 导出按钮 end currentPreset = exportPresets[selectingPresetIndex]; } GUILayout.EndVertical(); EditorGUILayout.Space(); GUILayout.EndHorizontal(); EditorGUILayout.Space(); GUILayout.EndScrollView(); handleClickedOnGUI( createProjectButtonClicked, choosePathButtonClicked, openTargetButtonClicked, resetButtonClicked, exportButtonClicked ); }