private void OnGUI() { GUILayout.BeginVertical(); // 绘制作者信息 NIEditorUtility.DrawAuthorSummary(); GUILayout.Space(5); if (GUILayout.Button("刷新", GUILayout.MaxWidth(70))) { Refresh(); return; } GUILayout.Space(5); GUILayout.EndVertical(); GUILayout.BeginHorizontal(); GUILayout.BeginVertical(); GUI.backgroundColor = new Color32(150, 200, 255, 255); //未创建的在前,已创建的在后 dirList.Sort((string a, string b) => { string aPath = a.Replace("Z_RES/Atlas/", "Assets/Art/Atlas/"); string bPath = b.Replace("Z_RES/Atlas/", "Assets/Art/Atlas/"); bool ae = Directory.Exists(aPath); bool be = Directory.Exists(bPath); if (ae && !be) { return(1); } else if (!ae && be) { return(-1); } else { //GetFileNameWithoutExtension得到没有扩充名(.txt)的文件名 //按首字母排序 string aN = Path.GetFileNameWithoutExtension(a); string bN = Path.GetFileNameWithoutExtension(b); return(aN[0] - bN[0]); } }); //文件夹列表 scrollPos = GUILayout.BeginScrollView(scrollPos, "AS TextArea", GUILayout.Width(480), GUILayout.Height(600)); for (int i = 0; i < dirList.Count; i++) { string atlasName = Path.GetFileNameWithoutExtension(dirList[i]); GUILayout.BeginHorizontal(); GUILayout.Space(10f); string resPath = dirList[i].Replace("Z_RES/Atlas/", "Assets/Art/Atlas/"); string buttonTxt = ""; bool isNew = false; if (Directory.Exists(resPath)) { buttonTxt = "更新"; } else { buttonTxt = "创建"; isNew = true; } if (isNew) { GUI.color = Color.green; } //1.创建/更新按钮 if (GUILayout.Button(buttonTxt, GUILayout.Width(50), GUILayout.Height(20))) { MakeAtlas(atlasName); } if (isNew) { GUI.color = Color.white; } //2.文件夹名 GUILayout.Label(atlasName, EditorStyles.boldLabel); //3.配置文件按钮 if (!isNew) { if (GUILayout.Button("配置", GUILayout.Width(70f), GUILayout.Height(20))) { if (File.Exists(ATLAS_PREFAB_PATH + atlasName + "Atlas" + ".prefab")) { UIAtlas atlas = Resources.Load <UIAtlas>("Atlas/" + atlasName + "Atlas"); string textPath = ATLAS_PATH + atlasName + ".txt"; textPath = GetProjectRelativePath(textPath); TextAsset configuration = AssetDatabase.LoadAssetAtPath <TextAsset>(textPath); NGUIJson.LoadSpriteData(atlas, configuration); //装载图集配置文件 atlas.MarkAsChanged(); PrefabUtility.RecordPrefabInstancePropertyModifications(atlas); } } } GUILayout.EndHorizontal(); GUILayout.Space(10f); } GUILayout.EndScrollView(); GUI.backgroundColor = Color.white; GUILayout.Space(10f); GUILayout.EndVertical(); GUILayout.EndHorizontal(); }
private void OnGUI() { //头像 GUILayout.Space(10); NIEditorUtility.DrawAuthorSummary(); GUILayout.Space(10); //选择目标目录 GUILayout.Space(10); GUILayout.BeginHorizontal(); { GUILayout.Space(5); GUIStyle style = EditorStyles.textArea; style.fontStyle = FontStyle.Bold; style.alignment = TextAnchor.MiddleLeft; GUILayout.Label(FILE_ROOT_PATH, style, GUILayout.Height(25)); if (GUILayout.Button("SetPath", GUILayout.MaxWidth(65f))) { string tempPath = NIEditorUtility.BrowseFolder(); if (!string.IsNullOrEmpty(tempPath)) { FILE_ROOT_PATH = tempPath; Refresh(); } return; } if (GUILayout.Button("ResetPath", GUILayout.MaxWidth(75f))) { FILE_ROOT_PATH = Application.dataPath + "/../" + CONFIG_JSON_FOLER_NAME; Refresh(); return; } } GUILayout.EndHorizontal(); GUILayout.Space(10); //内容 GUI.backgroundColor = new Color32(150, 200, 255, 255); GUILayout.BeginVertical("AS TextArea", GUILayout.Height(500)); { GUILayout.BeginHorizontal(); GUILayout.Label("Config File Name", EditorStyles.toolbarButton); GUILayout.Label("Operation", EditorStyles.toolbarButton); GUILayout.EndHorizontal(); _scrollPos = GUILayout.BeginScrollView(_scrollPos, GUILayout.Height(470)); for (int i = 0; i < mFilesPathList.Count; i++) { string fileName = Path.GetFileNameWithoutExtension(mFilesPathList[i]); GUILayout.BeginHorizontal(); { GUIStyle style = EditorStyles.textArea; style.fontStyle = FontStyle.Bold; style.alignment = TextAnchor.MiddleLeft; GUILayout.Label(fileName, style, GUILayout.Height(25)); DrawCreateBtn(mFilesPathList[i], fileName); } GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); } GUILayout.EndVertical(); //刷新 GUILayout.Space(10f); GUILayout.BeginHorizontal(); { GUILayout.Space(10); if (GUILayout.Button("Refresh", GUILayout.MaxWidth(60f))) { Refresh(); return; } GUILayout.Space(2); GUILayout.Label("To refresh Config Files"); } GUILayout.EndHorizontal(); //创建全部 GUILayout.Space(10); GUILayout.BeginHorizontal(); { GUILayout.Space(10); if (GUILayout.Button("Create All", GUILayout.MaxWidth(80f))) { for (int i = 0; i < mFilesPathList.Count; i++) { string fileName = Path.GetFileNameWithoutExtension(mFilesPathList[i]); NIEditorUtility.CreateCsConfigFile(mFilesPathList[i], fileName, CONFIG_FOLDER_NAME); } return; } GUILayout.Space(2); GUILayout.Label("To Create All Config Files"); } GUILayout.EndHorizontal(); //生成到目标路径 GUILayout.BeginVertical(); { GUILayout.Space(10); GUILayout.Label("生成到目标路径:"); GUI.color = Color.white; GUIStyle style = EditorStyles.textArea; style.fontStyle = FontStyle.Bold; style.alignment = TextAnchor.MiddleLeft; GUILayout.Label(Application.dataPath + "/../" + CONFIG_FOLDER_NAME, style, GUILayout.Height(25)); } GUILayout.EndVertical(); }