protected virtual void SetElementCount(int size, bool shouldChange = true) { if (size > children.Count) { Type elementType = GetElementType(); //because we know this will be null or a primitive, //it is safe to pass the same element to every new index //todo maybe make a real instance when we can object element = EditorReflector.GetDefaultForType(elementType); for (int i = children.Count; i < size; i++) { children.Add(CreateChild(this, string.Empty, elementType, element)); } if (shouldChange) { SetChanged(true); } } else if (size < children.Count) { while (children.Count > size) { DestroyChild(children.RemoveAndReturnAtIndex(children.Count - 1)); } if (shouldChange) { SetChanged(true); } } }
protected virtual void ResizeActualValue() { IList list = actualValue as IList; if (children.Count == 0 || (list != null && list.Count == children.Count)) { return; } list = list ?? EditorReflector.MakeInstance <IList>(declaredType); Debug.Assert(list != null, nameof(list) + " != null"); if (list.Count > children.Count) { while (list.Count > children.Count) { list.RemoveAt(list.Count - 1); } } else if (list.Count < children.Count) { while (list.Count < children.Count) { list.Add(EditorReflector.GetDefaultForType(declaredType.GetGenericArguments()[0])); } } actualValue = list; }
public void InsertElement(int index) { if (index >= 0 && index <= ChildCount) { Type elementType = GetElementType(); object defaultValue = EditorReflector.GetDefaultForType(declaredType); ReflectedProperty child = CreateChild(this, string.Empty, elementType, defaultValue); if (index == ChildCount) { AddElement(child); return; } children.Insert(index, child); SetChanged(true); } }
protected virtual void SetValue(object value) { Type previousType = actualType; if (value == null) { actualType = declaredType; actualValue = EditorReflector.GetDefaultForType(declaredType); } else { actualType = value.GetType(); actualValue = value; } if (actualType != previousType) { this.drawer = EditorReflector.CreateReflectedPropertyDrawer(this); } }