Beispiel #1
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();
        }
Beispiel #2
0
        /// <summary>
        /// Not yet documented.
        /// </summary>
        protected override void DrawPropertyLayout(IPropertyValueEntry <TElement> entry, AssetListAttribute attribute, GUIContent label)
        {
            var config = entry.Property.Context.Get(this, "Test", (CurrentContext)null);

            if (config.Value == null)
            {
                config.Value           = new CurrentContext();
                config.Value.Attribute = attribute;
                config.Value.Tags      = attribute.Tags != null?attribute.Tags.Trim().Split(',').Select(i => i.Trim()).ToArray() : null;

                config.Value.LayerNames = attribute.LayerNames != null?attribute.LayerNames.Trim().Split(',').Select(i => i.Trim()).ToArray() : null;

                config.Value.Property = entry.Property;
                if (attribute.Path != null)
                {
                    var path = attribute.Path.Trim('/', ' ');
                    path = "Assets/" + path + "/";
                    path = Application.dataPath + "/" + path;

                    config.Value.AssetsFolderLocation = new DirectoryInfo(path);

                    path = attribute.Path.TrimStart('/').TrimEnd('/');
                    config.Value.PrettyPath = "/" + path.TrimStart('/');
                }

                if (attribute.CustomFilterMethod != null)
                {
                    MethodInfo methodInfo;
                    string     error;
                    if (MemberFinder.Start(entry.ParentType)
                        .IsMethod()
                        .IsNamed(attribute.CustomFilterMethod)
                        .HasReturnType <bool>()
                        .HasParameters <TElement>()
                        .TryGetMember <MethodInfo>(out methodInfo, out error))
                    {
                        if (methodInfo.IsStatic)
                        {
                            config.Value.StaticCustomIncludeMethod = (Func <TElement, bool>)Delegate.CreateDelegate(typeof(Func <TElement, bool>), methodInfo, true);
                        }
                        else
                        {
                            config.Value.InstanceCustomIncludeMethod = EmitUtilities.CreateWeakInstanceMethodCaller <bool, TElement>(methodInfo);
                        }
                    }

                    config.Value.ErrorMessage = error;
                }

                if (config.Value.ErrorMessage != null)
                {
                    // We can get away with lag on load.
                    config.Value.MaxSearchDurationPrFrameInMS = 20;
                    config.Value.EnsureListPopulation();
                    config.Value.MaxSearchDurationPrFrameInMS = 1;
                }
            }

            var currentValue = (UnityEngine.Object)entry.WeakSmartValue;

            if (config.Value.ErrorMessage != null)
            {
                AllEditorGUI.ErrorMessageBox(config.Value.ErrorMessage);
            }
            else
            {
                config.Value.EnsureListPopulation();
            }

            AllEditorGUI.BeginIndentedVertical(SirenixGUIStyles.PropertyPadding);
            {
                AllEditorGUI.BeginHorizontalToolbar();
                if (label != null)
                {
                    GUILayout.Label(label);
                }

                GUILayout.FlexibleSpace();
                if (config.Value.PrettyPath != null)
                {
                    GUILayout.Label(config.Value.PrettyPath, SirenixGUIStyles.RightAlignedGreyMiniLabel);
                    AllEditorGUI.VerticalLineSeparator();
                }

                if (config.Value.IsPopulated)
                {
                    GUILayout.Label(config.Value.AvailableAsset.Count + " items", SirenixGUIStyles.RightAlignedGreyMiniLabel);
                    GUIHelper.PushGUIEnabled(GUI.enabled && (config.Value.AvailableAsset.Count > 0 && config.Value.ErrorMessage == null));
                }
                else
                {
                    GUILayout.Label("Scanning " + config.Value.CurrentSearchingIndex + " / " + config.Value.NumberOfResultsToSearch, SirenixGUIStyles.RightAlignedGreyMiniLabel);
                    GUIHelper.PushGUIEnabled(false);
                }

                AllEditorGUI.VerticalLineSeparator();

                bool drawConflict = entry.Property.ParentValues.Count > 1;
                if (drawConflict == false)
                {
                    var index = config.Value.AvailableAsset.IndexOf(currentValue) + 1;
                    if (index > 0)
                    {
                        GUILayout.Label(index.ToString(), SirenixGUIStyles.RightAlignedGreyMiniLabel);
                    }
                    else
                    {
                        drawConflict = true;
                    }
                }

                if (drawConflict)
                {
                    GUILayout.Label("-", SirenixGUIStyles.RightAlignedGreyMiniLabel);
                }

                if (AllEditorGUI.ToolbarButton(EditorIcons.TriangleLeft) && config.Value.IsPopulated)
                {
                    var index = config.Value.AvailableAsset.IndexOf(currentValue) - 1;
                    index = index < 0 ? config.Value.AvailableAsset.Count - 1 : index;
                    entry.WeakSmartValue = config.Value.AvailableAsset[index];
                }

                if (AllEditorGUI.ToolbarButton(EditorIcons.TriangleDown) && config.Value.IsPopulated)
                {
                    GenericMenu m            = new GenericMenu();
                    var         selected     = currentValue;
                    int         itemsPrPage  = 40;
                    bool        showPages    = config.Value.AvailableAsset.Count > 50;
                    string      page         = "";
                    int         selectedPage = (config.Value.AvailableAsset.IndexOf(entry.WeakSmartValue as UnityEngine.Object) / itemsPrPage);
                    for (int i = 0; i < config.Value.AvailableAsset.Count; i++)
                    {
                        var obj = config.Value.AvailableAsset[i];
                        if (obj != null)
                        {
                            var path       = AssetDatabase.GetAssetPath(obj);
                            var name       = string.IsNullOrEmpty(path) ? obj.name : path.Substring(7).Replace("/", "\\");
                            var localEntry = entry;

                            if (showPages)
                            {
                                var p = (i / itemsPrPage);
                                page = (p * itemsPrPage) + " - " + Mathf.Min(((p + 1) * itemsPrPage), config.Value.AvailableAsset.Count - 1);
                                if (selectedPage == p)
                                {
                                    page += " (contains selected)";
                                }
                                page += "/";
                            }

                            m.AddItem(new GUIContent(page + name), obj == selected, () =>
                            {
                                localEntry.Property.Tree.DelayActionUntilRepaint(() => localEntry.WeakSmartValue = obj);
                            });
                        }
                    }
                    m.ShowAsContext();
                }

                if (AllEditorGUI.ToolbarButton(EditorIcons.TriangleRight) && config.Value.IsPopulated)
                {
                    var index = config.Value.AvailableAsset.IndexOf(currentValue) + 1;
                    entry.WeakSmartValue = config.Value.AvailableAsset[index % config.Value.AvailableAsset.Count];
                }

                GUIHelper.PopGUIEnabled();

                AllEditorGUI.EndHorizontalToolbar();
                AllEditorGUI.BeginVerticalList();
                AllEditorGUI.BeginListItem(false, padding);
                this.CallNextDrawer(entry.Property, null);
                AllEditorGUI.EndListItem();
                AllEditorGUI.EndVerticalList();
            }
            AllEditorGUI.EndIndentedVertical();
        }
Beispiel #3
0
        private Rect DrawItem(ListDrawerConfigInfo info, InspectorProperty itemProperty, DragHandle dragHandle, int index = -1)
        {
            var listItemInfo = itemProperty.Context.Get <ListItemInfo>(this, "listItemInfo");

            Rect rect;

            rect = AllEditorGUI.BeginListItem(false, info.ListItemStyle, listItemOptions);
            {
                if (Event.current.type == EventType.Repaint && !info.IsReadOnly)
                {
                    listItemInfo.Value.Width          = rect.width;
                    dragHandle.DragHandleRect         = new Rect(rect.x + 4, rect.y, 20, rect.height);
                    listItemInfo.Value.DragHandleRect = new Rect(rect.x + 4, rect.y + 2 + ((int)rect.height - 23) / 2, 20, 20);
                    listItemInfo.Value.AddBtnRect     = new Rect(listItemInfo.Value.DragHandleRect.x + rect.width - 22, listItemInfo.Value.DragHandleRect.y + 1, 14, 14);
                    itemProperty.Context.GetGlobal <Rect?>("overrideRect").Value = rect;
                    if (info.Draggable)
                    {
                        //GL.sRGBWrite = QualitySettings.activeColorSpace == ColorSpace.Linear;
                        GUI.Label(listItemInfo.Value.DragHandleRect, EditorIcons.List.Inactive, GUIStyle.none);
                        //GL.sRGBWrite = false;
                    }
                }

                GUIHelper.PushHierarchyMode(false);
                GUIContent label = null;

                if (info.CustomListDrawerOptions.ShowIndexLabelsHasValue)
                {
                    if (info.CustomListDrawerOptions.ShowIndexLabels)
                    {
                        label = new GUIContent(index.ToString());
                    }
                }
                else if (info.listConfig.ShowIndexLabels)
                {
                    label = new GUIContent(index.ToString());
                }

                if (info.GetListElementLabelText != null)
                {
                    var value = itemProperty.ValueEntry.WeakSmartValue;

                    if (object.ReferenceEquals(value, null))
                    {
                        if (label == null)
                        {
                            label = new GUIContent("Null");
                        }
                        else
                        {
                            label.text += " : Null";
                        }
                    }
                    else
                    {
                        label = label ?? new GUIContent("");
                        if (label.text != "")
                        {
                            label.text += " : ";
                        }

                        object text = info.GetListElementLabelText(value);
                        label.text += (text == null ? "" : text.ToString());
                    }
                }

                if (info.OnBeginListElementGUI != null)
                {
                    info.OnBeginListElementGUI(info.property.ParentValues[0], index);
                }
                InspectorUtilities.DrawProperty(itemProperty, label);

                if (info.OnEndListElementGUI != null)
                {
                    info.OnEndListElementGUI(info.property.ParentValues[0], index);
                }

                GUIHelper.PopHierarchyMode();

                if (info.IsReadOnly == false)
                {
                    if (AllEditorGUI.IconButton(listItemInfo.Value.AddBtnRect, EditorIcons.X))
                    {
                        if (index >= 0)
                        {
                            info.RemoveAt = index;
                        }
                    }
                }
            }
            AllEditorGUI.EndListItem();

            return(rect);
        }
Beispiel #4
0
        private void DrawItems(ListDrawerConfigInfo info)
        {
            int  from   = 0;
            int  to     = info.Count;
            bool paging = info.CustomListDrawerOptions.PagingHasValue ? info.CustomListDrawerOptions.ShowPaging : true;

            if (paging && info.ShowAllWhilePageing == false)
            {
                from = Mathf.Clamp(info.StartIndex, 0, info.Count);
                to   = Mathf.Clamp(info.EndIndex, 0, info.Count);
            }

            var   drawEmptySpace = info.DropZone.IsBeingHovered || info.IsDroppingUnityObjects;
            float height         = drawEmptySpace ? info.IsDroppingUnityObjects ? 16 : (DragAndDropManager.CurrentDraggingHandle.Rect.height - 3) : 0;
            var   rect           = AllEditorGUI.BeginVerticalList();

            {
                for (int i = 0, j = from, k = from; j < to; i++, j++)
                {
                    var dragHandle = this.BeginDragHandle(info, j, i);
                    {
                        if (drawEmptySpace)
                        {
                            var topHalf = dragHandle.Rect;
                            topHalf.height /= 2;
                            if (topHalf.Contains(info.LayoutMousePosition) || topHalf.y > info.LayoutMousePosition.y && i == 0)
                            {
                                GUILayout.Space(height);
                                drawEmptySpace = false;
                                info.InsertAt  = k;
                            }
                        }

                        if (dragHandle.IsDragging == false)
                        {
                            k++;
                            this.DrawItem(info, info.property.Children[j], dragHandle, j);
                        }
                        else
                        {
                            GUILayout.Space(3);
                            ListDrawerStaticInfo.DelayedGUIDrawer.Begin(dragHandle.Rect.width, dragHandle.Rect.height, dragHandle.CurrentMethod != DragAndDropMethods.Move);
                            DragAndDropManager.AllowDrop = false;
                            this.DrawItem(info, info.property.Children[j], dragHandle, j);
                            DragAndDropManager.AllowDrop = true;
                            ListDrawerStaticInfo.DelayedGUIDrawer.End();
                            if (dragHandle.CurrentMethod != DragAndDropMethods.Move)
                            {
                                GUILayout.Space(3);
                            }
                        }

                        if (drawEmptySpace)
                        {
                            var bottomHalf = dragHandle.Rect;
                            bottomHalf.height /= 2;
                            bottomHalf.y      += bottomHalf.height;

                            if (bottomHalf.Contains(info.LayoutMousePosition) || bottomHalf.yMax < info.LayoutMousePosition.y && j + 1 == to)
                            {
                                GUILayout.Space(height);
                                drawEmptySpace = false;
                                info.InsertAt  = Mathf.Min(k, to);
                            }
                        }
                    }
                    this.EndDragHandle(info, i);
                }

                if (drawEmptySpace)
                {
                    GUILayout.Space(height);
                    info.InsertAt = Event.current.mousePosition.y > rect.center.y ? to : from;
                }

                if (to == info.property.Children.Count && info.property.ValueEntry.ValueState == PropertyValueState.CollectionLengthConflict)
                {
                    AllEditorGUI.BeginListItem(false);
                    GUILayout.Label(GUIHelper.TempContent("------"), EditorStyles.centeredGreyMiniLabel);
                    AllEditorGUI.EndListItem();
                }
            }
            AllEditorGUI.EndVerticalList();

            if (Event.current.type == EventType.Repaint)
            {
                info.LayoutMousePosition = Event.current.mousePosition;
            }
        }
Beispiel #5
0
            public void DrawMenu()
            {
                if (this.GameObject == null)
                {
                    return;
                }

                if (!this.IsIncluded)
                {
                    return;
                }

                GUIHelper.PushGUIEnabled(GUI.enabled && this.ErrorCount + this.WarningCount > 0);

                var rect = AllEditorGUI.BeginListItem(true);

                {
                    if (Event.current.rawType == EventType.MouseDown && rect.Contains(Event.current.mousePosition))
                    {
                        if (this.IsSelected || this.Behaviour == null)
                        {
                            EditorGUIUtility.PingObject(this.GameObject);
                        }

                        this.Select();
                        GUIHelper.RequestRepaint();
                    }

                    if (this.IsSelected)
                    {
                        GUIHelper.PushGUIEnabled(true);
                        AllEditorGUI.DrawSolidRect(rect, SirenixGUIStyles.MenuButtonActiveBgColor);
                        GUIHelper.PushLabelColor(Color.white);
                        EditorGUILayout.LabelField(this.Name);
                        GUIHelper.PopLabelColor();
                        GUIHelper.PopGUIEnabled();
                    }
                    else
                    {
                        EditorGUILayout.LabelField(this.Name);
                    }
                    rect    = new Rect(rect.position, new Vector2(20, 20));
                    rect.x += 6;

                    const float offAlpha = 0.1f;
                    var         tmpColor = GUI.color;
                    GUI.color = this.WarningCount > 0 ? Color.white : new Color(1, 1, 1, offAlpha);
                    //GL.sRGBWrite = QualitySettings.activeColorSpace == ColorSpace.Linear;
                    GUI.DrawTexture(rect, EditorIcons.UnityWarningIcon);

                    rect.x   += 20;
                    GUI.color = this.ErrorCount > 0 ? Color.white : new Color(1, 1, 1, offAlpha);
                    GUI.DrawTexture(rect, EditorIcons.UnityErrorIcon);

                    if (this.IsIncluded && this.ErrorCount == 0 && this.WarningCount == 0)
                    {
                        rect.x   -= 10;
                        GUI.color = (this.ErrorCount + this.WarningCount) == 0 ? Color.green : new Color(0, 1, 0, offAlpha);
                        GUI.DrawTexture(rect, EditorIcons.Checkmark.Highlighted);
                    }
                    //GL.sRGBWrite = false;

                    GUI.color = tmpColor;
                }
                AllEditorGUI.EndListItem();

                GUIHelper.PopGUIEnabled();
            }
Beispiel #6
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();
        }
Beispiel #7
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();
            }
        }
Beispiel #8
0
        private void DrawType(TypeGroup.TypePair typeToDraw, IPropertyValueEntry <InspectorTypeDrawingConfig> entry)
        {
            Type currentEditorType = typeToDraw.PreExistingEditorType;
            bool conflict          = false;

            if (currentEditorType == null)
            {
                for (int i = 0; i < entry.Values.Count; i++)
                {
                    var type = entry.Values[i].GetEditorType(typeToDraw.DrawnType);

                    if (i == 0)
                    {
                        currentEditorType = type;
                    }
                    else if (type != currentEditorType)
                    {
                        currentEditorType = null;
                        conflict          = true;
                        break;
                    }
                }
            }

            bool useToggle = true;

            AllEditorGUI.BeginListItem();
            {
                AllEditorGUI.BeginIndentedHorizontal();
                AllEditorGUI.IconButton(EditorIcons.Transparent, IconStyle, 16);

                if (typeToDraw.PreExistingEditorType != null)
                {
                    AllEditorGUI.IconButton(EditorIcons.Transparent, IconStyle, 16);
                    GUILayout.Label(typeToDraw.DrawnType.GetNiceName());
                    GUILayout.Label("Drawn by '" + typeToDraw.PreExistingEditorType + "'", SirenixGUIStyles.RightAlignedGreyMiniLabel);

                    for (int i = 0; i < entry.Values.Count; i++)
                    {
                        if (entry.Values[i].HasEntryForType(typeToDraw.DrawnType))
                        {
                            entry.Values[i].ClearEditorEntryForDrawnType(typeToDraw.DrawnType);
                        }
                    }
                }
                else
                {
                    EditorGUI.showMixedValue = conflict;

                    if (useToggle)
                    {
                        bool isToggled = currentEditorType == typeof(OdinEditor);

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

                        if (GUI.changed)
                        {
                            for (int i = 0; i < entry.Values.Count; i++)
                            {
                                entry.Values[i].SetEditorType(typeToDraw.DrawnType, isToggled ? typeof(OdinEditor) : null);
                            }

                            UpdateRootGroupConflicts();
                            InspectorConfig.Instance.UpdateOdinEditors();
                        }

                        GUILayout.Label(typeToDraw.DrawnType.GetNiceName());
                    }
                    else
                    {
                        GUILayout.Label("TODO: DROPDOWN!");
                    }
                }

                AllEditorGUI.EndIndentedHorizontal();
                EditorGUI.showMixedValue = false;
            }
            AllEditorGUI.EndListItem();
        }
Beispiel #9
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();
        }
Beispiel #10
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();
            }
        }