Unity Editor Basics (1): Build-In Attribute (built-in attribute)

Source address: http://gad.qq.com/article/detail/33462 The
built-in properties of Unity can be queried from the official documentation. This article only introduces some commonly used built-in properties, as shown in the following figure:


Next, go to project settings, create an empty Unity project, the name is up to you, and the hierarchical relationship of the folders is as follows:



The Editor folder is not needed yet, but create it first and use it in future tutorials. Then create a new C# script in the Scripts folder, name it "People", and double-click to open the script.


The AddComponentMenu property allows adding a script to the Component menu, which you can then create for a selected game object via Component -> (the name you set), like this:



The RequireComponent() property will automatically add the components you need for you. If it already exists, it will not be added repeatedly and cannot be removed, as shown below:



Tip : After testing, I found a problem. If the script is already hung on the object, and then modify the script to add the RequireComponent attribute, it will not work at all, so it is recommended that you pay attention when using this attribute.


The ContextMenu() property allows you to add a command to the component, you can call it by right-clicking or clicking the settings icon (usually for functions), and the function is executed in a non-running state, as shown below:



HelpURL() provides a custom documentation link. Clicking the documentation icon on the component will open the link you specify, as shown below:



Tip : When filling in the link, be sure to write  http://  or  https:// , otherwise nothing will happen.



The Range() property is used to specify a value within a certain range and add a slider to it in the Inspector panel; the Multiline() property is used to add multi-line input to the string type; the header() property is used to add properties Title, the specific operation is as follows:



Simply break it down:


    1. On line 9, we use [Header("BaseInfo")] to set the header (to be "BaseInfo"), as shown above.


    2. In line 10, we used [Multiline(5)] to add 5 lines of input to its name attribute. As shown in the figure above, it is obvious that the input box has become larger.


    3. On line 12, we use [Range(-2,2)] to specify a range of (-2,2) for its age attribute, and add a slider to it, as shown above.



The Tooptip() property is used to add a specified tip in the Inspector panel when the mouse stays on the property with the Toptip() set; Space() is used to add the specified distance between the two properties of the Inspector panel, as shown below:





Well, at this point, the content of this article is over. You can use the knowledge you just learned to simply design your own scripts and experience the experience. The following tutorials will be more exciting, so stay tuned.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325713000&siteId=291194637