using System;
using System.IO;
using UnityEditor;
public class SpineFileRename
{
//场景文件夹信息容器
private static FileSystemInfo[] fileSystemInfos;
/// <summary>
/// 路径
/// </summary>
private static string _path;
/// <summary>
/// 重命名动画文件
/// </summary>
[MenuItem("Tools/SpineFileRename")]
private static void RenameSpineExtension()
{
string path = EditorUtility.OpenFolderPanel("RenameWindow",
Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "");
if (path == null||string.IsNullOrEmpty(path)) return;
RenameFileName(path);
}
private static void RenameFileName(string targetName)
{
//资源路径
_path = targetName;
//根据资源路径获取对应文件夹
DirectoryInfo directoryInfo = new DirectoryInfo(_path);
//获取对应文件夹下的子类
fileSystemInfos = directoryInfo.GetFileSystemInfos();
//遍历子类文件夹
foreach (FileSystemInfo tempDirectoryInfo in fileSystemInfos)
{
//安全判断
if (!tempDirectoryInfo.Exists)
{
EditorUtility.DisplayDialog("SpineFileRename", "路径文件夹下资源为空!", "确定");
return;
}
//遍历场景中的文件系统
TraFileSystemInfo(tempDirectoryInfo);
}
EditorUtility.DisplayDialog("SpineFileRename", "Spine动画重命名完成!", "确定");
}
/// <summary>
/// 遍历场景中的文件系统
/// </summary>
/// <param name="fileSystemInfo"></param>
private static void TraFileSystemInfo(FileSystemInfo fileSystemInfo)
{
//文件系统强转成目录信息
if (fileSystemInfo is DirectoryInfo directoryInfo)
{
FileSystemInfo[] childFileSystemInfos = directoryInfo.GetFileSystemInfos();
foreach (var tempFileSystemInfo in childFileSystemInfos)
{
//尝试强转成文件
FileInfo fileInfo = tempFileSystemInfo as FileInfo;
if (fileInfo == null)
{
//遍历到文件夹继续迭代
TraFileSystemInfo(tempFileSystemInfo);
}
else
{
//扩展名筛选
if (fileInfo.Extension == ".atlas")
{
string newFullName = fileInfo.FullName + ".txt";
fileInfo.MoveTo(newFullName);
}
if (fileInfo.Extension == ".skel")
{
string newFullName = fileInfo.FullName + ".bytes";
fileInfo.MoveTo(newFullName);
}
}
}
}
else
{
//尝试强转成文件
if (fileSystemInfo is FileInfo childFileInfo)
{
//扩展名筛选
if (childFileInfo.Extension == ".atlas")
{
string newFullName = childFileInfo.FullName + ".txt";
childFileInfo.MoveTo(newFullName);
}
if (childFileInfo.Extension == ".skel")
{
string newFullName = childFileInfo.FullName + ".bytes";
childFileInfo.MoveTo(newFullName);
}
}
}
}
}
Unity编辑器工具-批量给spine文件重命名
最新推荐文章于 2024-06-17 19:50:40 发布