Commonly used knowledge in Unity

  1. Text components can use Chinese fonts:

The font used in the default text box of Unity does not support Chinese, and we need to manually import Chinese fonts for Unity, because I am using a Windows system, so the following is only valid for Windows systems. There is a Fonts folder in the Windows folder under the C disk directory of the Windows system. All font styles will be placed in this directory. Find the font style you need in it, copy it to your project, right click and select Text to create Font Asset (Font Asset), if you are using a new version of the text component, it is to create the font resource in the TMPMeshPro option (as shown in the figure), and its export result should be a blue F style.

Then you can drag and drop this font into the text component to display Chinese normally.

Then, if you don’t want to replace it every time you create a text component, you can open the project settings, the TextMeshPro settings, and then put your font into the Default Fonts Asset to set the default font. (But it seems that it is only valid for new fonts?)

 

     2. C# script intelligent comment

We often need to label our own code comments, the following can help us quickly sort out the comments

Entering / on the method or member variable written on VS three times in a row will be automatically replaced with

///<summary>

///

///</summary>

If it is a method, then whether there are additional tags for incoming parameters or return values, and write a description in the corresponding position, so that it can be reviewed later or shown to others to better understand the role of the end code

#region

//content

#endregion

Include the content between these two ends, which can be folded, and it is more convenient to layer the functions of the code, as shown in the following figure

For more details, see this blogger's article: http://t.csdn.cn/xW5zR

     3. Label of member variables

Tag [Header("Content")] is also called header comment

After adding this comment and saving the code, we can see this content on the corresponding member variable in the editor, so that we can better mark the content of this variable and facilitate setting in the editor for positioning.

tag[SerializeField]

The member variables marked by this, even if they are private attributes, can also be seen in the editor. I personally prefer to think that this is for the convenience of observing the value changes of some private attributes in the editor, because adding this tag in It is not as convenient as setting it to public directly from the beginning.

label[Range(min,max)]

The marked member variable can be set in the same way as the box slider in the editor, and its value range will also be set between min and max.

Guess you like

Origin blog.csdn.net/WEIWEI6661012/article/details/130340076