コード例 #1
0
        protected ListFieldBase(MemberData data, object owner, bool requiresSetter)
        {
            _owner          = owner;
            _label          = new GUIContent(data.name, data.description);
            this.memberName = data.member.Name;

            var prop = data.member as PropertyInfo;

            if (prop != null)
            {
                _reorderable = !prop.IsDefined <NotReorderableAttribute>(true);
                _itemType    = GetItemType(prop.PropertyType);
                _list        = (IList)prop.GetValue(owner, null);
                if (_list == null || requiresSetter)
                {
                    _setter = (list) =>
                    {
                        _list = list;
                        prop.SetValue(owner, list, null);
                        if (_simpleItemCreator != null)
                        {
                            _simpleItemCreator.SetParent(_list);
                        }
                    };
                }
            }
            else
            {
                var field = data.member as FieldInfo;
                if (field != null)
                {
                    _reorderable = !field.IsDefined <NotReorderableAttribute>(true);
                    _itemType    = GetItemType(field.FieldType);
                    _list        = (IList)field.GetValue(owner);
                    if (_list == null || requiresSetter)
                    {
                        _setter = (list) =>
                        {
                            _list = list;
                            field.SetValue(owner, list);
                            if (_simpleItemCreator != null)
                            {
                                _simpleItemCreator.SetParent(_list);
                            }
                        };
                    }
                }
                else
                {
                    throw new ArgumentException("Invalid reflected member type, only fields and properties are supported.");
                }
            }

            _isSimpleType = SerializationMaster.ConverterExists(_itemType) || SerializationMaster.StagerExists(_itemType);

            if (_list != null)
            {
                var count = _list.Count;
                _editorItems = new List <EditorItem>(count);

                if (_isSimpleType)
                {
                    _simpleItemCreator = new SimpleItemConstructor(_list, _itemType);

                    for (int i = 0; i < count; i++)
                    {
                        var item = _simpleItemCreator.Conctruct(i, _list[i]);
                        _editorItems.Add(ReflectMaster.Reflect(item));
                    }
                }
                else
                {
                    for (int i = 0; i < count; i++)
                    {
                        _editorItems.Add(ReflectMaster.Reflect(_list[i]));
                    }
                }
            }
            else
            {
                _editorItems = new List <EditorItem>();
            }
        }