Esempio n. 1
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(InspectorProperty property, ShowIfAttribute attribute, GUIContent label)
        {
            bool   result;
            string errorMessage;

            IfAttributesHelper.HandleIfAttributesCondition(this, property, attribute.MemberName, attribute.Value, out result, out errorMessage);

            if (errorMessage != null)
            {
                AllEditorGUI.ErrorMessageBox(errorMessage);
                this.CallNextDrawer(property, label);
            }
            else
            {
                if (attribute.Animate)
                {
                    if (AllEditorGUI.BeginFadeGroup(UniqueDrawerKey.Create(property, this), result))
                    {
                        this.CallNextDrawer(property, label);
                    }
                    AllEditorGUI.EndFadeGroup();
                }
                else
                {
                    if (result)
                    {
                        this.CallNextDrawer(property, label);
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(IPropertyValueEntry <TList> entry, GUIContent label)
        {
            var property = entry.Property;
            int minCount = int.MaxValue;
            int maxCount = 0;

            PropertyContext <bool> isVisible;

            if (entry.Context.Get(this, "is_visible", out isVisible))
            {
                isVisible.Value = GeneralDrawerConfig.Instance.OpenListsByDefault;
            }

            for (int i = 0; i < entry.ValueCount; i++)
            {
                if (entry.Values[i].Count > maxCount)
                {
                    maxCount = entry.Values[i].Count;
                }

                if (entry.Values[i].Count < minCount)
                {
                    minCount = entry.Values[i].Count;
                }
            }

            AllEditorGUI.BeginHorizontalToolbar();
            isVisible.Value = AllEditorGUI.Foldout(isVisible.Value, GUIHelper.TempContent("SyncList " + label.text + "  [" + typeof(TList).Name + "]"));
            EditorGUILayout.LabelField(GUIHelper.TempContent(minCount == maxCount ? (minCount == 0 ? "Empty" : minCount + " items") : minCount + " (" + maxCount + ") items"), SirenixGUIStyles.RightAlignedGreyMiniLabel);
            AllEditorGUI.EndHorizontalToolbar();

            if (AllEditorGUI.BeginFadeGroup(isVisible, isVisible.Value))
            {
                GUIHelper.PushGUIEnabled(false);
                AllEditorGUI.BeginVerticalList();
                {
                    var elementLabel = new GUIContent();
                    for (int i = 0; i < maxCount; i++)
                    {
                        AllEditorGUI.BeginListItem();
                        elementLabel.text = "Item " + i;

                        if (i < minCount)
                        {
                            InspectorUtilities.DrawProperty(property.Children[i], elementLabel);
                        }
                        else
                        {
                            EditorGUILayout.LabelField(elementLabel, "—");
                        }
                        AllEditorGUI.EndListItem();
                    }
                }
                AllEditorGUI.EndVerticalList();
                GUIHelper.PopGUIEnabled();
            }
            AllEditorGUI.EndFadeGroup();
        }
Esempio n. 3
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);
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Draws this menu item followed by all of its child menu items
 /// </summary>
 /// <param name="indentLevel">The indent level.</param>
 /// <param name="textColor">字体颜色</param>
 public virtual void DrawMenuItems(int indentLevel)
 {
     // 真正画的地方
     this.DrawMenuItem(indentLevel);
     // 如果还有子菜单继续添加
     if (AllEditorGUI.BeginFadeGroup(this, this.Toggled))
     {
         foreach (OdinMenuItem child in this.ChildMenuItems)
         {
             child.DrawMenuItems(indentLevel + 1);
         }
     }
     AllEditorGUI.EndFadeGroup();
 }
Esempio n. 5
0
        /// <summary>
        /// Not yet documented.
        /// </summary>
        protected override void DrawPropertyLayout(IPropertyValueEntry <GUIStyleState> entry, GUIContent label)
        {
            var property = entry.Property;

            var isVisible = property.Context.Get(this, "isVisible", AllEditorGUI.ExpandFoldoutByDefault);

            isVisible.Value = AllEditorGUI.Foldout(isVisible.Value, label ?? GUIContent.none);

            if (AllEditorGUI.BeginFadeGroup(isVisible, isVisible.Value))
            {
                EditorGUI.indentLevel++;
                entry.SmartValue.background = (Texture2D)SirenixEditorFields.UnityObjectField(label, entry.SmartValue.background, typeof(Texture2D), true);
                entry.SmartValue.textColor  = EditorGUILayout.ColorField(label ?? GUIContent.none, entry.SmartValue.textColor);
                EditorGUI.indentLevel--;
            }
            AllEditorGUI.EndFadeGroup();
        }
Esempio n. 6
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();
        }
Esempio n. 7
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(IPropertyValueEntry <Rect> entry, GUIContent label)
        {
            if (label == null)
            {
                this.DrawValues(entry);
            }
            else
            {
                var isVisible = entry.Property.Context.GetPersistent <bool>(this, "IsVisible", GeneralDrawerConfig.Instance.ExpandFoldoutByDefault);

                isVisible.Value = AllEditorGUI.Foldout(isVisible.Value, label);
                if (AllEditorGUI.BeginFadeGroup(UniqueDrawerKey.Create(entry, this), isVisible.Value))
                {
                    EditorGUI.indentLevel++;
                    this.DrawValues(entry);
                    EditorGUI.indentLevel--;
                }
                AllEditorGUI.EndFadeGroup();
            }
        }
Esempio n. 8
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();
        }
Esempio n. 9
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(IPropertyValueEntry <TList> entry, GUIContent label)
        {
            var property    = entry.Property;
            var infoContext = property.Context.Get(this, "Context", (ListDrawerConfigInfo)null);
            var info        = infoContext.Value;

            bool isReadOnly = false;

            if (entry.TypeOfValue.IsArray == false)
            {
                for (int i = 0; i < entry.ValueCount; i++)
                {
                    if ((entry.WeakValues[i] as IList <TElement>).IsReadOnly)
                    {
                        isReadOnly = true;
                        break;
                    }
                }
            }

            if (info == null)
            {
                var customListDrawerOptions = property.Info.GetAttribute <ListDrawerSettingsAttribute>() ?? new ListDrawerSettingsAttribute();
                isReadOnly = entry.IsEditable == false || isReadOnly || customListDrawerOptions.IsReadOnlyHasValue && customListDrawerOptions.IsReadOnly;

                info = infoContext.Value = new ListDrawerConfigInfo()
                {
                    StartIndex              = 0,
                    Toggled                 = entry.Context.GetPersistent <bool>(this, "ListDrawerToggled", customListDrawerOptions.ExpandedHasValue ? customListDrawerOptions.Expanded : GeneralDrawerConfig.Instance.OpenListsByDefault),
                    RemoveAt                = -1,
                    label                   = new GUIContent(label == null || string.IsNullOrEmpty(label.text) ? property.ValueEntry.TypeOfValue.GetNiceName() : label.text, label == null ? string.Empty : label.tooltip),
                    ShowAllWhilePageing     = false,
                    EndIndex                = 0,
                    CustomListDrawerOptions = customListDrawerOptions,
                    IsReadOnly              = isReadOnly,
                    Draggable               = !isReadOnly && (!customListDrawerOptions.IsReadOnlyHasValue)
                };

                info.listConfig = GeneralDrawerConfig.Instance;
                info.property   = property;

                if (customListDrawerOptions.DraggableHasValue && !customListDrawerOptions.DraggableItems)
                {
                    info.Draggable = false;
                }

                if (info.CustomListDrawerOptions.OnBeginListElementGUI != null)
                {
                    string     errorMessage;
                    MemberInfo memberInfo = property.ParentType
                                            .FindMember()
                                            .IsMethod()
                                            .IsNamed(info.CustomListDrawerOptions.OnBeginListElementGUI)
                                            .HasParameters <int>()
                                            .ReturnsVoid()
                                            .GetMember <MethodInfo>(out errorMessage);

                    if (memberInfo == null || errorMessage != null)
                    {
                        Debug.LogError(errorMessage ?? "There should really be an error message here.");
                    }
                    else
                    {
                        info.OnBeginListElementGUI = EmitUtilities.CreateWeakInstanceMethodCaller <int>(memberInfo as MethodInfo);
                    }
                }

                if (info.CustomListDrawerOptions.OnEndListElementGUI != null)
                {
                    string     errorMessage;
                    MemberInfo memberInfo = property.ParentType
                                            .FindMember()
                                            .IsMethod()
                                            .IsNamed(info.CustomListDrawerOptions.OnEndListElementGUI)
                                            .HasParameters <int>()
                                            .ReturnsVoid()
                                            .GetMember <MethodInfo>(out errorMessage);

                    if (memberInfo == null || errorMessage != null)
                    {
                        Debug.LogError(errorMessage ?? "There should really be an error message here.");
                    }
                    else
                    {
                        info.OnEndListElementGUI = EmitUtilities.CreateWeakInstanceMethodCaller <int>(memberInfo as MethodInfo);
                    }
                }

                if (info.CustomListDrawerOptions.OnTitleBarGUI != null)
                {
                    string     errorMessage;
                    MemberInfo memberInfo = property.ParentType
                                            .FindMember()
                                            .IsMethod()
                                            .IsNamed(info.CustomListDrawerOptions.OnTitleBarGUI)
                                            .HasNoParameters()
                                            .ReturnsVoid()
                                            .GetMember <MethodInfo>(out errorMessage);

                    if (memberInfo == null || errorMessage != null)
                    {
                        Debug.LogError(errorMessage ?? "There should really be an error message here.");
                    }
                    else
                    {
                        info.OnTitleBarGUI = EmitUtilities.CreateWeakInstanceMethodCaller(memberInfo as MethodInfo);
                    }
                }

                if (info.CustomListDrawerOptions.ListElementLabelName != null)
                {
                    string     errorMessage;
                    MemberInfo memberInfo = typeof(TElement)
                                            .FindMember()
                                            .HasNoParameters()
                                            .IsNamed(info.CustomListDrawerOptions.ListElementLabelName)
                                            .HasReturnType <object>(true)
                                            .GetMember(out errorMessage);

                    if (memberInfo == null || errorMessage != null)
                    {
                        Debug.LogError(errorMessage ?? "There should really be an error message here.");
                    }
                    else
                    {
                        string methodSuffix = memberInfo as MethodInfo == null ? "" : "()";
                        info.GetListElementLabelText = DeepReflection.CreateWeakInstanceValueGetter(typeof(TElement), typeof(object), info.CustomListDrawerOptions.ListElementLabelName + methodSuffix);
                    }
                }
            }

            info.listConfig = GeneralDrawerConfig.Instance;
            info.property   = property;

            info.ListItemStyle.padding.left  = info.Draggable ? 25 : 7;
            info.ListItemStyle.padding.right = info.IsReadOnly ? 4 : 20;

            if (Event.current.type == EventType.Repaint)
            {
                info.DropZoneTopLeft = GUIUtility.GUIToScreenPoint(new Vector2(0, 0));
            }

            info.ListValueChanger = property.ValueEntry.GetListValueEntryChanger();
            info.Count            = property.Children.Count;
            info.IsEmpty          = property.Children.Count == 0;

            AllEditorGUI.BeginIndentedVertical(SirenixGUIStyles.PropertyPadding);
            this.BeginDropZone(info);
            {
                this.DrawToolbar(info);
                if (AllEditorGUI.BeginFadeGroup(UniqueDrawerKey.Create(property, this), info.Toggled.Value))
                {
                    GUIHelper.PushLabelWidth(EditorGUIUtility.labelWidth - info.ListItemStyle.padding.left);
                    this.DrawItems(info);
                    GUIHelper.PopLabelWidth();
                }
                AllEditorGUI.EndFadeGroup();
            }
            this.EndDropZone(info);
            AllEditorGUI.EndIndentedVertical();

            if (info.RemoveAt >= 0 && Event.current.type == EventType.Repaint)
            {
                info.ListValueChanger.RemoveListElementAt(info.RemoveAt, CHANGE_ID);

                info.RemoveAt = -1;
                GUIHelper.RequestRepaint();
            }

            if (info.ObjectPicker != null && info.ObjectPicker.IsReadyToClaim && Event.current.type == EventType.Repaint)
            {
                var value = info.ObjectPicker.ClaimObject();

                if (info.JumpToNextPageOnAdd)
                {
                    info.StartIndex = int.MaxValue;
                }

                object[] values = new object[info.ListValueChanger.ValueCount];

                values[0] = value;
                for (int j = 1; j < values.Length; j++)
                {
                    values[j] = SerializationUtility.CreateCopy(value);
                }

                info.ListValueChanger.AddListElement(values, CHANGE_ID);
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyImplementation(InspectorProperty property, GUIContent label)
        {
            if (label == null)
            {
                AllEditorGUI.BeginIndentedVertical();
                for (int i = 0; i < property.Children.Count; i++)
                {
                    InspectorUtilities.DrawProperty(property.Children[i]);
                }
                AllEditorGUI.EndIndentedVertical();
            }
            else
            {
                Context context;
                if (property.Context.Get <Context>(this, "context", out context))
                {
                    context.IsVisisble       = property.Context.GetPersistent(this, "IsVisible", AllEditorGUI.ExpandFoldoutByDefault);
                    context.IsInlineProperty =
                        property.ValueEntry.TypeOfValue.GetAttribute <InlinePropertyAttribute>() ??
                        property.Info.GetAttribute <InlinePropertyAttribute>();
                }

                if (context.IsInlineProperty != null)
                {
                    var outerRect = EditorGUILayout.BeginHorizontal();
                    {
                        if (Event.current.type == EventType.Repaint)
                        {
                            outerRect.y += 1;
                            EditorGUI.PrefixLabel(outerRect, label);
                        }

                        GUILayout.Space(EditorGUIUtility.labelWidth);
                        GUILayout.BeginVertical();
                        {
                            if (context.IsInlineProperty.LabelWidth > 0)
                            {
                                GUIHelper.PushLabelWidth(context.IsInlineProperty.LabelWidth);
                            }
                            GUIHelper.PushIndentLevel(0);
                            for (int i = 0; i < property.Children.Count; i++)
                            {
                                InspectorUtilities.DrawProperty(property.Children[i]);
                            }
                            GUIHelper.PopIndentLevel();
                            if (context.IsInlineProperty.LabelWidth > 0)
                            {
                                GUIHelper.PopLabelWidth();
                            }
                        }
                        GUILayout.EndVertical();
                    }
                    EditorGUILayout.EndHorizontal();
                }
                else
                {
                    context.IsVisisble.Value = AllEditorGUI.Foldout(context.IsVisisble.Value, label);
                    if (AllEditorGUI.BeginFadeGroup(context, context.IsVisisble.Value))
                    {
                        EditorGUI.indentLevel++;
                        for (int i = 0; i < property.Children.Count; i++)
                        {
                            InspectorUtilities.DrawProperty(property.Children[i]);
                        }
                        EditorGUI.indentLevel--;
                    }
                    AllEditorGUI.EndFadeGroup();
                }
            }
        }
Esempio n. 11
0
            public void DrawItem()
            {
                bool hasLabel = this.labelName != null && (this.matchesSearchTerm || this.window.hasSearchTerm == false);

                if (hasLabel)
                {
                    bool isSelected = false, isChosen = false;
                    if (this.ChildNodes != null)
                    {
                        if (this.window.hideFoldoutLabels == false)
                        {
                            AllEditorGUI.BeginMenuListItem(out isSelected, out isChosen, this.ForceSetSelected);
                            {
                                if (this.matchesSearchTerm)
                                {
                                    AllEditorGUI.Foldout(true, this.label);
                                }
                                else
                                {
                                    this.IsVisible = AllEditorGUI.Foldout(this.IsVisible, this.label);
                                }
                            }
                            AllEditorGUI.EndMenuListItem();
                        }
                    }
                    else
                    {
                        AllEditorGUI.BeginMenuListItem(out isSelected, out isChosen, this.ForceSetSelected);
                        {
                            //if (this.drawHasNoEmptyConstructor)
                            //{
                            //    GUIHelper.PushGUIEnabled(false);
                            //}

                            // Properbly a type
                            if (this.isTypeNode && this.Type == typeof(NullType))
                            {
                                EditorGUILayout.LabelField(this.label, SirenixGUIStyles.LeftAlignedGreyMiniLabel);
                            }
                            else
                            {
                                EditorGUILayout.LabelField(this.label);
                            }

                            //if (this.drawHasNoEmptyConstructor)
                            //{
                            //    GUIHelper.PopGUIEnabled();
                            //}

                            if (this.drawHasNoEmptyConstructor)
                            {
                                var rect = GUILayoutUtility.GetLastRect();

                                rect.width -= 16;

                                EditorIcons.AlertTriangle.Draw(new Rect(rect.xMax, rect.yMin, 16, 16));

                                GUI.Label(rect, this.hasNoEmptyConstructorLabel, SirenixGUIStyles.RightAlignedGreyMiniLabel);
                                //isChosen = false;
                            }
                            //var rect = GUILayoutUtility.GetLastRect();
                            //if (this.isTypeNode && this.showNotSerializableLabel)
                            //{
                            //    GUI.Label(rect, isNotSerializableLabel, isSelected ? SirenixGUIStyles.RightAlignedWhiteMiniLabel : SirenixGUIStyles.RightAlignedGreyMiniLabel);
                            //}
                        }
                        AllEditorGUI.EndMenuListItem();
                    }

                    if (isSelected && Event.current.type == EventType.KeyDown)
                    {
                        if (Event.current.keyCode == KeyCode.RightArrow)
                        {
                            this.IsVisible = true;
                        }
                        else if (Event.current.keyCode == KeyCode.LeftArrow)
                        {
                            this.IsVisible = false;
                        }
                        else if (Event.current.keyCode == KeyCode.Return)
                        {
                            isChosen = true;
                        }
                    }

                    if (isChosen)
                    {
                        this.IsVisible = !this.IsVisible;

                        if (this.isTypeNode)
                        {
                            this.window.chosenType = this.Type;
                        }
                    }

                    this.ForceSetSelected = false;
                }

                if (this.labelName == null)
                {
                    this.IsVisible = true;
                }

                if (this.ChildNodes != null)
                {
                    if (this.matchesSearchTerm || AllEditorGUI.BeginFadeGroup(this, this.IsVisible))
                    {
                        if (hasLabel && !this.window.hideFoldoutLabels)
                        {
                            EditorGUI.indentLevel++;
                        }
                        for (int i = 0; i < this.ChildNodes.Count; i++)
                        {
                            this.ChildNodes[i].DrawItem();
                        }
                        if (hasLabel && !this.window.hideFoldoutLabels)
                        {
                            EditorGUI.indentLevel--;
                        }
                    }
                    if (this.matchesSearchTerm == false)
                    {
                        AllEditorGUI.EndFadeGroup();
                    }
                }
            }
Esempio n. 12
0
        private void DrawRootTypeGroup(InspectorDefaultEditors editorCategory, IPropertyValueEntry <InspectorTypeDrawingConfig> entry, string searchText)
        {
            TypeGroup typeGroup;

            switch (editorCategory)
            {
            case InspectorDefaultEditors.UserTypes:
                typeGroup = UserTypesRootGroup;
                break;

            case InspectorDefaultEditors.PluginTypes:
                typeGroup = PluginTypesRootGroup;
                break;

            case InspectorDefaultEditors.UnityTypes:
                typeGroup = UnityTypesRootGroup;
                break;

            case InspectorDefaultEditors.OtherTypes:
            default:
                typeGroup = OtherTypesRootGroup;
                break;
            }

            if (typeGroup.SubTypes.Count == 0 && typeGroup.SubGroups.Count == 0)
            {
                AllEditorGUI.BeginListItem();
                {
                    AllEditorGUI.BeginIndentedHorizontal();
                    {
                        GUIHelper.PushGUIEnabled(false);
                        {
                            AllEditorGUI.IconButton(EditorIcons.TriangleRight, IconStyle, 16);
                            GUILayoutUtility.GetRect(16, 16, EditorStyles.toggle, GUILayoutOptions.ExpandWidth(false).Width(16));
                            GUILayout.Label(typeGroup.Name);
                        }
                        GUIHelper.PopGUIEnabled();
                    }
                    AllEditorGUI.EndIndentedHorizontal();
                }
                AllEditorGUI.EndListItem();
            }
            else
            {
                bool useToggle = true;

                var rect = AllEditorGUI.BeginListItem();
                {
                    bool toggleExpansion = false;

                    AllEditorGUI.BeginIndentedHorizontal();
                    {
                        EditorIcon icon = (typeGroup.IsExpanded || !searchText.IsNullOrWhitespace()) ? EditorIcons.TriangleDown : EditorIcons.TriangleRight;

                        toggleExpansion = AllEditorGUI.IconButton(icon, IconStyle, 16);

                        if (useToggle)
                        {
                            EditorGUI.showMixedValue = typeGroup.HasConflict;

                            bool isToggled = typeGroup.HasConflict || typeGroup.GetSharedEditorType() == typeof(OdinEditor);

                            GUI.changed = false;
                            isToggled   = EditorGUI.Toggle(GUILayoutUtility.GetRect(16, 16, EditorStyles.toggle, GUILayoutOptions.ExpandWidth(false).Width(16)), isToggled);

                            if (GUI.changed)
                            {
                                typeGroup.ClearEditorTypes();

                                if (isToggled)
                                {
                                    // Add rule flag
                                    InspectorConfig.Instance.DefaultEditorBehaviour |= editorCategory;
                                }
                                else
                                {
                                    // Remove rule flag
                                    InspectorConfig.Instance.DefaultEditorBehaviour = InspectorConfig.Instance.DefaultEditorBehaviour & ~editorCategory;
                                }

                                EditorUtility.SetDirty(InspectorConfig.Instance);
                                InspectorConfig.Instance.UpdateOdinEditors();
                            }

                            EditorGUI.showMixedValue = false;
                        }
                        else
                        {
                            GUILayout.Label("TODO: DROPDOWN!");
                        }

                        GUILayout.Label(typeGroup.Name);
                    }
                    AllEditorGUI.EndIndentedHorizontal();

                    if (toggleExpansion || (Event.current.type == EventType.MouseDown && rect.Contains(Event.current.mousePosition)))
                    {
                        typeGroup.IsExpanded = !typeGroup.IsExpanded;
                        Event.current.Use();
                    }
                }
                AllEditorGUI.EndListItem();

                if (AllEditorGUI.BeginFadeGroup(typeGroup, typeGroup.IsExpanded || !searchText.IsNullOrWhitespace()))
                {
                    EditorGUI.indentLevel++;

                    foreach (var subType in typeGroup.SubTypes)
                    {
                        if (typeGroup.IsTypeVisible(subType.DrawnType))
                        {
                            this.DrawType(subType, entry);
                        }
                    }

                    foreach (var subGroup in typeGroup.SubGroups)
                    {
                        this.DrawTypeGroup(subGroup, entry, searchText);
                    }

                    EditorGUI.indentLevel--;
                }
                AllEditorGUI.EndFadeGroup();
            }
        }
Esempio n. 13
0
        private void DrawTypeGroup(TypeGroup typeGroup, IPropertyValueEntry <InspectorTypeDrawingConfig> entry, string searchText)
        {
            if (!typeGroup.IsSearchVisible)
            {
                return;
            }

            bool useToggle = true;

            var rect = AllEditorGUI.BeginListItem();

            {
                bool toggleExpansion = false;

                AllEditorGUI.BeginIndentedHorizontal();
                {
                    EditorIcon icon = (typeGroup.IsExpanded || !searchText.IsNullOrWhitespace()) ? EditorIcons.TriangleDown : EditorIcons.TriangleRight;

                    toggleExpansion = AllEditorGUI.IconButton(icon, IconStyle, 16);

                    if (!typeGroup.HasEligibleTypes)
                    {
                        toggleExpansion |= AllEditorGUI.IconButton(EditorIcons.Transparent, 20);
                    }
                    else
                    {
                        if (useToggle)
                        {
                            EditorGUI.showMixedValue = typeGroup.HasConflict;

                            bool isToggled = typeGroup.HasConflict || typeGroup.GetSharedEditorType() == typeof(OdinEditor);

                            GUI.changed = false;
                            isToggled   = EditorGUI.Toggle(GUILayoutUtility.GetRect(16, 16, EditorStyles.toggle, GUILayoutOptions.ExpandWidth(false).Width(16)), isToggled);

                            if (GUI.changed)
                            {
                                typeGroup.SetSharedEditorType(isToggled ? typeof(OdinEditor) : null);
                                UpdateRootGroupConflicts();
                                InspectorConfig.Instance.UpdateOdinEditors();
                            }

                            EditorGUI.showMixedValue = false;
                        }
                        else
                        {
                            GUILayout.Label("TODO: DROPDOWN!");
                        }
                    }

                    GUILayout.Label(typeGroup.Name);
                }
                AllEditorGUI.EndIndentedHorizontal();

                if (toggleExpansion || (Event.current.type == EventType.MouseDown && rect.Contains(Event.current.mousePosition)))
                {
                    typeGroup.IsExpanded = !typeGroup.IsExpanded;
                    Event.current.Use();
                }
            }
            AllEditorGUI.EndListItem();

            if (AllEditorGUI.BeginFadeGroup(typeGroup, typeGroup.IsExpanded || !searchText.IsNullOrWhitespace()))
            {
                EditorGUI.indentLevel++;

                foreach (var subType in typeGroup.SubTypes)
                {
                    if (typeGroup.IsTypeVisible(subType.DrawnType))
                    {
                        this.DrawType(subType, entry);
                    }
                }

                foreach (var subGroup in typeGroup.SubGroups)
                {
                    this.DrawTypeGroup(subGroup, entry, searchText);
                }

                EditorGUI.indentLevel--;
            }
            AllEditorGUI.EndFadeGroup();
        }
Esempio n. 14
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(IPropertyValueEntry <TDictionary> entry, GUIContent label)
        {
            var context = entry.Property.Context.Get(this, "context", (Context)null);

            if (context.Value == null)
            {
                context.Value                = new Context();
                context.Value.Toggled        = entry.Context.GetPersistent(this, "Toggled", GeneralDrawerConfig.Instance.OpenListsByDefault);
                context.Value.KeyWidthOffset = 130;
                context.Value.Label          = label ?? new GUIContent(typeof(TDictionary).GetNiceName());
                context.Value.AttrSettings   = entry.Property.Info.GetAttribute <DictionaryDrawerSettings>() ?? new DictionaryDrawerSettings();
                context.Value.DisableAddKey  = entry.Property.Tree.HasPrefabs && !entry.GetDictionaryHandler().SupportsPrefabModifications;

                if (!context.Value.DisableAddKey)
                {
                    context.Value.TempKeyValue = new TempKeyValue();

                    var tree = PropertyTree.Create(context.Value.TempKeyValue);
                    tree.UpdateTree();

                    context.Value.TempKeyEntry   = (IPropertyValueEntry <TKey>)tree.GetPropertyAtPath("Key").ValueEntry;
                    context.Value.TempValueEntry = (IPropertyValueEntry <TValue>)tree.GetPropertyAtPath("Value").ValueEntry;
                }
            }

            context.Value.DictionaryHandler           = (DictionaryHandler <TDictionary, TKey, TValue>)entry.GetDictionaryHandler();
            context.Value.Config                      = GeneralDrawerConfig.Instance;
            context.Value.Paging.NumberOfItemsPerPage = context.Value.Config.NumberOfItemsPrPage;
            context.Value.ListItemStyle.padding.right = !entry.IsEditable || context.Value.AttrSettings.IsReadOnly ? 4 : 20;

            //if (!IsSupportedKeyType)
            //{
            //    var message = entry.Property.Context.Get(this, "error_message", (string)null);
            //    var detailedMessage = entry.Property.Context.Get(this, "error_message_detailed", (string)null);
            //    var folded = entry.Property.Context.Get(this, "error_message_folded", true);

            //    if (message.Value == null)
            //    {
            //        string str = "";

            //        if (label != null)
            //        {
            //            str += label.text + "\n\n";
            //        }

            //        str += "The dictionary key type '" + typeof(TKey).GetNiceFullName() + "' is not supported in prefab instances. Expand this box to see which key types are supported.";

            //        message.Value = str;
            //    }

            //    if (detailedMessage.Value == null)
            //    {
            //        var sb = new StringBuilder("The following key types are supported:");

            //        sb.AppendLine()
            //          .AppendLine();

            //        foreach (var type in DictionaryKeyUtility.GetPersistentPathKeyTypes())
            //        {
            //            sb.AppendLine(type.GetNiceName());
            //        }

            //        sb.AppendLine("Enums of any type");

            //        detailedMessage.Value = sb.ToString();
            //    }

            //    folded.Value = AllEditorGUI.DetailedMessageBox(message.Value, detailedMessage.Value, MessageType.Error, folded.Value);

            //    return;
            //}

            AllEditorGUI.BeginIndentedVertical(SirenixGUIStyles.PropertyPadding);
            {
                context.Value.Paging.Update(elementCount: entry.Property.Children.Count);
                this.DrawToolbar(entry, context.Value);
                context.Value.Paging.Update(elementCount: entry.Property.Children.Count);

                if (!context.Value.DisableAddKey && context.Value.AttrSettings.IsReadOnly == false)
                {
                    this.DrawAddKey(entry, context.Value);
                }

                float t;
                GUIHelper.BeginLayoutMeasuring();
                if (AllEditorGUI.BeginFadeGroup(UniqueDrawerKey.Create(entry.Property, this), context.Value.Toggled.Value, out t))
                {
                    var rect = AllEditorGUI.BeginVerticalList(false);
                    if (context.Value.AttrSettings.DisplayMode == DictionaryDisplayOptions.OneLine)
                    {
                        var maxWidth = rect.width - 90;
                        rect.xMin = context.Value.KeyWidthOffset + 22;
                        rect.xMax = rect.xMin + 10;
                        context.Value.KeyWidthOffset = context.Value.KeyWidthOffset + AllEditorGUI.SlideRect(rect).x;

                        if (Event.current.type == EventType.Repaint)
                        {
                            context.Value.KeyWidthOffset = Mathf.Clamp(context.Value.KeyWidthOffset, 90, maxWidth);
                        }

                        if (context.Value.Paging.ElementCount != 0)
                        {
                            var headerRect = AllEditorGUI.BeginListItem(false);
                            {
                                GUILayout.Space(14);
                                if (Event.current.type == EventType.Repaint)
                                {
                                    GUI.Label(headerRect.SetWidth(context.Value.KeyWidthOffset), context.Value.AttrSettings.KeyLabel, SirenixGUIStyles.LabelCentered);
                                    GUI.Label(headerRect.AddXMin(context.Value.KeyWidthOffset), context.Value.AttrSettings.ValueLabel, SirenixGUIStyles.LabelCentered);
                                    AllEditorGUI.DrawSolidRect(headerRect.AlignBottom(1), SirenixGUIStyles.BorderColor);
                                }
                            }
                            AllEditorGUI.EndListItem();
                        }
                    }

                    this.DrawElements(entry, label, context.Value);
                    AllEditorGUI.EndVerticalList();
                }
                AllEditorGUI.EndFadeGroup();

                // Draw borders
                var outerRect = GUIHelper.EndLayoutMeasuring();
                if (t > 0.01f && Event.current.type == EventType.Repaint)
                {
                    Color col = SirenixGUIStyles.BorderColor;
                    outerRect.yMin -= 1;
                    AllEditorGUI.DrawBorders(outerRect, 1, col);
                    col.a *= t;
                    if (context.Value.AttrSettings.DisplayMode == DictionaryDisplayOptions.OneLine)
                    {
                        // Draw Slide Rect Border
                        outerRect.width = 1;
                        outerRect.x    += context.Value.KeyWidthOffset + 13;
                        AllEditorGUI.DrawSolidRect(outerRect, col);
                    }
                }
            }
            AllEditorGUI.EndIndentedVertical();
        }
Esempio n. 15
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();
            }
        }
Esempio n. 16
0
        private void DrawAddKey(IPropertyValueEntry <TDictionary> entry, Context context)
        {
            if (entry.IsEditable == false || context.AttrSettings.IsReadOnly)
            {
                return;
            }

            if (AllEditorGUI.BeginFadeGroup(context, context.ShowAddKeyGUI))
            {
                GUILayout.BeginVertical(AddKeyPaddingStyle);
                {
                    if (typeof(TKey) == typeof(string) && context.NewKey == null)
                    {
                        context.NewKey        = (TKey)(object)"";
                        context.NewKewIsValid = null;
                    }

                    if (context.NewKewIsValid == null)
                    {
                        context.NewKewIsValid = CheckKeyIsValid(entry, context.NewKey, out context.NewKeyErrorMessage);
                    }

                    InspectorUtilities.BeginDrawPropertyTree(context.TempKeyEntry.Property.Tree, false);

                    // Key
                    {
                        //context.TempKeyValue.key = context.NewKey;
                        context.TempKeyEntry.Property.Update();

                        EditorGUI.BeginChangeCheck();

                        context.TempKeyEntry.Property.Draw();

                        bool changed1 = EditorGUI.EndChangeCheck();
                        bool changed2 = context.TempKeyEntry.ApplyChanges();

                        if (changed1 || changed2)
                        {
                            context.NewKey = context.TempKeyValue.Key;
                            EditorApplication.delayCall += () => context.NewKewIsValid = null;
                            GUIHelper.RequestRepaint();
                        }
                    }

                    // Value
                    {
                        //context.TempKeyValue.value = context.NewValue;
                        context.TempValueEntry.Property.Update();
                        context.TempValueEntry.Property.Draw();
                        context.TempValueEntry.ApplyChanges();
                        context.NewValue = context.TempKeyValue.Value;
                    }

                    context.TempKeyEntry.Property.Tree.InvokeDelayedActions();
                    var changed = context.TempKeyEntry.Property.Tree.ApplyChanges();

                    if (changed)
                    {
                        context.NewKey = context.TempKeyValue.Key;
                        EditorApplication.delayCall += () => context.NewKewIsValid = null;
                        GUIHelper.RequestRepaint();
                    }

                    InspectorUtilities.EndDrawPropertyTree(context.TempKeyEntry.Property.Tree);

                    GUIHelper.PushGUIEnabled(GUI.enabled && context.NewKewIsValid.Value);
                    if (GUILayout.Button(context.NewKewIsValid.Value ? "Add" : context.NewKeyErrorMessage))
                    {
                        context.DictionaryHandler.SetValue(context.NewKey, context.NewValue);
                        EditorApplication.delayCall += () => context.NewKewIsValid = null;
                        GUIHelper.RequestRepaint();

                        entry.Property.Tree.DelayActionUntilRepaint(() =>
                        {
                            context.NewValue           = default(TValue);
                            context.TempKeyValue.Value = default(TValue);
                            context.TempValueEntry.Update();
                        });
                    }
                    GUIHelper.PopGUIEnabled();
                }
                GUILayout.EndVertical();
            }
            AllEditorGUI.EndFadeGroup();
        }
Esempio n. 17
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);
            }
        }