Unity Notes Tips

Source: Internet
Author: User
Tags float number

If you expand Editor, you can have the property display the Chinese name in the Inspector View. Take a look at the official tagged feature that allows you to display Chinese on the top of your field

You just need to add effects to the field.


[Header (" note ")][space]  Public Vector3 test1;

=====================================================================================

Own time to write a Chinese display small script. Next time, ask the boss if he can add it to the project.

usingUnityengine;usingSystem.Collections;usingUnityeditor;usingSystem;usingSystem.Reflection;usingSystem.Collections.Generic; [Customeditor (typeof(mycompoment))] Public classmycompomenteditor:editor{ PublicMycompomenteditor ():Base()    {        //Debug.Log ("I Initialized");    }    Private Static BOOLIsdevelop =true;  Public Override voidOninspectorgui () {if(isdevelop) {mycompoment edit=(mycompoment) target; Type T=Edit.            GetType (); stringLabel =string.            Empty; Fieldinfo[] Fieldinfs=T.getfields (); System.object[] Atrrs=NULL;  for(inti =0; i < fieldinfs.length; i++) {Atrrs= Fieldinfs[i]. GetCustomAttributes (false);  for(intK =0; K < Fieldinfs[i]. GetCustomAttributes (false). Length; k++)                {                    if(Atrrs[k] isLabelattribute) {Label=((Labelattribute) atrrs[k]).                        Label; Switch(Fieldinfs[i]. Fieldtype.name) { Case "String": Fieldinfs[i]. SetValue (Edit, Editorguilayout.textfield (label, Fieldinfs[i). GetValue (Edit).                                ToString ()));  Break;  Case "Float": Fieldinfs[i]. SetValue (Edit, Editorguilayout.floatfield (label,float) Fieldinfs[i].                                GetValue (edit));  Break; //Case "Double"://Fieldinfs[i]. SetValue (Edit, Editorguilayout.doube (label, double) fieldinfs[i].                            GetValue (edit)); //Break ;                             Case "Int": Fieldinfs[i]. SetValue (Edit, Editorguilayout.intfield (label,int) Fieldinfs[i].                                GetValue (edit));  Break;  Case "Int32": Fieldinfs[i]. SetValue (Edit, Editorguilayout.intfield (label,int) Fieldinfs[i].                                GetValue (edit));  Break;  Case "Color": Fieldinfs[i]. SetValue (Edit, Editorguilayout.colorfield (label, (Unityengine.color) fieldinfs[i].                                GetValue (edit));  Break;  Case "Gameobject": Fieldinfs[i]. SetValue (Edit, Editorguilayout.objectfield (label, (Unityengine.object) fieldinfs[i]. GetValue (edit),typeof(Gameobject)));  Break;  Case "Component": Debug.Log ("run over component"); Fieldinfs[i]. SetValue (Edit, Editorguilayout.objectfield (label, (Unityengine.object) fieldinfs[i]. GetValue (edit),typeof(Component)));  Break;  Case "Vector2": Fieldinfs[i]. SetValue (Edit, Editorguilayout.vector2field (label, (Vector2) fieldinfs[i].                                GetValue (edit));  Break;  Case "Vector3": Fieldinfs[i]. SetValue (Edit, Editorguilayout.vector3field (label, (Vector3) fieldinfs[i].                                GetValue (edit));  Break;  Case "Vector4": Fieldinfs[i]. SetValue (Edit, Editorguilayout.vector4field (label, (VECTOR4) fieldinfs[i].                                GetValue (edit));  Break; //Case "Test"://Debug.Log ("Run over component"); //Fieldinfs[i]. SetValue (Edit, Editorguilayout.objectfield (label, (Unityengine.object) fieldinfs[i].                            GetValue (Edit), typeof (Component)); //Break ;                            default:                                //Debug.Log ("Fieldinfs[i"). Name "+ fieldinfs[i]. FieldType.BaseType.Name);                                if(Fieldinfs[i]. FieldType.BaseType.Name = ="Monobehaviour") {Fieldinfs[i]. SetValue (Edit, Editorguilayout.objectfield (label, (Unityengine.object) fieldinfs[i]. GetValue (edit), Fieldinfs[i].                                FieldType)); }                                                                 Break; }                    }                }            }        }        Else        {            Base.        Oninspectorgui (); }     }    #regionCode that is not currently in use/*    <summary>///Cache instance properties, next time you do not need to use the loop///</summary> public dictionary<string, string> dir;            public void Getprorptes () {if (isdevelop) {mycompoment edit = (mycompoment) target; Type t = edit.            GetType (); String label = String.            Empty;            fieldinfo[] Fieldinfos = T.getfields ();            system.object[] Atrrs = null;            Guicontent contextui = null; for (int i = 0; i < fieldinfos.length; i++) {Atrrs = Fieldinfos[i].                GetCustomAttributes (FALSE); for (int k = 0; k < Atrrs. Length;  k++) {if (Atrrs[k] is Labelattribute) {label = ((Labelattribute) atrrs[k]).                        Label;                        Contextui = new Guicontent ();                        contextui.text = label; Editorguilayout.propertyfield (Serializedobject.findproperty (fieldinfos[i). Name), CONTEXTUI); }}}} else {base.        Oninspectorgui ();     }    }*/    #endregion}

Mycompoment:

usingUnityengine;usingSystem.Collections; [Serializefield] Public classMycompoment:monobehaviour {[Labelattribute (Label="name")]     Public stringMyName ="123"; [Labelattribute (Label="Float Number")]     Public floatFLOAT1 = -; [Labelattribute (Label="Double digit")]     Public DoubleDouble1 = -; [Labelattribute (Label="int number")]     Public intInt1 = -; [Labelattribute (Label="Color")]     PublicColor Color1 =color.red; [Labelattribute (Label="Game Objects")]     PublicGameobject GameObject1; [Labelattribute (Label="Components")]     PublicStartPanel Component1; [Labelattribute (Label="2D")]     PublicVector2 Vector2; [Labelattribute (Label="3D")]     PublicVector3 Vector3; [Labelattribute (Label="4D")]     PublicVector4 Vector4;}

Labelattribute Features:

using Unityengine; using System.Collections; using System;  Public class Labelattribute:attribute {    publicstring  Label;}

Source code: Http://yunpan.cn/cJhp4tThyGauJ Access Password 5789

Unity Notes Tips

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.