[Unity3D] editor extension array or List display, unity3dlist

Source: Internet
Author: User

[Unity3D] editor extension array or List display, unity3dlist

The effect is as follows:

The source code is as follows:

1 using System. collections. generic; 2 using UnityEditor; 3 using UnityEngine; 4 5 namespace XM. editor 6 {7 public class AssetBundleCreator: EditorWindow 8 {9 [MenuItem ("Tools/Build Asset Bundle")] 10 public static void BuildAssetBundle () 11 {12 var win = GetWindow <AssetBundleCreator> ("Build Asset Bundle"); 13 win. show (); 14} 15 16 [SerializeField] // 17 protected List must be added <UnityEngine. object> _ assetLst = new List <UnityEngine. object> (); 18 19 // serialization Object 20 protected SerializedObject _ serializedObject; 21 22 // serialization attribute 23 protected SerializedProperty _ assetLstProperty; 24 25 26 protected void OnEnable () 27 {28 // use the current class to initialize 29 _ serializedObject = new SerializedObject (this); 30 // obtain the serializedObject attribute 31 _ assetLstProperty = _ serializedObject in the current class. findProperty ("_ assetLst"); 32} 33 34 protected void OnGUI () 35 {36 // Update 37 _ serializedObject. update (); 38 39 // start to check whether there is any modification 40 EditorGUI. beginChangeCheck (); 41 42 // display attribute 43 // The second parameter must be set to true; otherwise, the child node cannot be displayed, that is, the List content 44 EditorGUILayout. propertyField (_ assetLstProperty, true); 45 46 // check whether there is any modification 47 if (EditorGUI. endChangeCheck () 48 {// submit the modification 49 _ serializedObject. applyModifiedProperties (); 50} 51} 52} 53}

Above original address http://blog.csdn.net/u012741077/article/details/54884623

 

------------------------------------ Modify -------------------------------------------------

You need to define the variable in the script you modified the Panel (currently only the List has been successfully tested), and serialize it. Then, serialize the script in the corresponding editor file.

1 SerializedObject serializedObject = new UnityEditor. serializedObject (itemCollider); 2 SerializedProperty serializedPropertyMyInt = serializedObject. findProperty ("HideObjForOnEnable"); 3 if (itemCollider. isOnEnableHideObj = EditorGUILayout. toggle (new GUIContent ("Is On Disable Hide Obj", "whether to add and activate hidden object events"), itemCollider. isOnEnableHideObj) 4 {5 // start to check whether there are any modifications to 6 EditorGUI. beginChangeCheck (); 7 8 // display attribute 9 // The second parameter must be true; otherwise, the child node cannot be displayed, that is, the List content 10 EditorGUILayout. propertyField (serializedPropertyMyInt, new GUIContent ("Hide Obj For On Disable", "Hide object"), true); 11 12 // check whether there is any modification 13 if (EditorGUI. endChangeCheck () 14 {// submit the modification 15 serializedObject. applyModifiedProperties (); 16}

The effect is as follows:

After the experiment, it is no problem to write it directly in the OnInspectorGUI () method.

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.