首页 > 编程语言 > 详细

Unity中实现List类型的自定义GUI(ReorderableList)

时间:2016-05-04 13:12:51      阅读:777      评论:0      收藏:0      [点我收藏+]

感谢JW同学提供的相关链接。

Unity本身提供了float,int,vector3..等类型字段的gui接口,而对于集合类型一般要自己硬写。

官方提供了一个List的自定义GUI,但使用起来非常复杂

 

UnityEditorInternal.ReorderableList使用:

http://www.cnblogs.com/hont/p/5458021.html

 

 

另外有一个开源的ReorderableList实现,Rotorz.ReorderableList

这个用起来非常简单

 

MonoBehaviour:

public class ReorderableTest : MonoBehaviour
{
    public List<string> names = new List<string>();
}

 

Editor:

[CustomEditor(typeof(ReorderableTest))]
public class ReorderableTestInspector : Editor
{
    SerializedProperty mNamesProp;


    private void OnEnable()
    {
        mNamesProp = serializedObject.FindProperty("names");
    }

    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        ReorderableListGUI.Title("names");
        ReorderableListGUI.ListField(mNamesProp);

        serializedObject.ApplyModifiedProperties();
    }
}

 

最终效果:

技术分享

 

 

只需把序列化字段名称传给Rotorz.ReorderableList就可以在GUI显示了。

 

下载地址:

https://bitbucket.org/rotorz/reorderable-list-editor-field-for-unity

Unity中实现List类型的自定义GUI(ReorderableList)

原文:http://www.cnblogs.com/hont/p/5458035.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!