码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2016-05-04 13:13:13      阅读:3318      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!