[Unity] HTFramework framework (43) standardized naming

Updated: April 28, 2022.
Github source code: [Click me to get the source code]
Gitee source code: [Click me to get the source code]

standardized naming

When the team members get together 命名习惯(or it’s not a habit, just a matter of heart) together, a situation like the one shown below, as a patient with obsessive-compulsive disorder, have you collapsed... In fact, most of the brainpower is spent on writing
insert image description here
functions For programmers on the Internet, there is really no more time for naming. Therefore, there has not been a fixed rule for naming UI components, game objects, and even script variables for a long time, but However, everyone knows that good naming habits can not only bring 可读性的显著提升, 容错性but also 工作的心情have a considerable impact on the performance of the program.

For example, in the picture below, after the component naming is standardized, does it look more palatable?
insert image description here

So, for the naming thing, we customized a very simple standardized naming tool (really simple).

use

Standardized naming configuration

First, you need to create a standardized naming configuration file, use him to tell the system which objects will support standardized naming, and how to name them.

Click the following menu to bring up the configuration window:
insert image description here
In the configuration window, click Createthe button to create a new standardized naming configuration file:
insert image description here
After the creation is completed:
insert image description here
Name Matchto match 原始名称the matching character of the naming target, StandardizingNaminguse it to customize the naming specification in the naming configuration file, As follows, StandardizingNamingsome things are generated by default for us:
insert image description here
Hierarchyhierarchical naming rules, specifying which components are named and combined according to which rules, for example, the Buttonnaming rules of components are Btn_#NAME#, which #NAME#will automatically match the original name of the target object (to put it bluntly, add a prefix).

Of course, you can also add any custom components, +just click the button above.

insert image description here
ProjectSimilarly, the naming rules of the objects in the Project view are specified.

One-click renaming

Then, after generating this configuration file, we only need two steps to complete the unified and standardized naming of all objects.

1. Name the object according to its actual use (of course you can not do this):
insert image description here
2. Select the object to be renamed, press the shortcut key Alt + 2, and complete the renaming with one key:
insert image description here
at the same time, if you need to refer to the specified object in the code For example Btn_Head, here is a simple method: select this object, on the component Inspectorof its panel Transform, click Copy To C# Public Field:
insert image description here
and then enter the code editor to paste:

    [Label("Btn_Head")] public GameObject Btn_Head;

Of course, it can also be generated in Privatethe form of an object, where path injection will be automatically added to it InjectPath(of course, the default generated path may not be correct):

    [InjectPath("Canvas/UserInfo/Btn_Head")] private GameObject _btn_Head;

Seeing this, I think you have also noticed that it is obvious that maintaining correspondence 代码里面的变量名with 场景对象的名称each other satisfies our obsessive-compulsive disorder. Similarly, we also save the time of tangling how to name variables. Why not do it? !

Guess you like

Origin blog.csdn.net/qq992817263/article/details/124470077