133 lines
3.5 KiB
C#
133 lines
3.5 KiB
C#
using System;
|
|
using System.IO;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
using System.Collections.Generic;
|
|
|
|
namespace BFEditor
|
|
{
|
|
public class ToggleCaseWindow : EditorWindow
|
|
{
|
|
private string folderPath = "";
|
|
|
|
//需要忽略的文件后缀
|
|
private Dictionary<string, bool> ignoreResSuffix = new Dictionary<string, bool>() {
|
|
{ ".meta", true },
|
|
{ ".ds_store", true },
|
|
};
|
|
|
|
public ToggleCaseWindow()
|
|
{
|
|
this.titleContent = new GUIContent("大小写转换");
|
|
}
|
|
|
|
void Awake()
|
|
{
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
}
|
|
|
|
private void OnGUI()
|
|
{
|
|
#region 设置Excel路径
|
|
GUILayout.Space(18);
|
|
GUILayout.BeginHorizontal();
|
|
GUILayout.Label("需要转换的文件夹路径");
|
|
GUILayout.TextField(folderPath, GUILayout.Width(280));
|
|
if (GUILayout.Button("选择", GUILayout.Width(80)))
|
|
{
|
|
string openPath = EditorUtility.OpenFolderPanel("select excel path", "", "");
|
|
if (openPath.CompareTo("") != 0){
|
|
folderPath = openPath.Replace("\\", "/");
|
|
}
|
|
}
|
|
GUILayout.EndHorizontal();
|
|
GUILayout.Space(10);
|
|
#endregion
|
|
|
|
#region 导出lua
|
|
GUILayout.BeginHorizontal();
|
|
GUILayout.Space(150);
|
|
if (GUILayout.Button("一键转小写", GUILayout.Width(200), GUILayout.Height(40)))
|
|
{
|
|
bool succ = OnClickExport();
|
|
if (succ)
|
|
{
|
|
Close();
|
|
EditorUtility.DisplayDialog("成功", "转换成功!", "ok");
|
|
}
|
|
else
|
|
{
|
|
Close();
|
|
EditorUtility.DisplayDialog("失败", "转换失败!", "ok");
|
|
}
|
|
}
|
|
GUILayout.EndHorizontal();
|
|
GUILayout.Space(30);
|
|
#endregion
|
|
}
|
|
|
|
private bool CheckIgnoreOrHidden(FileInfo fi)
|
|
{
|
|
|
|
if (((fi.Attributes & FileAttributes.Hidden) > 0) || ((fi.Attributes & FileAttributes.System) > 0))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
if (ignoreResSuffix.ContainsKey(fi.Extension.ToLower()))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
private bool OnClickExport()
|
|
{
|
|
if (string.IsNullOrEmpty(folderPath) || !Directory.Exists(folderPath))
|
|
{
|
|
EditorUtility.DisplayDialog("错误", "路径不存在,请先设置正确路径", "ok");
|
|
return false;
|
|
}
|
|
var outFolderPath = folderPath + "_out";
|
|
if (!Directory.Exists(outFolderPath))
|
|
{
|
|
Directory.CreateDirectory(outFolderPath);
|
|
}
|
|
|
|
var dirInfo = new DirectoryInfo(folderPath);
|
|
var dirs = dirInfo.GetDirectories();
|
|
foreach (var subDirInfo in dirs)
|
|
{
|
|
var subDirPath = subDirInfo.FullName.Replace("\\", "/");;
|
|
var outSubDirPath = subDirPath.Replace(folderPath, outFolderPath);
|
|
if (!Directory.Exists(outSubDirPath))
|
|
{
|
|
Directory.CreateDirectory(outSubDirPath);
|
|
}
|
|
}
|
|
|
|
var files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories);
|
|
var assetFiles = new List<string>();
|
|
|
|
for (var i = 0; i < files.Length; ++i)
|
|
{
|
|
var fileInfo = files[i];
|
|
|
|
if (CheckIgnoreOrHidden(fileInfo))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var relativePath = fileInfo.FullName.Substring(folderPath.Length + 1).ToLower();
|
|
var outFilePath = Path.Combine(outFolderPath, relativePath);
|
|
File.Copy(fileInfo.FullName, outFilePath, true);
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
}
|