Пример #1
0
        public InspectableProperty GetFixedBufferElementAtIndex(int index)
        {
            InspectableProperty property = Copy();
            InspectableProperty result   = null;

            if (index >= 0 && index < property.FixedBufferSize)
            {
                int i = 0;
                if (property.NextVisible(true))
                {
                    property.NextVisible(false);
                    do
                    {
                        if (i == index)
                        {
                            result = property;
                            break;
                        }
                        i++;
                    } while (property.NextVisible(false));
                }
            }
            else
            {
                result = null;
            }
            return(result);
        }
Пример #2
0
            public bool MoveNext()
            {
                uint num = (uint)position;

                position = -1;
                switch (num)
                {
                case 0:
                    if (!target.IsArray)
                    {
                        end = target.GetEndProperty();
                        if (target.NextVisible(true) && !InspectableProperty.EqualContents(target, end))
                        {
                            current = target;
                            if (!disposing)
                            {
                                position = 2;
                            }
                            return(true);
                        }
                        position = -1;
                        return(false);
                    }
                    index = 0;
                    break;

                case 1:
                    index++;
                    break;

                case 2:
                    if (target.NextVisible(true) && !InspectableProperty.EqualContents(target, end))
                    {
                        current = target;
                        if (!disposing)
                        {
                            position = 2;
                        }
                        return(true);
                    }
                    position = -1;
                    return(false);

                default:
                    return(false);
                }
                if (index >= target.ArraySize)
                {
                    position = -1;
                    return(false);
                }
                current = target.GetArrayElementAtIndex(index);
                if (!disposing)
                {
                    position = 1;
                }
                return(true);
            }
Пример #3
0
        public InspectableProperty GetEndProperty(bool includeInVisible = false)
        {
            InspectableProperty property = Copy();

            if (includeInVisible)
            {
                property.Next(false);
                return(property);
            }
            property.NextVisible(false);
            return(property);
        }
Пример #4
0
        private void FindTargetProperties(InspectableProperty property)
        {
            listIndex.Clear();
            editableIndex.Clear();

            var depth = property.Depth;

            do
            {
                if (property.IsArray && property.PropertyType != InspectablePropertyType.String)
                {
                    var canTurnToList = property.HasAttribute <ReorderableAttribute>();
                    if (canTurnToList)
                    {
                        CreateListData(property.InspectableObject.FindProperty(property.PropertyPath));
                    }
                }

                if (property.PropertyType.IsSubclassOf(InspectablePropertyType.Object))
                {
                    var propType = property.GetTypeReflection();
                    if (propType == null)
                    {
                        continue;
                    }
                    var isScriptable = propType.IsSubclassOf(scriptableObjectType);
                    if (isScriptable)
                    {
                        var makeEditable = property.HasAttribute <ReorderableAttribute>();
                        if (makeEditable)
                        {
                            UnityEditor.Editor scriptableEditor = null;
                            if (property.ObjectReference != null)
                            {
                                UnityEditor.Editor.CreateCachedEditorWithContext(property.ObjectReference,
                                                                                 property.InspectableObject.SerializedObject.targetObject, null,
                                                                                 ref scriptableEditor);
                            }
                            editableIndex.Add(property.PropertyPath, scriptableEditor);
                        }
                    }
                }
            } while (property.Depth < depth && property.NextVisible(true));

            isInitialized = true;
        }
        public float GetHeight(InspectableProperty property, GUIContent label, bool includeChildren)
        {
            float height = 0;

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

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

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

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

            return(height);
        }
        public bool OnGUI(Rect position, InspectableProperty 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 (InspectableDrawer != null)
            {
                // Remember widths
                oldLabelWidth = EditorGUIUtility.labelWidth;
                oldFieldWidth = EditorGUIUtility.fieldWidth;
                // Draw with custom drawer
                InspectableDrawer.OnGUISafe(position, property.Copy(), label ?? EditorGUIUtilityHelper.TempContent(property.DisplayName));
                // Restore widths
                EditorGUIUtility.labelWidth = oldLabelWidth;
                EditorGUIUtility.fieldWidth = oldFieldWidth;

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

                int relIndent = origIndent - property.Depth;

                InspectableProperty prop = property.Copy();

                position.height = EasyGUI.GetSinglePropertyHeight(prop, label);

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

                // Loop through all child properties
                if (childrenAreExpanded)
                {
                    InspectableProperty endProperty = property.GetEndProperty();
                    while (prop.NextVisible(childrenAreExpanded) && !InspectableProperty.EqualContents(prop, endProperty))
                    {
                        var handler = InspectableAttributeUtility.GetHandler(prop);
                        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) && EasyGUI.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);
            }
        }