protected void Destroy() { DestroyChildren(); this.drawer = null; this.actualValue = null; this.children = null; this.parent = null; this.attributes = null; this.guiContent = null; this.changedChildren = null; this.fieldInfo = null; }
public static float GetChildHeights(ReflectedProperty property) { property.Drawer.Initialize(); float height = 0; for (int i = 0; i < property.ChildCount; i++) { ReflectedProperty child = property.ChildAt(i); if (!child.IsHidden) { height += child.GetPropertyHeight(); } } return(height); }
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); } }
private static void DrawProperties(Rect position, ReflectedProperty root) { List <ReflectedProperty> properties = root.GetChildren(); float remainingHeight = position.height; for (int i = 0; i < properties.Count; i++) { ReflectedProperty child = properties[i]; float height = child.Drawer.GetPropertyHeight(child); remainingHeight -= height; position.height = height; Internal_PropertyField(position, child, child.GUIContent, child.IsHidden); position.y += height; position.height = remainingHeight; } }
protected static ReflectedProperty CheckCircularReference(ReflectedProperty property) { if (property.actualValue == null || property.parent == null) { return(null); } ReflectedProperty ptr = property.parent; while (ptr != null) { if (ptr.actualValue == property.actualValue) { return(ptr); } ptr = ptr.parent; } return(null); }
public ReflectedProperty FindProperty(params string[] path) { ReflectedProperty ptr = this; if (path == null || path.Length == 0) { return(null); } for (int i = 0; i < path.Length; i++) { ptr = ptr.FindProperty(path[i]); if (ptr == null) { return(null); } } return(ptr); }
public ReflectedProperty FindParentOfDeclaredType(Type type) { if (parent == null) { return(null); } ReflectedProperty ptr = parent; while (ptr != null) { if (ptr.declaredType == type) { return(ptr); } ptr = ptr.parent; } return(null); }
private static void Internal_PropertyField(Rect position, ReflectedProperty property, GUIContent label, bool isHidden) { if (isHidden) { return; } if (label == null) { label = property.GUIContent; } Debug.Assert(property.Drawer != null, "property.Drawer != null"); if (!property.Drawer.IsInitialized) { property.Drawer.OnInitialize(); } property.Drawer.OnGUI(position, property, label); }
public ReflectedObject([NotNull] object target) { Type type = target.GetType(); if (type.IsArray) { root = new ReflectedArrayProperty(null, "--Root--", type, target); } else if (typeof(IList).IsAssignableFrom(type)) { root = new ReflectedListProperty(null, "--Root--", type, target); } else if (type.IsPrimitive || type == typeof(string) || type.IsEnum) { root = new ReflectedPrimitiveProperty(null, "--Root--", type, target); } else { root = new ReflectedInstanceProperty(null, "--Root--", target.GetType(), target); } }
public override void OnGUI(Rect position, ReflectedProperty property, GUIContent label = null) { Type type = property.Type; if (type.IsEnum) { property.Value = EditorGUI.EnumPopup(position, property.GUIContent, (Enum)property.Value); } else if (type.IsSubclassOf(typeof(Object))) { property.Value = EditorGUI.ObjectField(position, label, (Object)property.Value, type, true); } else if (property is ReflectedListProperty) { RenderList(position, (ReflectedListProperty)property); } else if (property is ReflectedInstanceProperty) { RenderWithFields(position, (ReflectedInstanceProperty)property); } }
protected void SetChanged(bool didChange) { if (isDirty == didChange) { return; } isDirty = didChange; ReflectedProperty ptr = this; while (ptr?.parent != null) { if (didChange) { ptr.parent.changedChildren.Add(ptr); } else { ptr.parent.changedChildren.Remove(ptr); } ptr = ptr.parent; } }
private void CreateChildren() { if (actualValue == null) { return; } DestroyChildren(); circularReference = CheckCircularReference(this); UnityEngine.Debug.Assert(circularReference == null, "circularReference == null"); FieldInfo[] fieldInfos = EditorReflector.GetFields(actualType); for (int i = 0; i < fieldInfos.Length; i++) { FieldInfo fi = fieldInfos[i]; if (ShouldReflectProperty(fi)) { children.Add(CreateChild(this, fi.Name, fi.FieldType, fi.GetValue(actualValue))); } } }
public override float GetPropertyHeight(ReflectedProperty property) { if (property is ReflectedListProperty) { float height = EditorGUIUtility.singleLineHeight; if (property.IsExpanded) { height += EditorGUIUtility.singleLineHeight; height += GetChildHeights(property); } return(height); } else if (property is ReflectedInstanceProperty) { float height = EditorGUIUtility.singleLineHeight; if (property.IsExpanded) { height += GetChildHeights(property); } return(height); } return(EditorGUIUtility.singleLineHeight); }
private void UpdateChildren() { FieldInfo[] fieldInfos = EditorReflector.GetFields(actualType); childSet = childSet ?? new List <ReflectedProperty>(8); for (int i = 0; i < children.Count; i++) { childSet.Add(children[i]); } for (int i = 0; i < fieldInfos.Length; i++) { FieldInfo info = fieldInfos[i]; if (ShouldReflectProperty(info)) { ReflectedProperty child = children.Find(info, (c, fInfo) => c.name == fInfo.Name); if (child != null) { UpdateChildIntenal(child, info.GetValue(actualValue)); childSet.Remove(child); } else { children.Add(CreateChild(this, info.Name, info.FieldType, info.GetValue(actualValue))); } } } for (int i = 0; i < childSet.Count; i++) { children.Remove(childSet[i]); } childSet.Clear(); UnityEngine.Debug.Assert(isDirty == false && changedChildren.Count == 0); }
public static float GetChildHeights(ReflectedProperty property, string[] skipList) { if (skipList == null) { return(GetChildHeights(property)); } property.Drawer.Initialize(); float height = 0; for (int i = 0; i < property.ChildCount; i++) { ReflectedProperty child = property.ChildAt(i); if (child.IsHidden) { continue; } int idx = Array.IndexOf(skipList, child.name); if (idx == -1) { height += child.GetPropertyHeight(); } } return(height); }
protected static ReflectedProperty CreateChild(ReflectedProperty parent, string name, Type type, object value) { if (type.IsPrimitive || type == typeof(string) || type.IsEnum) { return(new ReflectedPrimitiveProperty(parent, name, type, value)); } if (type.IsArray) { return(new ReflectedArrayProperty(parent, name, type, value)); } if (typeof(IList).IsAssignableFrom(type)) { return(new ReflectedListProperty(parent, name, type, value)); } if (type == typeof(Type)) { return(new ReflectedTypeProperty(parent, name, type, value)); } return(new ReflectedInstanceProperty(parent, name, type, value)); }
public override void OnGUI(Rect rect, ReflectedProperty property, GUIContent label = null) { property.Value = EditorGUI.CurveField(rect, label, (AnimationCurve)property.Value); }
public override void OnGUILayout(ReflectedProperty property, GUIContent label = null) { Rect rect = EditorGUILayout.GetControlRect(false, 16f, EditorStyles.colorField); OnGUI(rect, property, label); }
public override void OnGUI(Rect rect, ReflectedProperty property, GUIContent label = null) { property.Value = EditorGUI.Toggle(rect, label, (bool)property.Value); }
public override void OnGUI(Rect position, ReflectedProperty property, GUIContent label = null) { property.Value = EditorGUI.Vector4Field(position, label.text, (Vector4)property.Value); }
public void SetProperty(ReflectedProperty property) { this.property = property; }
public override void OnGUILayout(ReflectedProperty property, GUIContent label = null) { property.Value = EditorGUILayout.BoundsIntField(label, (BoundsInt)property.Value); }
public override void OnGUILayout(ReflectedProperty property, GUIContent label = null) { property.Value = EditorGUILayout.DoubleField(label, (double)property.Value); }
public void InsertElement(ReflectedProperty property, int insertIndex) { InsertElement(insertIndex); children[insertIndex].Value = property?.Value; }
public override void OnGUI(Rect position, ReflectedProperty property, GUIContent label = null) { property.Value = EditorGUI.BoundsField(position, label, (Bounds)property.Value); }
public override void OnGUI(Rect position, ReflectedProperty property, GUIContent label = null) { property.Value = EditorGUI.EnumPopup(position, label, (Enum)property.Value); }
public abstract void OnGUI(Rect position, ReflectedProperty property, GUIContent label);
public override void OnGUILayout(ReflectedProperty property, GUIContent label = null) { property.Value = EditorGUILayout.Toggle(label, property.boolValue); }
public override void OnGUILayout(ReflectedProperty property, GUIContent label = null) { property.Value = EditorGUILayout.EnumPopup(label, (Enum)property.Value); }
public override void OnGUILayout(ReflectedProperty property, GUIContent label = null) { property.Value = EditorGUILayout.Vector4Field(label.text, (Vector4)property.Value); }