Beispiel #1
0
        public static object DrawArray(object value, Type type, ref bool foldout, string label)
        {
            int len = 0;

            if (value == null)
            {
                value = ReflectionUtils.InvokeConstructor(type, new object[] { 0 });
            }
            else
            {
                len = ReflectionUtils.GetLength(value);
            }

            foldout = EditorGUILayout.Foldout(foldout, label);

            if (foldout)
            {
                YHEditorTools.PushLabelWidth(80);

                //数组大小
                int newLen = EditorGUILayout.IntField("size", len);
                if (newLen != len)
                {
                    object newValue = ReflectionUtils.InvokeConstructor(type, new object[] { newLen });;

                    for (int i = 0; i < newLen; ++i)
                    {
                        object ele = ReflectionUtils.InvokeMethod(value, "GetValue", new object[] { i < len ? i : len - 1 });
                        ReflectionUtils.InvokeMethod(newValue, "SetValue", new object[] { ele, i });
                    }

                    value = newValue;
                }

                //数组元素
                Type elementType = type.GetElementType();
                for (int i = 0; i < newLen; ++i)
                {
                    object ele    = type.GetMethod("GetValue", new Type[] { typeof(int) }).Invoke(value, new object[] { i });
                    object newEle = YHGUI.DrawElement(ele, elementType, "Element " + i);
                    if (ele != newEle)
                    {
                        ReflectionUtils.InvokeMethod(value, "SetValue", new object[] { newEle, i });
                    }
                }

                YHEditorTools.PopLabelWidth();
            }
            return(value);
        }
Beispiel #2
0
 public override void Draw()
 {
     YHEditorTools.PushIndentLevel(m_Deep);
     m_Value = YHGUI.DrawElement(m_Value, m_Type, m_Label);
     YHEditorTools.PopIndentLevel();
 }