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
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?
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:
In the configuration window, click Create
the button to create a new standardized naming configuration file:
After the creation is completed:
Name Match
to match 原始名称
the matching character of the naming target, StandardizingNaming
use it to customize the naming specification in the naming configuration file, As follows, StandardizingNaming
some things are generated by default for us:
Hierarchy
hierarchical naming rules, specifying which components are named and combined according to which rules, for example, the Button
naming 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.
Project
Similarly, 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):
2. Select the object to be renamed, press the shortcut key Alt + 2
, and complete the renaming with one key:
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 Inspector
of its panel Transform
, click Copy To C# Public Field
:
and then enter the code editor to paste:
[Label("Btn_Head")] public GameObject Btn_Head;
Of course, it can also be generated in Private
the 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? !