使用visual studio创建一个控制台程序
代码语言:javascript复制using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Windows.Forms;
namespace ToUtf8
{
class Program
{
static void Main(string[] args)
{
var dir = Directory.GetCurrentDirectory();
var files = new DirectoryInfo(dir).GetFiles("*.*", SearchOption.AllDirectories).Where(s => s.FullName.EndsWith(".cs") || s.FullName.EndsWith(".txt") || s.FullName.EndsWith(".shader"));
foreach (var f in files)
{
var s = File.ReadAllText(f.FullName, Encoding.Default);
try
{
File.WriteAllText(f.FullName, s, Encoding.UTF8);
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
continue;
}
}
}
}
}
生成的exe放到unity中的一个文件夹下,双击运行,然后同文件夹下的脚本会转换为utf8