Ejemplo n.º 1
0
        public object Edit(Rect region, GUIContent label, object element, fiGraphMetadata metadata)
        {
            // draw the nullable type toggle
            {
                int labelHeight = (int)EditorStyles.label.CalcHeight(GUIContent.none, 100);

                Rect toggleRegion = new Rect(region);
                toggleRegion.height = labelHeight;
                region.y           += toggleRegion.height;
                region.height      -= toggleRegion.height;

                if (EditorGUI.Toggle(toggleRegion, label, element != null))
                {
                    if (element == null)
                    {
                        element     = _elementType.CreateInstance();
                        GUI.changed = true;
                    }
                }
                else
                {
                    element = null;
                }
            }

            // no element; no editor
            if (element == null)
            {
                return(null);
            }

            // we have a value for the nullable type; draw the property editor
            {
                Rect selectedRegion = new Rect(region);
                selectedRegion = fiRectUtility.IndentedRect(selectedRegion);
                region.y      += selectedRegion.height;
                region.height -= selectedRegion.height;

                // show custom editor
                PropertyEditorChain chain  = PropertyEditor.Get(element.GetType(), null);
                IPropertyEditor     editor = chain.SkipUntilNot(typeof(NullablePropertyEditor));

                return(editor.Edit(selectedRegion, GUIContent.none, element, metadata.Enter("NullableEditor", metadata.Context)));
            }
        }
Ejemplo n.º 2
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;
                }
            }
        }