Example #1
0
        private void DrawPropertySortableArray(Rect position, RuntimeSerializedProperty property, GUIContent label)
        {
            // Try to get the sortable list this property belongs to
            RuntimeReorderableListData listData = null;

            if (listDataDict.Count > 0)
            {
                listData = listDataDict.Find(data => property.PropertyPath.StartsWith(data.Parent));
            }

            UnityEditor.Editor scriptableEditor;
            bool isScriptableEditor = editableDict.TryGetValue(property.PropertyPath, out scriptableEditor);

            // Has ReorderableList and Try to show the list
            if (listData != null && listData.DoProperty(position, property))
            {
            }
            // Else try to draw ScriptableObject editor
            else if (isScriptableEditor)
            {
                bool hasHeader = property.HasAttribute <HeaderAttribute>();
                bool hasSpace  = property.HasAttribute <SpaceAttribute>();

                hasSpace |= hasHeader;

                // Reference type is not supported!
            }
            else
            {
                RuntimeEasyGUI.PropertyField(position, property, label, property.IsExpanded, null);
            }
        }
        private void DrawRuntimeObject(Rect position, RuntimeSerializedObject runtimeSerializedObject)
        {
            var prop           = runtimeSerializedObject.GetIterator();
            var height         = RuntimeEasyGUI.GetSinglePropertyHeight(prop, new GUIContent(prop.DisplayName));
            var headerPosition = new Rect(position.x, position.y, position.width, height);

            headerPosition.xMin += Space;
            prop.IsExpanded      = EditorGUI.Foldout(headerPosition, prop.IsExpanded, prop.DisplayName);
            RuntimeEasyGUI.PropertyField(headerPosition, prop, null);

            if (prop.IsExpanded)
            {
                var y = RuntimeEasyGUI.GetPropertyHeight(prop, null);
                EditorGUI.indentLevel++;
                while (prop.NextVisible(false))
                {
                    var mainPosition = new Rect(position.x, position.y + y, position.width, height);
                    mainPosition.xMin += Space;
                    height             = RuntimeEasyGUI.GetPropertyHeight(prop, new GUIContent(prop.DisplayName), prop.IsExpanded, null);
                    RuntimeEasyGUI.PropertyField(mainPosition, prop, new GUIContent(prop.DisplayName), prop.IsExpanded, null);
                    y += height;
                }
                EditorGUI.indentLevel--;
            }
        }
Example #3
0
        private string DoHeader(RuntimeSerializedProperty property, Rect position, string displayName)
        {
            displayName = string.IsNullOrEmpty(displayName) ? property.DisplayName : displayName;
            string headerName = string.Format(HeaderStr, displayName, property.ArraySize, property.HashCodeForPropertyPath());

            RuntimeEasyGUI.PropertyField(position, property, new GUIContent(headerName), false, null);
            return(headerName);
        }
        public void AddProperty(RuntimeSerializedProperty property)
        {
            // Check if this property actually belongs to the same direct child
            if (!property.GetRootPath().Equals(Parent))
            {
                return;
            }

            if (runtimeReorderableListDict.ContainsKey(property.PropertyPath))
            {
                return;
            }

            RuntimeReorderableList propList = new RuntimeReorderableList(
                property.RuntimeSerializedObject.SerializedObject, property,
                draggable: true, displayHeader: false,
                displayAddButton: true, displayRemoveButton: true)
            {
                headerHeight = 5
            };

            propList.drawElementBackgroundCallback = (Rect position, int index, bool active, bool focused) =>
            {
                if (DrawBackgroundCallback != null)
                {
                    Rect backgroundRect = new Rect(position);
                    if (index <= 0)
                    {
                        backgroundRect.yMin -= 8;
                    }
                    if (index >= propList.count - 1)
                    {
                        backgroundRect.yMax += 3;
                    }
                    EditorGUI.DrawRect(backgroundRect, DrawBackgroundCallback(active, focused));
                }
                else
                {
                    propList.drawElementBackgroundCallback = null;
                }
            };

            propList.drawElementCallback = (Rect position, int index, bool active, bool focused) =>
            {
                var iterProp    = property.GetArrayElementAtIndex(index);
                var elementName = iterProp.DisplayName;
                if (ElementNameCallback != null)
                {
                    elementName = ElementNameCallback(index);
                }
                RuntimeEasyGUI.PropertyField(position, iterProp, new GUIContent(elementName), ElementAttributes);
            };

            propList.elementHeightCallback = index => ElementHeightCallback(property, index);

            runtimeReorderableListDict.Add(property.PropertyPath, propList);
        }
Example #5
0
        public override float GetPropertyHeight(RuntimeSerializedProperty property, GUIContent label)
        {
            // Try to get the sortable list this property belongs to
            RuntimeReorderableListData listData = null;

            if (listDataDict.Count > 0)
            {
                listData = listDataDict.Find(data => property.PropertyPath.StartsWith(data.Parent));
            }

            return(listData != null?listData.GetPropertyHeight(property) : RuntimeEasyGUI.GetPropertyHeight(property, label, property.IsExpanded, null));
        }
        private float ElementHeightCallback(RuntimeSerializedProperty property, int index)
        {
            var height      = 3f;
            var iterProp    = property.GetArrayElementAtIndex(index);
            var elementName = iterProp.DisplayName;

            if (ElementNameCallback != null)
            {
                elementName = ElementNameCallback(index);
            }
            height += RuntimeEasyGUI.GetPropertyHeight(iterProp, new GUIContent(elementName), ElementAttributes);

            return(height);
        }
        private float GetRuntimeObjectHeight(RuntimeSerializedObject runtimeSerializedObject)
        {
            var height = 0f;
            var prop   = runtimeSerializedObject.GetIterator();

            height += RuntimeEasyGUI.GetSinglePropertyHeight(prop, new GUIContent(prop.DisplayName));
            if (prop.IsExpanded)
            {
                while (prop.NextVisible(false))
                {
                    height += RuntimeEasyGUI.GetPropertyHeight(prop, new GUIContent(prop.DisplayName), prop.IsExpanded, null);
                }
            }
            return(height);
        }
Example #8
0
        protected virtual void EmitPropertyField(Rect position, RuntimeSerializedProperty runtimeSerializedProperty, GUIContent label)
        {
            var multiline = GetMultilineAttribute();

            if (multiline == null)
            {
                var range = GetRangeAttribute();
                if (range == null)
                {
                    RuntimeEasyGUI.PropertyField(position, runtimeSerializedProperty, label, true, null);
                }
                else
                {
                    if (runtimeSerializedProperty.PropertyType == RuntimeSerializedPropertyType.Float)
                    {
                        RuntimeEasyGUI.Slider(position, runtimeSerializedProperty, range.Min, range.Max, label);
                    }
                    else if (runtimeSerializedProperty.PropertyType == RuntimeSerializedPropertyType.Integer)
                    {
                        RuntimeEasyGUI.IntSlider(position, runtimeSerializedProperty, (int)range.Min, (int)range.Max, label);
                    }
                    else
                    {
                        EditorGUI.LabelField(position, label.text, "Use Range with float or int.");
                    }
                }
            }
            else
            {
                var property = runtimeSerializedProperty;

                label = RuntimeEasyGUI.BeginProperty(position, label, property);
                var method = typeof(EditorGUI).GetMethod("MultiFieldPrefixLabel", BindingFlags.Static | BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.NonPublic);
                position = (Rect)method.Invoke(null, new object[] { position, 0, label, 1 });

                EditorGUI.BeginChangeCheck();
                int indentLevel = EditorGUI.indentLevel;
                EditorGUI.indentLevel = 0;
                var stringValue = EditorGUI.TextArea(position, property.StringValue);
                EditorGUI.indentLevel = indentLevel;
                if (EditorGUI.EndChangeCheck())
                {
                    property.StringValue = stringValue;
                }
                RuntimeEasyGUI.EndProperty();
            }
        }
        public override void OnGUI(Rect position, RuntimeSerializedProperty property, GUIContent label)
        {
            RangeAttribute rangeAttribute = Attribute as RangeAttribute;

            if (property.PropertyType == RuntimeSerializedPropertyType.Float)
            {
                RuntimeEasyGUI.Slider(position, property, rangeAttribute.min, rangeAttribute.max, label);
            }
            else if (property.PropertyType == RuntimeSerializedPropertyType.Integer)
            {
                RuntimeEasyGUI.IntSlider(position, property, (int)rangeAttribute.min, (int)rangeAttribute.max, label);
            }
            else
            {
                EditorGUI.LabelField(position, label.text, "Use Range with float or int.");
            }
        }
        public float GetHeight(RuntimeSerializedProperty property, GUIContent label, bool includeChildren)
        {
            float height = 0;

            if (DecoratorDrawers != null && !IsCurrentlyNested)
            {
                foreach (var drawer in DecoratorDrawers)
                {
                    height += drawer.GetHeight();
                }
            }

            if (RuntimePropertyDrawer != null)
            {
                height += RuntimePropertyDrawer.GetPropertyHeightSafe(property, label ?? EditorGUIUtilityHelper.TempContent(property.DisplayName));
            }
            else if (!includeChildren)
            {
                height += RuntimeEasyGUI.GetSinglePropertyHeight(property, label);
            }
            else
            {
                RuntimeSerializedProperty prop = property.Copy();

                // First property with custom label
                height += RuntimeEasyGUI.GetSinglePropertyHeight(prop, label);
                bool childrenAreExpanded = prop.IsExpanded && RuntimeEasyGUI.HasVisibleChildFields(prop);

                // Loop through all child properties
                if (childrenAreExpanded)
                {
                    RuntimeSerializedProperty endProperty = prop.GetEndProperty();
                    while (prop.NextVisible(childrenAreExpanded) && !RuntimeSerializedProperty.EqualContents(prop, endProperty))
                    {
                        height += RuntimeScriptAttributeUtility.GetHandler(prop, null).GetHeight(prop, EditorGUIUtilityHelper.TempContent(prop.DisplayName), true);
                        childrenAreExpanded = false;
                        height += EasyGUI.kControlVerticalSpacing;
                    }
                }
            }

            return(height);
        }
        public bool OnGUI(Rect position, RuntimeSerializedProperty property, GUIContent label, bool includeChildren, Rect visibleArea)
        {
            float oldLabelWidth, oldFieldWidth;
            float propHeight = position.height;

            position.height = 0;
            if (DecoratorDrawers != null && !IsCurrentlyNested)
            {
                foreach (var decorator in DecoratorDrawers)
                {
                    position.height = decorator.GetHeight();

                    oldLabelWidth = EditorGUIUtility.labelWidth;
                    oldFieldWidth = EditorGUIUtility.fieldWidth;
                    decorator.OnGUI(position);
                    EditorGUIUtility.labelWidth = oldLabelWidth;
                    EditorGUIUtility.fieldWidth = oldFieldWidth;

                    position.y += position.height;
                    propHeight -= position.height;
                }
            }

            position.height = propHeight;
            if (RuntimePropertyDrawer != null)
            {
                // Remember widths
                oldLabelWidth = EditorGUIUtility.labelWidth;
                oldFieldWidth = EditorGUIUtility.fieldWidth;
                // Draw with custom drawer
                RuntimePropertyDrawer.OnGUISafe(position, property, label ?? EditorGUIUtilityHelper.TempContent(property.DisplayName));
                // Restore widths
                EditorGUIUtility.labelWidth = oldLabelWidth;
                EditorGUIUtility.fieldWidth = oldFieldWidth;

                return(false);
            }
            else
            {
                if (!includeChildren)
                {
                    return(RuntimeEasyGUI.DefaultPropertyField(position, property, label));
                }
                // Remember state
                Vector2 oldIconSize = EditorGUIUtility.GetIconSize();
                bool    wasEnabled  = GUI.enabled;
                int     origIndent  = EditorGUI.indentLevel;

                int relIndent = origIndent - property.Depth;

                RuntimeSerializedProperty prop = property.Copy();

                position.height = RuntimeEasyGUI.GetSinglePropertyHeight(property, label);

                // First property with custom label
                EditorGUI.indentLevel = property.Depth + relIndent;
                bool childrenAreExpanded = RuntimeEasyGUI.DefaultPropertyField(position, property, label) && RuntimeEasyGUI.HasVisibleChildFields(property);
                position.y += position.height + EasyGUI.kControlVerticalSpacing;

                // Loop through all child properties
                if (childrenAreExpanded)
                {
                    RuntimeSerializedProperty endProperty = property.GetEndProperty();
                    while (prop.NextVisible(childrenAreExpanded) && !RuntimeSerializedProperty.EqualContents(prop, endProperty))
                    {
                        var handler = RuntimeScriptAttributeUtility.GetHandler(prop, null);
                        EditorGUI.indentLevel = prop.Depth + relIndent;
                        position.height       = handler.GetHeight(prop, null, false);

                        if (position.Overlaps(visibleArea))
                        {
                            EditorGUI.BeginChangeCheck();
                            childrenAreExpanded = handler.OnGUI(position, prop, null, false) && RuntimeEasyGUI.HasVisibleChildFields(prop);
                            // Changing child properties (like array size) may invalidate the iterator,
                            // so stop now, or we may get errors.
                            if (EditorGUI.EndChangeCheck())
                            {
                                break;
                            }
                        }

                        position.y += position.height + EasyGUI.kControlVerticalSpacing;
                    }
                }

                // Restore state
                GUI.enabled = wasEnabled;
                EditorGUIUtility.SetIconSize(oldIconSize);
                EditorGUI.indentLevel = origIndent;

                return(false);
            }
        }
        public bool DoProperty(Rect position, RuntimeSerializedProperty property)
        {
            if (!runtimeReorderableListDict.ContainsKey(property.PropertyPath))
            {
                return(false);
            }

            headerPosition        = new Rect(position);
            headerPosition.height = RuntimeEasyGUI.GetPropertyHeight(property, GUIContent.none, false, null);
            // Draw the background
            if (DrawBackgroundCallback != null)
            {
                Rect backgroundPosition = new Rect(headerPosition);
                backgroundPosition.xMin += EasyGUI.Indent;
                if (property.IsExpanded)
                {
                    backgroundPosition.yMax += 19;
                }
                EditorGUI.DrawRect(backgroundPosition, DrawBackgroundCallback(false, false));
            }

            // Draw header
            if (HeaderCallback != null)
            {
                HeaderCallback(headerPosition);
            }
            else
            {
                string headerName = string.Format(HeaderStr, property.DisplayName, property.ArraySize, property.HashCodeForPropertyPath());
                RuntimeEasyGUI.PropertyField(headerPosition, property, new GUIContent(headerName), false, null);
            }

            // Draw the reorderable list for the property
            if (property.IsExpanded)
            {
                EditorGUI.BeginDisabledGroup(!Editable);
                if (!property.Editable)
                {
                    EditorGUI.indentLevel++;
                }
                EditorGUI.BeginChangeCheck();
                var sizePosition = new Rect(headerPosition);
                sizePosition.yMin   = headerPosition.yMax;
                sizePosition.height = EditorGUIUtility.singleLineHeight;
                var newArraySize = Mathf.Clamp(EditorGUI.IntField(sizePosition, SizeStr, property.ArraySize), 0, int.MaxValue);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(property.RuntimeSerializedObject.TargetObject, SetArraySizeStr);
                    property.ArraySize = newArraySize;
                    EditorUtility.SetDirty(property.RuntimeSerializedObject.TargetObject);
                }
                var listPosition = new Rect(sizePosition);
                listPosition.xMin += EasyGUI.Indent;
                listPosition.yMin  = sizePosition.yMax;
                var indentLevel = EditorGUI.indentLevel;
                EditorGUI.indentLevel = 0;
                runtimeReorderableListDict[property.PropertyPath].DoList(listPosition);
                EditorGUI.indentLevel = indentLevel;
                if (!property.Editable)
                {
                    EditorGUI.indentLevel--;
                }
                EditorGUI.EndDisabledGroup();
            }

            return(true);
        }
Example #13
0
 public virtual void OnGUI(Rect position, RuntimeSerializedProperty property, GUIContent label)
 {
     RuntimeEasyGUI.DefaultPropertyField(position, property, label);
     EditorGUI.LabelField(position, label, EditorGUIUtilityHelper.TempContent("No GUI Implemented"));
 }