[Unity] script Chinese garbled characters in Inspector


problem causes

When using Unity, when you click the C# script in the Unity editor to preview, the Chinese in the script may appear garbled. If you are editing with VS, this is because the default encoding of VS saved scripts is GB2312, and Unity By default, UTF-8 is used for decoding, so garbled characters will appear, as shown in the figure below:
insert image description here

In this case, we can use the EditorConfig plug-in to deal with it uniformly, and this plug-in can also help us standardize the code and make it easier for the team to manage the code format.

Install EditorConfig

Search for EditorConfig in the editor extension store, click to download, and restart VS after success.
insert image description here

Configure Editor Config

To use EditorConfig, you need to create a configuration file in the project. We can right-click on the Assets directory and add an .editorconfig File.
insert image description here

VS will automatically generate some default configurations, we can delete all these configurations, and then paste the configurations we need:

[*]

# 将缩进方式设置为4个空格
indent_style = space
indent_size = 4

# 文件编码格式 UTF-8
charset = utf-8

# 行尾格式:Windows一般为CRLF,Linux一般为LF。
end_of_line = crlf

# 文件结尾添加换行符,以防警告
insert_final_newline = true

After the configuration file is written, save it, then restart VS, and the files saved later will be processed with UTF-8.

When opening a project, the EditorConfig plugin looks for an .editorconfig file in the directory where the file was opened and in each parent directory, the file search stops if the root file path or EditorConfig file root=true is reached. EditorConfig files are read top-to-bottom, with rules found first taking precedence.

Tip: If you need to configure other items, you can check the documentation.

Effect after repair

Re-save the file in VS, and you can see the effect in Unity.
insert image description here


For more information, please check the general catalog [Unity] Unity study notes catalog arrangement

Guess you like

Origin blog.csdn.net/xiaoyaoACi/article/details/127045107