Пример #1
0
        public static float GetPropertyHeight(GUIContent label, PersistentProperty property, bool includeChildren)
        {
            var height         = 0f;
            var propertyType   = property.type;
            var propertyDrawer = UserDatabase.caches.GetPropertyDrawer(propertyType);

            if (propertyDrawer != null)
            {
                height += propertyDrawer.GetHeight(property, label);
            }
            else if (UserDatabase.caches.IsDefaultPropertyType(propertyType))
            {
                return(GetDefaultTypeHeight(label, propertyType));
            }
            else
            {
                height += EditorGUIUtility.singleLineHeight;
                var foldout = UserDatabase.caches.GetPropertyFoldout(property);
                if (property.exist && includeChildren && foldout)
                {
                    var children = property.ListChildren();
                    foreach (var child in children)
                    {
                        var childLabel = new GUIContent(child.displayName);
                        height += EditorGUIUtility.standardVerticalSpacing;
                        height += GetPropertyHeight(childLabel, child, true);
                    }
                }
            }

            return(height);
        }
Пример #2
0
            public void SetPropertyFoldout(PersistentProperty persistentProperty, bool foldout)
            {
                var ret = mFoldouts.Find(i =>
                                         i.objectType == persistentProperty.persistentObject.type &&
                                         i.propertyPath == persistentProperty.propertyPath);

                if (ret != null)
                {
                    ret.foldout = foldout;
                }
            }
Пример #3
0
        public static void ObjectField(Rect position, GUIContent label, PersistentProperty property)
        {
            Debug.Assert(typeof(Object).IsAssignableFrom(property.type));
            EditorGUI.BeginChangeCheck();
            var obj = ObjectField(position, label, property.GetValue <Object>(), property.type,
                                  property.hasMultipleDifferentValues);

            if (EditorGUI.EndChangeCheck())
            {
                property.SetValue(obj);
            }
        }
Пример #4
0
        public override void OnGUI(Rect position, PersistentProperty property, GUIContent label)
        {
            var rect = position;

            rect.height = EditorGUIUtility.singleLineHeight;
            var propLength = property.Find("Length");

            PersistentGUI.BeginShowMixedValue(propLength.hasMultipleDifferentValues);
            EditorGUI.BeginChangeCheck();
            var length = EditorGUI.DelayedIntField(rect, label, propLength.GetValue <int>());

            if (EditorGUI.EndChangeCheck())
            {
                length = Mathf.Max(0, length);
                property.ResizeArray(length);
            }
            PersistentGUI.EndShowMixedValue();
            rect.y += EditorGUIUtility.singleLineHeight;
            rect.y += EditorGUIUtility.standardVerticalSpacing;
            var elType = property.type.GetElementType();

            if (property.length == 1 &&
                PersistentGUI.IsDefaultPropertyType(elType))
            {
                EditorGUI.indentLevel += 1;
                var array = property.GetValue <Array>();
                for (int i = 0; i < array.Length; i++)
                {
                    EditorGUI.BeginChangeCheck();
                    var itemLabel = new GUIContent("Element " + i);
                    var itemValue = PersistentGUI.DefaultTypeField(rect, itemLabel, array.GetValue(i));
                    if (EditorGUI.EndChangeCheck())
                    {
                        var newArray = Array.CreateInstance(elType, array.Length);
                        Array.Copy(array, newArray, array.Length);
                        newArray.SetValue(itemValue, i);
                        property.SetValue(newArray);
                    }
                    rect.y += PersistentGUI.GetDefaultTypeHeight(itemLabel, elType);
                    rect.y += EditorGUIUtility.standardVerticalSpacing;
                }
                EditorGUI.indentLevel -= 1;
            }
            else
            {
                PersistentGUI.BeginColor(Color.yellow);
                EditorGUI.LabelField(rect, new GUIContent("Array's element is not editable."));
                PersistentGUI.EndColor();
            }
        }
Пример #5
0
        public static void PropertyField(Rect position, GUIContent label, PersistentProperty property,
                                         bool includeChildren = false)
        {
            var propertyType = property.type;

            if (UserDatabase.caches.IsDefaultPropertyType(propertyType))
            {
                DefaultPropertyField(position, label, property);
            }
            else
            {
                var propertyRect = position;
                propertyRect.height = EditorGUIUtility.singleLineHeight;
                if (!property.exist)
                {
                    BeginColor(Color.yellow);
                    EditorGUI.LabelField(propertyRect, label, new GUIContent("NULL"));
                    EndColor();
                }
                else
                {
                    var propertyDrawer = UserDatabase.caches.GetPropertyDrawer(propertyType);
                    if (propertyDrawer != null)
                    {
                        propertyDrawer.OnGUI(position, property, label);
                    }
                    else
                    {
                        var foldout = EditorGUI.Foldout(propertyRect, UserDatabase.caches.GetPropertyFoldout(property),
                                                        label);
                        UserDatabase.caches.SetPropertyFoldout(property, foldout);
                        if (includeChildren && foldout)
                        {
                            propertyRect.y += EditorGUIUtility.singleLineHeight;
                            var children = property.ListChildren();
                            EditorGUI.indentLevel += 1;
                            foreach (var child in children)
                            {
                                var childLabel = new GUIContent(child.displayName);
                                propertyRect.y += EditorGUIUtility.standardVerticalSpacing;
                                PropertyField(propertyRect, childLabel, child, includeChildren);
                                propertyRect.y += GetPropertyHeight(childLabel, child, includeChildren);
                            }

                            EditorGUI.indentLevel -= 1;
                        }
                    }
                }
            }
        }
Пример #6
0
        public static void FloatSlider(Rect position, GUIContent label, PersistentProperty property, float leftValue,
                                       float rightValue)
        {
            Debug.Assert(property.type == typeof(float));
            var value = property.GetValue <float>();

            BeginShowMixedValue(property.hasMultipleDifferentValues);
            EditorGUI.BeginChangeCheck();
            var newValue = EditorGUI.Slider(position, label, value, leftValue, rightValue);

            if (EditorGUI.EndChangeCheck())
            {
                property.SetValue(newValue);
            }
            EndShowMixedValue();
        }
Пример #7
0
            public bool GetPropertyFoldout(PersistentProperty persistentProperty)
            {
                var ret = mFoldouts.Find(i =>
                                         i.objectType == persistentProperty.persistentObject.type &&
                                         i.propertyPath == persistentProperty.propertyPath);

                if (ret == null)
                {
                    ret = new FoldData()
                    {
                        objectType   = persistentProperty.persistentObject.type,
                        propertyPath = persistentProperty.propertyPath
                    };
                    mFoldouts.Add(ret);
                }

                return(ret.foldout);
            }
Пример #8
0
        public static void PropertyField(GUIContent label, PersistentProperty property, bool includeChildren,
                                         params GUILayoutOption[] options)
        {
            Rect rect;
            var  propertyType   = property.type;
            var  propertyDrawer = UserDatabase.caches.GetPropertyDrawer(propertyType);

            if (propertyType == typeof(bool) && propertyDrawer == null)
            {
                rect = GetToggleRect(true, options);
            }
            else
            {
                rect = EditorGUILayout.GetControlRect(PersistentGUI.LabelHasContent(label),
                                                      PersistentGUI.GetPropertyHeight(label, property, includeChildren), options);
            }

            PersistentGUI.PropertyField(rect, label, property, includeChildren);
        }
Пример #9
0
        public override float GetHeight(PersistentProperty property, GUIContent label)
        {
            var height = EditorGUIUtility.singleLineHeight;
            var elType = property.type.GetElementType();

            if (property.length == 1 &&
                PersistentGUI.IsDefaultPropertyType(elType))
            {
                var array = property.GetValue <Array>();
                for (int i = 0; i < array.Length; i++)
                {
                    var itemLabel = new GUIContent("Element " + i);
                    height += EditorGUIUtility.standardVerticalSpacing;
                    height += PersistentGUI.GetDefaultTypeHeight(itemLabel, elType);
                }
            }
            else
            {
                height += EditorGUIUtility.singleLineHeight;
            }
            return(height);
        }
Пример #10
0
        public static void BoundsField(Rect position, GUIContent label, PersistentProperty property)
        {
            var flag = LabelHasContent(label);

            if (flag)
            {
                var controlID = GUIUtility.GetControlID(s_PropertyHash, FocusType.Keyboard, position);
                position = MultiFieldPrefixLabel(position, controlID, label, 3);
                if (EditorGUIUtility.wideMode)
                {
                    position.y += EditorGUIUtility.singleLineHeight;
                }
            }

            position.height = EditorGUIUtility.singleLineHeight;
            position        = DrawBoundsFieldLabelsAndAdjustPositionForValues(position, EditorGUIUtility.wideMode && flag);
            MultiPropertyField(position,
                               new GUIContent[] { new GUIContent("X"), new GUIContent("Y"), new GUIContent("Z") },
                               property.Find(new string[] { "center.x", "center.y", "center.z" }));
            position.y += EditorGUIUtility.singleLineHeight;
            MultiPropertyField(position,
                               new GUIContent[] { new GUIContent("X"), new GUIContent("Y"), new GUIContent("Z") },
                               property.Find(new string[] { "extents.x", "extents.y", "extents.z" }));
        }
Пример #11
0
 public virtual float GetHeight(PersistentProperty property, GUIContent label)
 {
     return(0);
 }
Пример #12
0
 public static void PropertyField(GUIContent label, PersistentProperty property,
                                  params GUILayoutOption[] options)
 {
     PropertyField(label, property, true, options);
 }
Пример #13
0
        public static void DefaultPropertyField(Rect position, GUIContent label, PersistentProperty property)
        {
            var propertyType = property.type;

            if (propertyType == typeof(Vector2))
            {
                Vector2Field(position, label, property);
            }
            else if (propertyType == typeof(Vector3))
            {
                Vector3Field(position, label, property);
            }
            else if (propertyType == typeof(Vector4))
            {
                Vector4Field(position, label, property);
            }
            else if (propertyType == typeof(Rect))
            {
                RectField(position, label, property);
            }
            else if (propertyType == typeof(Bounds))
            {
                BoundsField(position, label, property);
            }
            else if (propertyType.IsSubclassOf(typeof(Object)))
            {
                ObjectField(position, label, property);
            }
            else
            {
                object updateValue   = null;
                var    propertyValue = property.GetValue <object>();
                BeginShowMixedValue(property.hasMultipleDifferentValues);
                EditorGUI.BeginChangeCheck();
                if (propertyType == typeof(bool))
                {
                    updateValue = EditorGUI.Toggle(position, label, (bool)propertyValue);
                }
                else if (propertyType == typeof(int))
                {
                    updateValue = EditorGUI.IntField(position, label, (int)propertyValue);
                }
                else if (propertyType == typeof(long))
                {
                    updateValue = EditorGUI.LongField(position, label, (long)propertyValue);
                }
                else if (propertyType == typeof(float))
                {
                    updateValue = EditorGUI.FloatField(position, label, (float)propertyValue);
                }
                else if (propertyType == typeof(double))
                {
                    updateValue = EditorGUI.DoubleField(position, label, (double)propertyValue);
                }
                else if (propertyType == typeof(string))
                {
                    updateValue = EditorGUI.TextField(position, label, (string)propertyValue);
                }
                else if (propertyType == typeof(Color) ||
                         propertyType == typeof(Color32))
                {
                    updateValue = EditorGUI.ColorField(position, label, (Color)propertyValue);
                }
                else if (propertyType == typeof(UnityEngine.Object) ||
                         propertyType.IsSubclassOf(typeof(UnityEngine.Object)))
                {
                    updateValue = EditorGUI.ObjectField(position, label, (UnityEngine.Object)propertyValue,
                                                        propertyType, false);
                }
                else if (propertyType == typeof(AnimationCurve))
                {
                    updateValue = EditorGUI.CurveField(position, label, (AnimationCurve)propertyValue);
                }
                else if (propertyType.IsEnum)
                {
                    updateValue = EditorGUI.EnumPopup(position, label, (Enum)propertyValue);
                }
                else
                {
                    throw new NotSupportedException("Invalide default type: " + propertyType.FullName);
                }

                if (EditorGUI.EndChangeCheck())
                {
                    property.SetValue(updateValue);
                }

                EndShowMixedValue();
            }
        }
Пример #14
0
 public static void RectField(Rect position, GUIContent label, PersistentProperty property)
 {
     MultiPropertyField2x2(position, label,
                           new[] { new GUIContent("X"), new GUIContent("Y"), new GUIContent("W"), new GUIContent("H") },
                           property.Find(new[] { "x", "y", "width", "height" }));
 }
Пример #15
0
 public static void Vector4Field(Rect position, GUIContent label, PersistentProperty property)
 {
     MultiPropertyField(position, label,
                        new[] { new GUIContent("X"), new GUIContent("Y"), new GUIContent("Z"), new GUIContent("W") },
                        property.Find(new[] { "x", "y", "z", "w" }));
 }
Пример #16
0
 public static void PropertyField(PersistentProperty property, params GUILayoutOption[] options)
 {
     PropertyField(new GUIContent(property.displayName), property, true, options);
 }
Пример #17
0
 public virtual void OnGUI(Rect position, PersistentProperty property, GUIContent label)
 {
 }
Пример #18
0
        protected override void OnGUI()
        {
            if (target == null)
            {
                EditorGUI.LabelField(nativeRect, Locale.L_Inspector, UserSetting.FrameTipsLabelStyle);
                return;
            }

            PersistentGUI.BeginLabelWidth(100);
            var brect   = EditorGUILayout.GetControlRect(false, EditorStyles.toolbarButton.fixedHeight);
            var tsize   = EditorStyles.toggle.CalcSize(GUIContent.none);
            var trect   = new Rect(brect.x + 5, brect.y + (brect.height - tsize.y) * 0.5f - 1, tsize.x, tsize.y);
            var lheight = EditorStyles.textField.CalcHeight(GUIContent.none, brect.width);
            var lrect   = new Rect(trect.xMax, brect.y + (brect.height - lheight) * 0.5f, brect.width - trect.xMax,
                                   lheight);

            PersistentGUI.PropertyField(trect, GUIContent.none, target.Find("enabled"));
            PersistentGUI.PropertyField(lrect, GUIContent.none, target.Find("name"));

            var nodes = target.GetValues <Node>();

            if (nodes.Length > 1)
            {
                PersistentGUILayout.PropertyField(target.Find("anchoredPosition"));
                PersistentGUILayout.PropertyField(target.Find("size"));
            }
            else
            {
                var node      = nodes[0];
                var anchorMin = node.anchorMin;
                var anchorMax = node.anchorMax;
                var labels    = new GUIContent[4];
                var props     = new PersistentProperty[4];
                if (anchorMin.x == anchorMax.x)
                {
                    labels[0] = new GUIContent("Pos X");
                    props[0]  = target.Find("anchoredPosition.x");
                    labels[2] = new GUIContent("Width");
                    props[2]  = target.Find("size.x");
                }
                else
                {
                    labels[0] = new GUIContent("Left");
                    props[0]  = target.Find("offsetMin.x");
                    labels[2] = new GUIContent("Right");
                    props[2]  = target.Find("offsetMax.x");
                }

                if (anchorMin.y == anchorMax.y)
                {
                    labels[1] = new GUIContent("Pos Y");
                    props[1]  = target.Find("anchoredPosition.y");
                    labels[3] = new GUIContent("Height");
                    props[3]  = target.Find("size.y");
                }
                else
                {
                    labels[1] = new GUIContent("Top");
                    props[1]  = target.Find("offsetMin.y");
                    labels[3] = new GUIContent("Bottom");
                    props[3]  = target.Find("offsetMax.y");
                }

                var position = EditorGUILayout.GetControlRect(false,
                                                              EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 2 : 3));
                position.height = EditorGUIUtility.singleLineHeight;
                PersistentGUI.MultiPropertyField2x2(position, new GUIContent("Position"), labels, props, 50);
            }

            PersistentGUILayout.PropertyField(target.Find("anchorMin"));
            PersistentGUILayout.PropertyField(target.Find("anchorMax"));
            PersistentGUILayout.PropertyField(target.Find("pivot"));
            PersistentGUILayout.FloatSlider(target.Find("localAngle"), 0f, 360f);
            PersistentGUILayout.PropertyField(target.Find("localScale"));

            var leafTypes = new List <Type>();

            foreach (var node in nodes)
            {
                var leaves = node.GetAllLeaves();
                foreach (var leaf in leaves)
                {
                    var leafType = leaf.GetType();
                    if (!leafTypes.Contains(leafType))
                    {
                        leafTypes.Add(leafType);
                    }
                }
            }

            leafTypes = leafTypes.FindAll(t => nodes.All(n => n.GetLeaf(t) != null));
            leafTypes.Sort((t1, t2) => String.Compare(t1.Name, t2.Name, StringComparison.Ordinal));
            foreach (var leafType in leafTypes)
            {
                var leaves = Array.ConvertAll(nodes, n => n.GetLeaf(leafType));
                var obj    = new PersistentObject(leaves);
                PersistentGUILayout.UserDrawerLayout(obj);
                EditorGUILayout.Space();
            }

            if (nodes.Length > 1 && nodes.Any(n => n.GetAllLeaves(true).Count() != leafTypes.Count))
            {
                EditorGUILayout.Separator();
                PersistentGUI.BeginColor(Color.yellow);
                EditorGUILayout.LabelField(Locale.L_MultiEditLeavesTips);
                PersistentGUI.EndColor();
            }

            EditorGUILayout.Separator();
            if (GUILayout.Button(Locale.L_AddLeaf, GUILayout.MaxWidth(100)))
            {
                var allTypes = CoreUtil.FindSubTypes(typeof(Leaf));
                Array.Sort(allTypes, (t1, t2) => String.Compare(t1.Name, t2.Name, StringComparison.Ordinal));
                var menu = new GenericMenu();
                foreach (var type in allTypes)
                {
                    var leafType = type;
                    menu.AddItem(new GUIContent(leafType.Name), false, () => { UserUtil.AddLeaf(nodes, leafType); });
                }

                menu.ShowAsContext();
            }

            PersistentGUI.EndLabelWidth();
        }
Пример #19
0
        public static void FloatSlider(PersistentProperty property, float leftValue, float rightValue)
        {
            var rect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight);

            PersistentGUI.FloatSlider(rect, new GUIContent(property.displayName), property, leftValue, rightValue);
        }