Unity comments tips

Source: Internet
Author: User
Tags float number
You only need to add a special effect to the field to [Header (comment)] [Space (20)] publicVector3test1; write a script to show Chinese characters. next time, ask the boss if he can add it to the Project for usin.

You only need to add a special effect to the field to [Header ("comment")] [Space (20)] public Vector3 test1; ========================================================== ========================================================== ===== I took the time to write a small script for displaying Chinese characters. next time, ask the boss if he can add it to the Project for usin.

You only need to add a special effect to the field.


[Header ("comment")] [Space (20)] public Vector3 test1;

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

I took the time to write a script to show Chinese characters. Next time I asked the boss if he could add the script to the project.

Using UnityEngine; using System. collections; using UnityEditor; using System. reflection; using System. collections. generic; [CustomEditor (typeof (MyCompoment)] public class MyCompomentEditor: Editor {public MyCompomentEditor (): base () {// Debug. log ("I initialized");} private static bool isDevelop = true; public override void OnInspectorGUI () {if (isDevelop) {MyCompoment edit = (MyCompoment) target; type t = edit. getType (); string label = string. empty; FieldInfo [] fieldInfs = t. getFields (); System. object [] atrrs = null; for (int I = 0; I <fieldInfs. length; I ++) {atrrs = fieldInfs [I]. getCustomAttributes (false); for (int k = 0; k <fieldInfs [I]. getCustomAttributes (false ). length; k ++) {if (atrrs [k] is LabelAttribute) {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 ("Running 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 ("Running 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 () ;}# code not currently used by region /*////// Cache instance attributes. You do not need to use loops next time ///Public Dictionary
 
  
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:

Using UnityEngine; using System. collections; [SerializeField] public class MyCompoment: MonoBehaviour {[LabelAttribute (Label = "name")] public string MyName = "123"; [LabelAttribute (Label = "float number")] public float float1 = 100; [LabelAttribute (Label = "double digit")] public double double1 = 100; [LabelAttribute (Label = "int digit")] public int int1 = 100; [LabelAttribute (Label = "Color")] public Color color1 = Color. red; [LabelAttribute (Label = "game object")] public GameObject GameObject1; [LabelAttribute (Label = "component")] public StartPanel Component1; [LabelAttribute (Label = "2D")] public Vector2 Vector2; [LabelAttribute (Label = "3D")] public Vector3 Vector3; [LabelAttribute (Label = "4D")] public Vector4 Vector4 ;}

LabelAttribute features:

using UnityEngine;using System.Collections;using System;public class LabelAttribute : Attribute {    public string Label;}

Source code: http://yunpan.cn/cJhp4tThyGauJ password 5789

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.