Example #1
0
        public object OnSceneGUI(object element)
        {
            try {
                if (_cycleScene == null)
                {
                    _cycleScene = new fiCycleDetector(_cycleEdit, _cycleHeight);
                }
                _cycleScene.Enter();

                // cycle; don't do anything
                if (_cycleScene.TryMark(element) == false)
                {
                    return(element);
                }

                // Not showing a scene GUI for the object for this frame should be fine
                if (element == null)
                {
                    return(element);
                }

                var inspectedProperties = _metadata.GetProperties(InspectedMemberFilters.InspectableMembers);
                for (int i = 0; i < inspectedProperties.Count; ++i)
                {
                    var property = inspectedProperties[i];

                    var             editorChain = PropertyEditor.Get(property.StorageType, property.MemberInfo);
                    IPropertyEditor editor      = editorChain.FirstEditor;

                    object currentValue = property.Read(element);
                    object updatedValue = editor.OnSceneGUI(currentValue);

                    // We use EqualityComparer instead of == because EqualityComparer will properly unbox structs
                    if (EqualityComparer <object> .Default.Equals(currentValue, updatedValue) == false)
                    {
                        property.Write(element, updatedValue);
                    }
                }

                return(element);
            }
            finally {
                _cycleScene.Exit();
                if (_cycleScene.Depth == 0)
                {
                    _cycleScene = null;
                }
            }
        }
Example #2
0
        public float GetElementHeight(GUIContent label, object element, fiGraphMetadata metadata)
        {
            try {
                if (_cycleHeight == null)
                {
                    _cycleHeight = new fiCycleDetector(_cycleEdit, _cycleScene);
                }
                _cycleHeight.Enter();

                if (_cycleHeight.TryMark(element) == false)
                {
                    return(EditorStyles.label.CalcHeight(GUIContent.none, 100));
                }

                float height = HasLabel(label) ? TitleHeight + fiRectUtility.IndentVertical : 0;

                if (element == null)
                {
                    // if the user want's an instance, we'll create one right away. We also check to
                    // make sure we should automatically instantiate references, as if we're pretty
                    // far down in the nesting level there may be an infinite recursion going on
                    if (fiSettings.InspectorAutomaticReferenceInstantation &&
                        _metadata.HasDefaultConstructor &&
                        ShouldAutoInstantiate())
                    {
                        element     = _metadata.CreateInstance();
                        GUI.changed = true;
                    }

                    // otherwise we show a button to create an instance
                    else
                    {
                        height += ButtonHeight;
                    }
                }

                if (element != null)
                {
                    // figure out which members we should display
                    List <InspectedMember> displayableMembers;
                    var categories = _metadata.GetCategories(InspectedMemberFilters.InspectableMembers);
                    if (categories.Count > 0)
                    {
                        var selectedCategoryMetadata = metadata.GetMetadata <SelectedCategoryMetadata>();
                        height            += CategoryToolbarHeight + fiLateBindings.EditorGUIUtility.standardVerticalSpacing;
                        displayableMembers = categories.Values.ElementAt(selectedCategoryMetadata.SelectedCategoryIndex);
                    }
                    else
                    {
                        displayableMembers = _metadata.GetMembers(InspectedMemberFilters.InspectableMembers);
                    }

                    // compute the height of the members we will display
                    for (int i = 0; i < displayableMembers.Count; ++i)
                    {
                        var member = displayableMembers[i];

                        // requested skip
                        if (ShouldShowMemberDynamic(element, member.MemberInfo) == false)
                        {
                            continue;
                        }

                        var childMetadata = metadata.Enter(member.Name);

                        if (member.IsMethod)
                        {
                            height += ButtonHeight;
                        }
                        else
                        {
                            fiGraphMetadataCallbacks.PropertyMetadataCallback(childMetadata.Metadata, member.Property);
                            height += fiEditorGUI.EditPropertyHeight(element, member.Property, childMetadata);
                        }

                        height += DividerHeight;
                    }

                    // Remove the last divider
                    if (displayableMembers.Count > 0)
                    {
                        height -= DividerHeight;
                    }
                }

                return(height);
            }
            finally {
                _cycleHeight.Exit();
                if (_cycleHeight.Depth == 0)
                {
                    _cycleHeight = null;
                }
            }
        }
Example #3
0
        public object Edit(Rect region, GUIContent label, object element, fiGraphMetadata metadata)
        {
            try {
                if (_cycleEdit == null)
                {
                    _cycleEdit = new fiCycleDetector(_cycleHeight, _cycleScene);
                }
                _cycleEdit.Enter();

                if (_cycleEdit.TryMark(element) == false)
                {
                    EditorGUI.LabelField(region, label, new GUIContent("<cycle>"));
                    return(element);
                }

                if (HasLabel(label))
                {
                    region = DrawLabel(region, label);
                }

                if (element == null)
                {
                    // if the user want's an instance, we'll create one right away We also check to
                    // make sure we should automatically instantiate references, as if we're pretty
                    // far down in the nesting level there may be an infinite recursion going on
                    if (fiSettings.InspectorAutomaticReferenceInstantation &&
                        _metadata.HasDefaultConstructor &&
                        ShouldAutoInstantiate())
                    {
                        element     = _metadata.CreateInstance();
                        GUI.changed = true;
                    }

                    // otherwise we show a button to create an instance
                    else
                    {
                        string buttonMessage = "null - create instance (ctor)?";
                        if (_metadata.HasDefaultConstructor == false)
                        {
                            buttonMessage = "null - create instance (unformatted)?";
                        }
                        if (fiEditorGUI.LabeledButton(region, _metadata.ReflectedType.Name, buttonMessage))
                        {
                            element     = _metadata.CreateInstance();
                            GUI.changed = true;
                        }

                        return(element);
                    }
                }

                return(EditPropertiesButtons(label, region, element, metadata));
            }
            finally {
                _cycleEdit.Exit();
                if (_cycleEdit.Depth == 0)
                {
                    _cycleEdit = null;
                }
            }
        }
        public object OnSceneGUI(object element) {
            try {
                if (_cycleScene == null) {
                    _cycleScene = new fiCycleDetector(_cycleEdit, _cycleHeight);
                }
                _cycleScene.Enter();

                // cycle; don't do anything
                if (_cycleScene.TryMark(element) == false) {
                    return element;
                }

                // Not showing a scene GUI for the object for this frame should be fine
                if (element == null) {
                    return element;
                }

                var inspectedProperties = _metadata.GetProperties(InspectedMemberFilters.InspectableMembers);
                for (int i = 0; i < inspectedProperties.Count; ++i) {
                    var property = inspectedProperties[i];

                    var editorChain = PropertyEditor.Get(property.StorageType, property.MemberInfo);
                    IPropertyEditor editor = editorChain.FirstEditor;

                    object currentValue = property.Read(element);
                    object updatedValue = editor.OnSceneGUI(currentValue);

                    // We use EqualityComparer instead of == because EqualityComparer will properly unbox structs
                    if (EqualityComparer<object>.Default.Equals(currentValue, updatedValue) == false) {
                        property.Write(element, updatedValue);
                    }
                }

                return element;
            }
            finally {
                _cycleScene.Exit();
                if (_cycleScene.Depth == 0) {
                    _cycleScene = null;
                }
            }
        }
        public float GetElementHeight(GUIContent label, object element, fiGraphMetadata metadata) {
            try {
                if (_cycleHeight == null) {
                    _cycleHeight = new fiCycleDetector(_cycleEdit, _cycleScene);
                }
                _cycleHeight.Enter();

                if (_cycleHeight.TryMark(element) == false) {
                    return EditorStyles.label.CalcHeight(GUIContent.none, 100);
                }

                float height = HasLabel(label) ? TitleHeight + fiRectUtility.IndentVertical : 0;

                if (element == null) {
                    // if the user want's an instance, we'll create one right away. We also check to
                    // make sure we should automatically instantiate references, as if we're pretty
                    // far down in the nesting level there may be an infinite recursion going on
                    if (fiSettings.InspectorAutomaticReferenceInstantation &&
                        _metadata.HasDefaultConstructor &&
                        ShouldAutoInstantiate()) {

                        element = _metadata.CreateInstance();
                        GUI.changed = true;
                    }

                    // otherwise we show a button to create an instance
                    else {
                        height += ButtonHeight;
                    }
                }

                if (element != null) {
                    // figure out which members we should display
                    List<InspectedMember> displayableMembers;
                    var categories = _metadata.GetCategories(InspectedMemberFilters.InspectableMembers);
                    if (categories.Count > 0) {
                        var selectedCategoryMetadata = metadata.GetMetadata<SelectedCategoryMetadata>();
                        height += CategoryToolbarHeight + EditorGUIUtility.standardVerticalSpacing;
                        displayableMembers = categories.Values.ElementAt(selectedCategoryMetadata.SelectedCategoryIndex);
                    }
                    else {
                        displayableMembers = _metadata.GetMembers(InspectedMemberFilters.InspectableMembers);
                    }

                    // compute the height of the members we will display
                    for (int i = 0; i < displayableMembers.Count; ++i) {
                        var member = displayableMembers[i];

                        // requested skip
                        if (ShouldShowMemberDynamic(element, member.MemberInfo) == false) {
                            continue;
                        }

                        var childMetadata = metadata.Enter(member.Name);

                        if (member.IsMethod) {
                            height += ButtonHeight;
                        }
                        else {
                            fiGraphMetadataCallbacks.PropertyMetadataCallback(childMetadata.Metadata, member.Property);
                            height += fiEditorGUI.EditPropertyHeight(element, member.Property, childMetadata);
                        }

                        height += DividerHeight;
                    }

                    // Remove the last divider
                    if (displayableMembers.Count > 0) height -= DividerHeight;
                }

                return height;
            }
            finally {
                _cycleHeight.Exit();
                if (_cycleHeight.Depth == 0) {
                    _cycleHeight = null;
                }
            }
        }
        public object Edit(Rect region, GUIContent label, object element, fiGraphMetadata metadata) {
            try {
                if (_cycleEdit == null) {
                    _cycleEdit = new fiCycleDetector(_cycleHeight, _cycleScene);
                }
                _cycleEdit.Enter();

                if (_cycleEdit.TryMark(element) == false) {
                    EditorGUI.LabelField(region, label, new GUIContent("<cycle>"));
                    return element;
                }

                if (HasLabel(label)) {
                    region = DrawLabel(region, label);
                }

                if (element == null) {
                    // if the user want's an instance, we'll create one right away We also check to
                    // make sure we should automatically instantiate references, as if we're pretty
                    // far down in the nesting level there may be an infinite recursion going on
                    if (fiSettings.InspectorAutomaticReferenceInstantation &&
                        _metadata.HasDefaultConstructor &&
                        ShouldAutoInstantiate()) {

                        element = _metadata.CreateInstance();
                        GUI.changed = true;
                    }

                    // otherwise we show a button to create an instance
                    else {
                        string buttonMessage = "null - create instance (ctor)?";
                        if (_metadata.HasDefaultConstructor == false) {
                            buttonMessage = "null - create instance (unformatted)?";
                        }
                        if (fiEditorGUI.LabeledButton(region, _metadata.ReflectedType.Name, buttonMessage)) {
                            element = _metadata.CreateInstance();
                            GUI.changed = true;
                        }

                        return element;
                    }
                }

                return EditPropertiesButtons(label, region, element, metadata);

            }
            finally {
                _cycleEdit.Exit();
                if (_cycleEdit.Depth == 0) {
                    _cycleEdit = null;
                }
            }
        }