Unity3d Chinese garbled Solution method--cs code file format Batch Conversion UTF8

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.