Ejemplo n.º 1
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(GUIContent label)
        {
            var entry = this.ValueEntry;

            if (!drawAsPreview)
            {
                if (entry.BaseValueType.IsInterface)
                {
                    entry.WeakSmartValue = SirenixEditorFields.PolymorphicObjectField(
                        label,
                        entry.WeakSmartValue,
                        entry.BaseValueType,
                        entry.Property.GetAttribute <AssetsOnlyAttribute>() == null);
                }
                else
                {
                    entry.WeakSmartValue = SirenixEditorFields.UnityObjectField(
                        label,
                        entry.WeakSmartValue as UnityEngine.Object,
                        entry.BaseValueType,
                        entry.Property.GetAttribute <AssetsOnlyAttribute>() == null);
                }
            }
            else
            {
                entry.WeakSmartValue = SirenixEditorFields.UnityPreviewObjectField(
                    label,
                    entry.WeakSmartValue as UnityEngine.Object,
                    entry.BaseValueType,
                    entry.Property.GetAttribute <AssetsOnlyAttribute>() == null,
                    GeneralDrawerConfig.Instance.SquareUnityObjectFieldHeight,
                    GeneralDrawerConfig.Instance.SquareUnityObjectAlignment);
            }
        }
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(GUIContent label)
        {
            var entry = this.ValueEntry;

            if (entry.ValueState == PropertyValueState.ReferenceValueConflict)
            {
                GUIHelper.PushGUIEnabled(GUI.enabled && entry.IsEditable);

                if (typeof(UnityEngine.Object).IsAssignableFrom(entry.TypeOfValue))
                {
                    bool prev = EditorGUI.showMixedValue;
                    EditorGUI.showMixedValue = true;
                    this.CallNextDrawer(label);
                    EditorGUI.showMixedValue = prev;
                }
                else
                {
                    bool prev = EditorGUI.showMixedValue;

                    EditorGUI.showMixedValue = true;
                    entry.SmartValue         = SirenixEditorFields.PolymorphicObjectField(label, entry.SmartValue, entry.BaseValueType, entry.Property.Info.GetAttribute <AssetsOnlyAttribute>() == null) as T;
                    EditorGUI.showMixedValue = prev;
                }

                GUIHelper.PopGUIEnabled();
            }
            else
            {
                this.CallNextDrawer(label);
            }
        }
Ejemplo n.º 3
0
        private void DrawInlinePropertyReferencePicker()
        {
            EditorGUI.BeginChangeCheck();
            var prev = EditorGUI.showMixedValue;

            if (this.ValueEntry.ValueState == PropertyValueState.ReferenceValueConflict)
            {
                EditorGUI.showMixedValue = true;
            }
            var newValue = SirenixEditorFields.PolymorphicObjectField(this.ValueEntry.WeakSmartValue, this.ValueEntry.BaseValueType, this.allowSceneObjects);

            EditorGUI.showMixedValue = prev;

            if (EditorGUI.EndChangeCheck())
            {
                this.ValueEntry.Property.Tree.DelayActionUntilRepaint(() =>
                {
                    this.ValueEntry.WeakValues[0] = newValue;
                    for (int j = 1; j < this.ValueEntry.ValueCount; j++)
                    {
                        this.ValueEntry.WeakValues[j] = SerializationUtility.CreateCopy(newValue);
                    }
                });
            }
        }
        private static void DrawObjectField(IPropertyValueEntry <T> entry, GUIContent label, ref bool isToggled, bool showToggle = true)
        {
            var prev = EditorGUI.showMixedValue;

            if (entry.ValueState == PropertyValueState.ReferenceValueConflict)
            {
                EditorGUI.showMixedValue = true;
            }

            object newValue;

            GUI.changed = false;
            if (showToggle == false)
            {
#pragma warning disable 0618 // Type or member is obsolete
                newValue = SirenixEditorGUI.ObjectField(entry, entry.BaseValueType, label, entry.SmartValue, entry.Property.Info.GetAttribute <AssetsOnlyAttribute>() == null);
#pragma warning restore 0618 // Type or member is obsolete
            }
            else if (label == null)
            {
                EditorGUI.indentLevel++;
#pragma warning disable 0618 // Type or member is obsolete
                newValue = SirenixEditorGUI.ObjectField(entry, entry.BaseValueType, label, entry.SmartValue, entry.Property.Info.GetAttribute <AssetsOnlyAttribute>() == null);
#pragma warning restore 0618 // Type or member is obsolete
                EditorGUI.indentLevel--;
            }
            else
            {
                newValue = SirenixEditorFields.PolymorphicObjectField(GUIHelper.TempContent("   " + label.text, label.tooltip), entry.SmartValue, entry.BaseValueType, entry.Property.Info.GetAttribute <AssetsOnlyAttribute>() == null);
            }
            if (GUI.changed)
            {
                //entry.WeakSmartValue = newValue;
                entry.Property.Tree.DelayActionUntilRepaint(() => entry.WeakSmartValue = newValue);
            }
            if (showToggle)
            {
                isToggled = SirenixEditorGUI.Foldout(GUILayoutUtility.GetLastRect(), isToggled, GUIContent.none);
            }

            EditorGUI.showMixedValue = prev;
        }
        protected override void DrawPropertyLayout(GUIContent label)
        {
            if (!(this.ValueEntry.ValueState == PropertyValueState.NullReference || this.ValueEntry.ValueState == PropertyValueState.ReferenceValueConflict))
            {
                this.CallNextDrawer(label);
                return;
            }

            if (Event.current.type == EventType.Layout)
            {
                this.isBroken = false;
                var count = this.ValueEntry.ValueCount;
                for (int i = 0; i < count; i++)
                {
                    var component = this.ValueEntry.Values[i];

                    if (ComponentIsBroken(component, ref this.realWrapperInstance))
                    {
                        this.isBroken = true;
                        break;
                    }
                }

                if (this.isBroken && autoFix)
                {
                    this.isBroken = false;

                    for (int i = 0; i < this.ValueEntry.ValueCount; i++)
                    {
                        T fixedComponent = null;
                        if (ComponentIsBroken(this.ValueEntry.Values[i], ref fixedComponent) && fixedComponent)
                        {
                            (this.ValueEntry as IValueEntryActualValueSetter <T>).SetActualValue(i, fixedComponent);
                        }
                    }

                    this.ValueEntry.Update();
                }
            }

            if (!this.isBroken)
            {
                this.CallNextDrawer(label);
                return;
            }

            var rect        = EditorGUILayout.GetControlRect(label != null);
            var btnRect     = rect.AlignRight(20);
            var controlRect = rect.SetXMax(btnRect.xMin - 5);

            object newInstance = null;

            EditorGUI.BeginChangeCheck();
            {
                if (this.ValueEntry.BaseValueType.IsInterface)
                {
                    newInstance = SirenixEditorFields.PolymorphicObjectField(controlRect,
                                                                             label,
                                                                             this.realWrapperInstance,
                                                                             this.ValueEntry.BaseValueType,
                                                                             this.allowSceneViewObjects);
                }
                else
                {
                    newInstance = SirenixEditorFields.UnityObjectField(
                        controlRect,
                        label,
                        this.realWrapperInstance,
                        this.ValueEntry.BaseValueType,
                        this.allowSceneViewObjects) as Component;
                }
            }
            if (EditorGUI.EndChangeCheck())
            {
                this.ValueEntry.WeakSmartValue = newInstance;
            }

            if (GUI.Button(btnRect, " ", EditorStyles.miniButton))
            {
                var popup = new FixBrokenUnityObjectWrapperPopup(this.ValueEntry);
                OdinEditorWindow.InspectObjectInDropDown(popup, 300);
            }

            if (Event.current.type == EventType.Repaint)
            {
                GUI.DrawTexture(btnRect, EditorIcons.ConsoleWarnicon, ScaleMode.ScaleToFit);
            }
        }
Ejemplo n.º 6
0
        private void DrawField(GUIContent label)
        {
            if (this.inlinePropertyAttr != null)
            {
                var pushLabelWidth = this.inlinePropertyAttr.LabelWidth > 0;
                if (label == null)
                {
                    if (pushLabelWidth)
                    {
                        GUIHelper.PushLabelWidth(this.inlinePropertyAttr.LabelWidth);
                    }
                    this.DrawInlinePropertyReferencePicker();
                    this.CallNextDrawer(null);
                    if (pushLabelWidth)
                    {
                        GUIHelper.PopLabelWidth();
                    }
                }
                else
                {
                    SirenixEditorGUI.BeginVerticalPropertyLayout(label);
                    this.DrawInlinePropertyReferencePicker();
                    if (pushLabelWidth)
                    {
                        GUIHelper.PushLabelWidth(this.inlinePropertyAttr.LabelWidth);
                    }
                    for (int i = 0; i < this.Property.Children.Count; i++)
                    {
                        var child = this.Property.Children[i];
                        child.Draw(child.Label);
                    }
                    if (pushLabelWidth)
                    {
                        GUIHelper.PopLabelWidth();
                    }
                    SirenixEditorGUI.EndVerticalPropertyLayout();
                }
            }
            else
            {
                Rect valueRect;
                bool hasKeyboadFocus;
                int  id;
                var  rect = SirenixEditorGUI.GetFeatureRichControlRect(null, out id, out hasKeyboadFocus, out valueRect);

                if (label != null)
                {
                    rect.width     = GUIHelper.BetterLabelWidth;
                    valueRect.xMin = rect.xMax;

                    if (this.drawChildren)
                    {
                        this.isToggled.Value = SirenixEditorGUI.Foldout(rect, this.isToggled.Value, label);
                    }
                    else if (Event.current.type == EventType.Repaint)
                    {
                        rect = EditorGUI.IndentedRect(rect);
                        GUI.Label(rect, label);
                    }
                }
                else if (this.drawChildren)
                {
                    if (EditorGUIUtility.hierarchyMode)
                    {
                        rect.width = 18;
                        var preev = EditorGUIUtility.hierarchyMode;
                        this.isToggled.Value = SirenixEditorGUI.Foldout(rect, this.isToggled.Value, GUIContent.none);
                    }
                    else
                    {
                        rect.width     = 18;
                        valueRect.xMin = rect.xMax;
                        var preev = EditorGUIUtility.hierarchyMode;
                        EditorGUIUtility.hierarchyMode = false;
                        this.isToggled.Value           = SirenixEditorGUI.Foldout(rect, this.isToggled.Value, GUIContent.none);
                        EditorGUIUtility.hierarchyMode = preev;
                    }
                }

                EditorGUI.BeginChangeCheck();
                var prev = EditorGUI.showMixedValue;
                if (this.ValueEntry.ValueState == PropertyValueState.ReferenceValueConflict)
                {
                    EditorGUI.showMixedValue = true;
                }
                var newValue = SirenixEditorFields.PolymorphicObjectField(valueRect, this.ValueEntry.WeakSmartValue, this.ValueEntry.BaseValueType, this.allowSceneObjects, hasKeyboadFocus, id);
                EditorGUI.showMixedValue = prev;

                if (EditorGUI.EndChangeCheck())
                {
                    this.ValueEntry.Property.Tree.DelayActionUntilRepaint(() =>
                    {
                        this.ValueEntry.WeakValues[0] = newValue;
                        for (int j = 1; j < this.ValueEntry.ValueCount; j++)
                        {
                            this.ValueEntry.WeakValues[j] = SerializationUtility.CreateCopy(newValue);
                        }
                    });
                }

                if (this.drawChildren)
                {
                    var toggle = this.ValueEntry.ValueState == PropertyValueState.NullReference ? false : this.isToggled.Value;
                    if (SirenixEditorGUI.BeginFadeGroup(this, toggle))
                    {
                        EditorGUI.indentLevel++;
                        this.CallNextDrawer(null);
                        EditorGUI.indentLevel--;
                    }
                    SirenixEditorGUI.EndFadeGroup();
                }
            }
        }
Ejemplo n.º 7
0
 private static Object _DrawSourcePicker(Object value, GUIContent label)
 {
     return((Object)SirenixEditorFields.PolymorphicObjectField(value, typeof(IImageSource),
                                                               true));
 }