Unity3d How to extend the script of the Inspector panel

Source: Internet
Author: User

About the extended editor Unity gives us a good visual programming environment, but it's not convenient for some of our more lazy-egg program apes. So unity has also provided us with a very friendly way to expand. For today, how to customize the Inspector panel of a script. All editor-related scripts in unity are placed in the Editor folder, so build one first. Suppose there is a script ABC.cs we want to customize its Inspector panel. Now on the code:
//scripts to customize Public classabc:monobehaviour{ Public BOOLA;  Public floatb;  Public intC;}//Custom Editor Scripts[Customeditor (typeof(ABC)), Caneditormutipleobjects]//This means that this script is an editor script for the ABC script, caneditormutipleobjects, as the name implies, can edit multiple objects simultaneously Public classabc_editor:editor{//Here's a simple display control that lets you understand the process of customizing the editor.            Public StaticSerializedproperty A_prop, B_prop, C_prop; voidonenable () {//three properties defined in ABC.csA_prop = Serializedobject.findproperty ("a"); B_prop= Serializedobject.findproperty ("b"); C_prop= Serializedobject.findproperty ("C"); }            Public Override voidOninspectorgui () {//update the serialization properties displayed by the editorserializedobject.update (); //nothing to say, show propertiesEditorguilayout.propertyfield (A_prop); //gets the serialized value of a                     BOOLdisplay =A_prop.boolvalue; if(Display) {Editorguilayout.propertyfield (b_prop); floatWeight =B_prop.floatvalue; if(Weight >0.5f) Editorguilayout.propertyfield (C_prop); }                        //Accept Serialization Assignmentserializedobject.applymodifiedproperties (); }}//at this point, an example of a simple variable control showing each other is complete. //Try it! 

Unity3d How to extend the script of the Inspector panel

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.