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