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--;
            }
        }
Exemplo n.º 2
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);
        }
        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);
        }