コード例 #1
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(IPropertyValueEntry <T> entry, GUIContent label)
        {
            if (entry.ValueState == PropertyValueState.Reference)
            {
                var isToggled  = entry.Context.GetPersistent(this, "is_Toggled", false);
                var targetProp = entry.Property.Tree.GetPropertyAtPath(entry.TargetReferencePath);

                AllEditorGUI.BeginBox();

                AllEditorGUI.BeginBoxHeader();
                EditorGUILayout.BeginHorizontal();

                isToggled.Value = label != null?AllEditorGUI.Foldout(isToggled.Value, label)
                                      : AllEditorGUI.Foldout(isToggled.Value, GUIHelper.TempContent(""));

                if (targetProp.Parent == null)
                {
                    EditorGUILayout.LabelField("Reference to " + targetProp.Path, SirenixGUIStyles.RightAlignedGreyMiniLabel);
                }
                else
                {
                    EditorGUILayout.LabelField("Reference to " + targetProp.Path, SirenixGUIStyles.RightAlignedGreyMiniLabel);
                }

                EditorGUILayout.EndHorizontal();
                AllEditorGUI.EndBoxHeader();

                if (AllEditorGUI.BeginFadeGroup(UniqueDrawerKey.Create(entry.Property, this), isToggled.Value))
                {
                    //EditorGUI.indentLevel++;
                    //GUIHelper.PushGUIEnabled(true);

                    var  isInReference = targetProp.Context.GetGlobal("is_in_reference", false);
                    bool previous      = isInReference.Value;
                    isInReference.Value = true;

                    InspectorUtilities.DrawProperty(targetProp);

                    isInReference.Value = previous;

                    //GUIHelper.PopGUIEnabled();
                    //EditorGUI.indentLevel--;
                }
                AllEditorGUI.EndFadeGroup();
                AllEditorGUI.EndBox();
            }
            else
            {
                this.CallNextDrawer(entry.Property, label);
            }
        }
コード例 #2
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(IPropertyValueEntry <ColorPalette> entry, GUIContent label)
        {
            var isEditing = entry.Property.Context.Get(this, "isEditing", false);

            entry.SmartValue.Name = entry.SmartValue.Name ?? "Palette Name";

            AllEditorGUI.BeginBox();
            {
                AllEditorGUI.BeginBoxHeader();
                {
                    GUILayout.Label(entry.SmartValue.Name);
                    GUILayout.FlexibleSpace();
                    if (AllEditorGUI.IconButton(EditorIcons.Pen))
                    {
                        isEditing.Value = !isEditing.Value;
                    }
                }
                AllEditorGUI.EndBoxHeader();

                if (entry.SmartValue.Colors == null)
                {
                    entry.SmartValue.Colors = new List <Color>();
                }

                if (AllEditorGUI.BeginFadeGroup(entry.SmartValue, entry, isEditing.Value))
                {
                    this.CallNextDrawer(entry.Property, null);
                }
                AllEditorGUI.EndFadeGroup();

                if (AllEditorGUI.BeginFadeGroup(entry.SmartValue, entry.SmartValue, isEditing.Value == false))
                {
                    Color col = default(Color);

                    var stretch = ColorPaletteManager.Instance.StretchPalette;
                    var size    = ColorPaletteManager.Instance.SwatchSize;
                    var margin  = ColorPaletteManager.Instance.SwatchSpacing;
                    ColorPaletteAttributeDrawer.DrawColorPaletteColorPicker(entry, entry.SmartValue, ref col, entry.SmartValue.ShowAlpha, stretch, size, 20, margin);
                }
                AllEditorGUI.EndFadeGroup();
            }
            AllEditorGUI.EndBox();
        }
コード例 #3
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyGroupLayout(InspectorProperty property, FoldoutGroupAttribute attribute, GUIContent label)
        {
            var context = property.Context.Get <FoldoutGroupContext>(this, "FoldoutGroupContext", (FoldoutGroupContext)null);

            if (context.Value == null)
            {
                context.Value = new FoldoutGroupContext()
                {
                    IsVisible   = property.Context.GetPersistent <bool>(this, "IsVisible", attribute.HasDefinedExpanded ? attribute.Expanded : AllEditorGUI.ExpandFoldoutByDefault),
                    TitleHelper = new StringMemberHelper(property.ParentType, attribute.GroupName)
                };
            }

            if (context.Value.TitleHelper.ErrorMessage != null)
            {
                AllEditorGUI.ErrorMessageBox(context.Value.TitleHelper.ErrorMessage);
            }

            AllEditorGUI.BeginBox();
            {
                AllEditorGUI.BeginBoxHeader();
                var content = GUIHelper.TempContent(context.Value.TitleHelper.GetString(property));
                var rect    = GUILayoutUtility.GetRect(content, SirenixGUIStyles.Label);
                context.Value.IsVisible.Value = AllEditorGUI.Foldout(rect, context.Value.IsVisible.Value, content);
                AllEditorGUI.EndBoxHeader();

                if (AllEditorGUI.BeginFadeGroup(context, context.Value.IsVisible.Value))
                {
                    for (int i = 0; i < property.Children.Count; i++)
                    {
                        InspectorUtilities.DrawProperty(property.Children[i]);
                    }
                }

                AllEditorGUI.EndFadeGroup();
            }
            AllEditorGUI.EndBox();
        }
コード例 #4
0
        /// <summary>
        /// Not yet documented.
        /// </summary>
        protected override void DrawPropertyLayout(IPropertyValueEntry <Color> entry, ColorPaletteAttribute attribute, GUIContent label)
        {
            AllEditorGUI.BeginIndentedHorizontal();
            {
                var hideLabel = label == null;
                if (hideLabel == false)
                {
                    GUILayout.Label(label, GUILayoutOptions.Width(EditorGUIUtility.labelWidth - 4).ExpandWidth(false));
                }
                else
                {
                    GUILayout.Space(5);
                }

                PropertyContext <PaletteContext> contextBuffer;
                if (entry.Context.Get(this, "ColorPalette", out contextBuffer))
                {
                    contextBuffer.Value = new PaletteContext()
                    {
                        PaletteIndex = 0,
                        CurrentName  = attribute.PaletteName,
                        ShowAlpha    = attribute.ShowAlpha,
                        Names        = ColorPaletteManager.Instance.ColorPalettes.Select(x => x.Name).ToArray(),
                    };

                    // Get persistent context value
                    if (attribute.PaletteName == null)
                    {
                        contextBuffer.Value.PersistentName = entry.Context.GetPersistent <string>(this, "ColorPaletteName", null);
                        var list = contextBuffer.Value.Names.ToList();
                        contextBuffer.Value.CurrentName = contextBuffer.Value.PersistentName.Value;

                        if (contextBuffer.Value.CurrentName != null && list.Contains(contextBuffer.Value.CurrentName))
                        {
                            contextBuffer.Value.PaletteIndex = list.IndexOf(contextBuffer.Value.CurrentName);
                        }
                    }
                    else
                    {
                        contextBuffer.Value.NameGetter = new StringMemberHelper(entry.ParentType, attribute.PaletteName);
                    }
                }

                var context = contextBuffer.Value;

                //var colorPaletDropDown = entry.Context.Get(this, "colorPalette", 0);
                //var currentName = entry.Context.Get(this, "currentName", attribute.PaletteName);
                //var showAlpha = entry.Context.Get(this, "showAlpha", attribute.ShowAlpha);
                //var names = ColorPaletteManager.Instance.GetColorPaletteNames();

                ColorPalette colorPalette;
                var          rect = EditorGUILayout.BeginHorizontal();
                {
                    rect.x    -= 3;
                    rect.width = 25;

                    entry.SmartValue = AllEditorGUI.DrawColorField(rect, entry.SmartValue, false, context.ShowAlpha);
                    bool openInEditorShown = false;
                    GUILayout.Space(28);
                    AllEditorGUI.BeginInlineBox();
                    {
                        if (attribute.PaletteName == null || ColorPaletteManager.Instance.ShowPaletteName)
                        {
                            AllEditorGUI.BeginBoxHeader();
                            {
                                if (attribute.PaletteName == null)
                                {
                                    var newValue = EditorGUILayout.Popup(context.PaletteIndex, context.Names, GUILayoutOptions.ExpandWidth(true));
                                    if (context.PaletteIndex != newValue)
                                    {
                                        context.PaletteIndex         = newValue;
                                        context.CurrentName          = context.Names[newValue];
                                        context.PersistentName.Value = context.CurrentName;
                                        GUIHelper.RemoveFocusControl();
                                    }
                                }
                                else
                                {
                                    GUILayout.Label(context.CurrentName);
                                    GUILayout.FlexibleSpace();
                                }
                                openInEditorShown = true;
                                if (AllEditorGUI.IconButton(EditorIcons.SettingsCog))
                                {
                                    ColorPaletteManager.Instance.OpenInEditor();
                                }
                            }
                            AllEditorGUI.EndBoxHeader();
                        }

                        if (attribute.PaletteName == null)
                        {
                            colorPalette = ColorPaletteManager.Instance.ColorPalettes.FirstOrDefault(x => x.Name == context.Names[context.PaletteIndex]);
                        }
                        else
                        {
                            colorPalette = ColorPaletteManager.Instance.ColorPalettes.FirstOrDefault(x => x.Name == context.NameGetter.GetString(entry));
                        }

                        if (colorPalette == null)
                        {
                            GUILayout.BeginHorizontal();
                            {
                                if (attribute.PaletteName != null)
                                {
                                    if (GUILayout.Button("Create color palette: " + context.NameGetter.GetString(entry)))
                                    {
                                        ColorPaletteManager.Instance.ColorPalettes.Add(new ColorPalette()
                                        {
                                            Name = context.NameGetter.GetString(entry)
                                        });
                                        ColorPaletteManager.Instance.OpenInEditor();
                                    }
                                }
                            }
                            GUILayout.EndHorizontal();
                        }
                        else
                        {
                            context.CurrentName = colorPalette.Name;
                            context.ShowAlpha   = attribute.ShowAlpha && colorPalette.ShowAlpha;
                            if (openInEditorShown == false)
                            {
                                GUILayout.BeginHorizontal();
                            }
                            var color   = entry.SmartValue;
                            var stretch = ColorPaletteManager.Instance.StretchPalette;
                            var size    = ColorPaletteManager.Instance.SwatchSize;
                            var margin  = ColorPaletteManager.Instance.SwatchSpacing;
                            if (DrawColorPaletteColorPicker(entry, colorPalette, ref color, colorPalette.ShowAlpha, stretch, size, 20, margin))
                            {
                                entry.SmartValue = color;
                                //entry.ApplyChanges();
                            }
                            if (openInEditorShown == false)
                            {
                                GUILayout.Space(4);
                                if (AllEditorGUI.IconButton(EditorIcons.SettingsCog))
                                {
                                    ColorPaletteManager.Instance.OpenInEditor();
                                }
                                GUILayout.EndHorizontal();
                            }
                        }
                    }
                    AllEditorGUI.EndInlineBox();
                }
                EditorGUILayout.EndHorizontal();
            }

            AllEditorGUI.EndIndentedHorizontal();
        }
コード例 #5
0
        private void DrawElements(IPropertyValueEntry <TDictionary> entry, GUIContent label, Context context)
        {
            for (int i = context.Paging.StartIndex; i < context.Paging.EndIndex; i++)
            {
                var keyValuePairProperty = entry.Property.Children[i];
                var keyValuePairEntry    = (PropertyDictionaryElementValueEntry <TDictionary, TKey, TValue>)keyValuePairProperty.BaseValueEntry;

                Rect rect = AllEditorGUI.BeginListItem(false, context.ListItemStyle);
                {
                    if (context.AttrSettings.DisplayMode != DictionaryDisplayOptions.OneLine)
                    {
                        bool defaultExpanded;
                        switch (context.AttrSettings.DisplayMode)
                        {
                        case DictionaryDisplayOptions.CollapsedFoldout:
                            defaultExpanded = false;
                            break;

                        case DictionaryDisplayOptions.ExpandedFoldout:
                            defaultExpanded = true;
                            break;

                        default:
                            defaultExpanded = AllEditorGUI.ExpandFoldoutByDefault;
                            break;
                        }
                        var isExpanded = keyValuePairProperty.Context.Get(this, "Expanded", defaultExpanded);

                        AllEditorGUI.BeginBox();
                        AllEditorGUI.BeginBoxHeader();
                        {
                            if (keyValuePairEntry.HasTempInvalidKey)
                            {
                                GUIHelper.PushColor(Color.red);
                            }
                            var btnRect = GUIHelper.GetCurrentLayoutRect().AlignLeft(HeaderMargin.margin.left);
                            btnRect.y += 1;
                            GUILayout.BeginVertical(HeaderMargin);
                            GUIHelper.PushIsDrawingDictionaryKey(true);

                            GUIHelper.PushLabelWidth(10);

                            InspectorUtilities.DrawProperty(keyValuePairProperty.Children[0], null);

                            GUIHelper.PopLabelWidth();

                            GUIHelper.PopIsDrawingDictionaryKey();
                            GUILayout.EndVertical();
                            if (keyValuePairEntry.HasTempInvalidKey)
                            {
                                GUIHelper.PopColor();
                            }
                            isExpanded.Value = AllEditorGUI.Foldout(btnRect, isExpanded.Value, GUIHelper.TempContent("Key"));
                        }
                        AllEditorGUI.EndBoxHeader();

                        if (AllEditorGUI.BeginFadeGroup(isExpanded, isExpanded.Value))
                        {
                            InspectorUtilities.DrawProperty(keyValuePairProperty.Children[1], null);
                        }
                        AllEditorGUI.EndFadeGroup();

                        AllEditorGUI.EndBox();
                    }
                    else
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.BeginVertical(GUILayoutOptions.Width(context.KeyWidthOffset));
                        {
                            var keyProperty = keyValuePairProperty.Children[0];

                            if (keyValuePairEntry.HasTempInvalidKey)
                            {
                                GUIHelper.PushColor(Color.red);
                            }

                            if (context.AttrSettings.IsReadOnly)
                            {
                                GUIHelper.PushGUIEnabled(false);
                            }

                            GUIHelper.PushIsDrawingDictionaryKey(true);
                            GUIHelper.PushLabelWidth(10);

                            InspectorUtilities.DrawProperty(keyProperty, null);

                            GUIHelper.PopLabelWidth();
                            GUIHelper.PopIsDrawingDictionaryKey();

                            if (context.AttrSettings.IsReadOnly)
                            {
                                GUIHelper.PopGUIEnabled();
                            }

                            if (keyValuePairEntry.HasTempInvalidKey)
                            {
                                GUIHelper.PopColor();
                            }
                        }
                        GUILayout.EndVertical();
                        GUILayout.BeginVertical(OneLineMargin);
                        {
                            var valueEntry = keyValuePairProperty.Children[1];
                            var tmp        = GUIHelper.ActualLabelWidth;
                            EditorGUIUtility.labelWidth = 150;
                            InspectorUtilities.DrawProperty(valueEntry, null);
                            EditorGUIUtility.labelWidth = tmp;
                        }
                        GUILayout.EndVertical();
                        GUILayout.EndHorizontal();
                    }

                    if (entry.IsEditable && !context.AttrSettings.IsReadOnly && AllEditorGUI.IconButton(new Rect(rect.xMax - 24 + 5, rect.y + 2 + ((int)rect.height - 23) / 2, 14, 14), EditorIcons.X))
                    {
                        context.DictionaryHandler.Remove(context.DictionaryHandler.GetKey(0, i));
                        EditorApplication.delayCall += () => context.NewKewIsValid = null;
                        GUIHelper.RequestRepaint();
                    }
                }
                AllEditorGUI.EndListItem();
            }

            if (context.Paging.IsOnLastPage && entry.ValueState == PropertyValueState.CollectionLengthConflict)
            {
                AllEditorGUI.BeginListItem(false);
                GUILayout.Label(GUIHelper.TempContent("------"), EditorStyles.centeredGreyMiniLabel);
                AllEditorGUI.EndListItem();
            }
        }
コード例 #6
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(IPropertyValueEntry <T> entry, GUIContent label)
        {
            var isToggled = entry.Property.Context.GetPersistent <bool>(this, "Toggled", AllEditorGUI.ExpandFoldoutByDefault);

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

                try
                {
                    if (typeof(UnityEngine.Object).IsAssignableFrom(entry.TypeOfValue))
                    {
                        entry.WeakSmartValue = label == null?
                                               EditorGUILayout.ObjectField((UnityEngine.Object) entry.WeakSmartValue, entry.TypeOfValue, entry.Property.Info.GetAttribute <AssetsOnlyAttribute>() == null) :
                                                   EditorGUILayout.ObjectField(label, (UnityEngine.Object)entry.WeakSmartValue, entry.TypeOfValue, entry.Property.Info.GetAttribute <AssetsOnlyAttribute>() == null);
                    }
                    else
                    {
                        if (entry.SerializationBackend == SerializationBackend.Unity && entry.IsEditable && Event.current.type == EventType.Layout)
                        {
                            Debug.LogError("Unity-backed value is null. This should already be fixed by the FixUnityNullDrawer!");
                        }
                        else
                        {
                            bool drawWithBox  = ShouldDrawReferenceObjectPicker(entry);
                            bool contextValue = isToggled.Value;

                            if (drawWithBox)
                            {
                                AllEditorGUI.BeginBox();
                                AllEditorGUI.BeginBoxHeader();
                                {
                                    DrawObjectField(entry, label, ref contextValue);
                                }
                                AllEditorGUI.EndBoxHeader();
                                AllEditorGUI.EndBox();
                            }
                            else
                            {
                                DrawObjectField(entry, label, ref contextValue, false);
                            }

                            isToggled.Value = contextValue;
                        }
                    }
                }
                finally
                {
                    GUIHelper.PopGUIEnabled();
                }
            }
            else
            {
                if (ShouldDrawReferenceObjectPicker(entry))
                {
                    AllEditorGUI.BeginBox();
                    AllEditorGUI.BeginBoxHeader();
                    {
                        GUIHelper.PushGUIEnabled(GUI.enabled && entry.IsEditable);
                        bool contextValue = isToggled.Value;
                        DrawObjectField(entry, label, ref contextValue);
                        isToggled.Value = contextValue;
                        GUIHelper.PopGUIEnabled();
                    }
                    AllEditorGUI.EndBoxHeader();
                    if (AllEditorGUI.BeginFadeGroup(UniqueDrawerKey.Create(entry, this), isToggled.Value))
                    {
                        this.CallNextDrawer(entry.Property, null);
                    }
                    AllEditorGUI.EndFadeGroup();
                    AllEditorGUI.EndBox();
                }
                else
                {
                    this.CallNextDrawer(entry.Property, label);
                }
            }

            var objectPicker = ObjectPicker.GetObjectPicker(entry, entry.BaseValueType);

            if (objectPicker.IsReadyToClaim)
            {
                var obj = objectPicker.ClaimObject();
                entry.Property.Tree.DelayActionUntilRepaint(() => entry.WeakSmartValue = obj);
            }
        }