示例#1
0
 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);
        }
示例#3
0
 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);
     }
 }
示例#4
0
        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;
            }
        }
示例#5
0
        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);
        }
示例#6
0
        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);
        }
示例#7
0
        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);
        }
示例#8
0
        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);
        }
示例#9
0
        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);
            }
        }
示例#10
0
        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);
            }
        }
示例#11
0
        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)));
                }
            }
        }
示例#13
0
 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);
        }
示例#15
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);
        }
示例#16
0
        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));
        }
示例#17
0
 public override void OnGUI(Rect rect, ReflectedProperty property, GUIContent label = null)
 {
     property.Value = EditorGUI.CurveField(rect, label, (AnimationCurve)property.Value);
 }
示例#18
0
        public override void OnGUILayout(ReflectedProperty property, GUIContent label = null)
        {
            Rect rect = EditorGUILayout.GetControlRect(false, 16f, EditorStyles.colorField);

            OnGUI(rect, property, label);
        }
示例#19
0
 public override void OnGUI(Rect rect, ReflectedProperty property, GUIContent label = null)
 {
     property.Value = EditorGUI.Toggle(rect, label, (bool)property.Value);
 }
示例#20
0
 public override void OnGUI(Rect position, ReflectedProperty property, GUIContent label = null)
 {
     property.Value = EditorGUI.Vector4Field(position, label.text, (Vector4)property.Value);
 }
示例#21
0
 public void SetProperty(ReflectedProperty property)
 {
     this.property = property;
 }
示例#22
0
 public override void OnGUILayout(ReflectedProperty property, GUIContent label = null)
 {
     property.Value = EditorGUILayout.BoundsIntField(label, (BoundsInt)property.Value);
 }
示例#23
0
 public override void OnGUILayout(ReflectedProperty property, GUIContent label = null)
 {
     property.Value = EditorGUILayout.DoubleField(label, (double)property.Value);
 }
示例#24
0
 public void InsertElement(ReflectedProperty property, int insertIndex)
 {
     InsertElement(insertIndex);
     children[insertIndex].Value = property?.Value;
 }
示例#25
0
 public override void OnGUI(Rect position, ReflectedProperty property, GUIContent label = null)
 {
     property.Value = EditorGUI.BoundsField(position, label, (Bounds)property.Value);
 }
示例#26
0
 public override void OnGUI(Rect position, ReflectedProperty property, GUIContent label = null)
 {
     property.Value = EditorGUI.EnumPopup(position, label, (Enum)property.Value);
 }
示例#27
0
 public abstract void OnGUI(Rect position, ReflectedProperty property, GUIContent label);
示例#28
0
 public override void OnGUILayout(ReflectedProperty property, GUIContent label = null)
 {
     property.Value = EditorGUILayout.Toggle(label, property.boolValue);
 }
示例#29
0
 public override void OnGUILayout(ReflectedProperty property, GUIContent label = null)
 {
     property.Value = EditorGUILayout.EnumPopup(label, (Enum)property.Value);
 }
示例#30
0
 public override void OnGUILayout(ReflectedProperty property, GUIContent label = null)
 {
     property.Value = EditorGUILayout.Vector4Field(label.text, (Vector4)property.Value);
 }