In Unity3d often encounter the problem of Chinese garbled, such as the Code of [Addcomponentmenu ("gamedef/ai/fighter AI"), comments, Chinese text and so on
The reason is that unity itself is regardless of the region, so the default is all Unicode encoding, resulting in Chinese garbled
There are many solutions, for example,
- A file is converted to UTF8 format using a text tool
- Modify the Unity3d file template
The first method, when the number of times feasible, the number of times is more time-consuming and repetitive
The second approach works well in the early stages of the project, but it's useless if you haven't done it before, and once you upgrade the Unity version or use a different version, you'll need to re-modify the template
So to sum up, you can deal with this:
- Modify the template as early as possible (no modification is OK)
- Try not to create scripts in unity (it is convenient to generate class files automatically using the Resharpe tool and inherit the encoding)
- If you need to convert the encoding, we recommend using the Bulk encoding conversion tool
Bulk Encoding conversion Tool code
Create a console program using Visual Studio
The code is as follows
Using System;
Using System.IO;
Using System.Text;
Namespace ToUTF8
{
Class Program
{
static void Main (string[] args)
{
var dir = directory.getcurrentdirectory ();
foreach (Var f in new DirectoryInfo (dir). GetFiles ("*.cs", Searchoption.alldirectories))
{
var s = file.readalltext (F.fullname, Encoding.default);
Try
{
File.writealltext (F.fullname, S, Encoding.UTF8);
}
catch (Exception)
{
Continue
}
}
}
}
}
Compile the generated EXE file in a unity project, double-click to run, and wait to run
Unity3d Chinese garbled Solution method--cs code file format Batch Conversion UTF8