예제 #1
0
        private void ApplyTitleStyle(GUITableCell from, GUITableCell to)
        {
            if (from == null)
            {
                throw new NullReferenceException("from");
            }
            if (to == null)
            {
                throw new NullReferenceException("to");
            }

            bool horizontal = from.X < to.X;
            bool vertical   = from.Y < to.Y;

            var titleBgColor = SirenixGUIStyles.ListItemColorEven * 0.9f;

            titleBgColor.a = 0.7f;

            from.GUIStyle += rect =>
            {
                if (!horizontal && !vertical)
                {
                    AllEditorGUI.DrawSolidRect(rect, titleBgColor);
                    rect.height += 1;
                    rect.width  += 1;
                    AllEditorGUI.DrawBorders(rect, 1, 1, 1, 1, SirenixGUIStyles.BorderColor);
                    return;
                }

                float heightOffset = 0;

                if (horizontal)
                {
                    var hRect = rect;
                    heightOffset += hRect.height;
                    hRect.xMax    = to.Rect.xMax;
                    AllEditorGUI.DrawSolidRect(hRect, titleBgColor);
                    hRect.height += 1;
                    hRect.width  += 1;
                    AllEditorGUI.DrawBorders(hRect, 1, 1, 1, 1, SirenixGUIStyles.BorderColor);
                }

                if (vertical)
                {
                    var hRect = rect;
                    hRect.yMin += heightOffset;
                    hRect.yMax  = to.Rect.yMax;
                    AllEditorGUI.DrawSolidRect(hRect, titleBgColor);
                    hRect.height += 1;
                    hRect.width  += 1;
                    AllEditorGUI.DrawBorders(hRect, 1, 1, 1, 1, SirenixGUIStyles.BorderColor);
                }
            };
        }
예제 #2
0
        private void OnGUI()
        {
            this.Focus();
            this.wantsMouseMove = true;

            if (InstanceCreator.Type == null)
            {
                this.Close();
                return;
            }
            else
            {
                this.RootNode = this.RootNode ?? this.GetTypeTree(InstanceCreator.Type);

                AllEditorGUI.BeginHorizontalToolbar(ToolbarBackgroundChainedTop);
                {
                    this.searchChanged = this.searchTerm != (this.searchTerm = AllEditorGUI.ToolbarSearchField(this.searchTerm, true)) || this.searchChanged;
                }
                AllEditorGUI.EndHorizontalToolbar();

                AllEditorGUI.BeginVerticalMenuList(this);
                {
                    this.RootNode.DrawItem();
                }
                AllEditorGUI.EndVerticalMenuList();

                AllEditorGUI.DrawBorders(new Rect(0, 0, this.position.width, this.position.height), 1, 1, 1, 1, SirenixGUIStyles.BorderColor);

                if (Event.current.type == EventType.Repaint)
                {
                    this.hasSearchTerm = this.searchTerm != null && (this.searchTerm.Length >= 2 || (this.searchTerm.Length == 1 && !char.IsLetter(this.searchTerm[0])));

                    if (this.searchChanged)
                    {
                        this.RootNode.UpdateSearchTerm();

                        this.searchChanged = false;
                    }
                }

                if (this.chosenType != null)
                {
                    this.SetSelectedType();
                    this.chosenType = null;
                    this.Close();
                    return;
                }

                this.RepaintIfRequested();
            }
        }
예제 #3
0
        private void DrawToolbar()
        {
            if (Event.current.type == EventType.Layout)
            {
                this.toolbarRect        = this.OuterRect;
                this.toolbarRect.height = this.toolbarHeight;
                this.toolbarRect.x     += 1;
                this.toolbarRect.width -= 1;
            }

            //if (Event.current.OnRepaint())
            //{
            //    AllEditorGUI.DrawBorders(new Rect(GUILayoutUtility.GetLastRect()) { height = this.toolbarHeight }, 1);
            //}

            AllEditorGUI.BeginHorizontalToolbar(this.toolbarHeight);
            foreach (var page in this.OrderedPages)
            {
                if (page.IsActive)
                {
                    if (AllEditorGUI.ToolbarTab(page == (this.nextPage ?? this.CurrentPage), page.Title))
                    {
                        this.nextPage = page;
                    }
                }
            }
            AllEditorGUI.EndHorizontalToolbar();

            if (Event.current.OnRepaint())
            {
                AllEditorGUI.DrawBorders(new Rect(GUILayoutUtility.GetLastRect())
                {
                    height = this.toolbarHeight
                }, 1, 1, 0, 0);
            }
        }
예제 #4
0
        /// <summary>
        /// Creates a table.
        /// </summary>
        public static GUITable Create(int colCount, int rowCount, Action <Rect, int, int> drawElement, string horizontalLabel, Action <Rect, int> columnLabels, string verticalLabel, Action <Rect, int> rowLabels, bool resizable = true)
        {
            int cols = colCount;
            int rows = rowCount;

            if (string.IsNullOrEmpty(verticalLabel) == false)
            {
                cols++;
            }
            if (rowLabels != null)
            {
                cols++;
            }
            if (string.IsNullOrEmpty(horizontalLabel) == false)
            {
                rows++;
            }
            if (columnLabels != null)
            {
                rows++;
            }

            GUITable table = new GUITable(cols, rows);

            cols = colCount;
            rows = rowCount;

            int colStart = 0;
            int rowStart = 0;

            if (string.IsNullOrEmpty(verticalLabel) == false)
            {
                colStart++;
                table[0, Mathf.Max(table.RowCount - 1, 2)] = new GUITableCell()
                {
                    OnGUI = rect =>
                    {
                        if (Event.current.type != EventType.Repaint)
                        {
                            return;
                        }

                        var titleBgColor = SirenixGUIStyles.ListItemColorEven * 0.9f;
                        titleBgColor.a = 0.7f;
                        AllEditorGUI.DrawSolidRect(rect, titleBgColor);

                        rect.width  += 1;
                        rect.height += 1;
                        AllEditorGUI.DrawBorders(rect, 1);
                        rect.width  -= 1;
                        rect.height -= 1;

                        // Rotate -90 degreees:
                        // We can't simply rotate it in place, beacuse Unity will render it to a target before rotating it.
                        // So if that target is not partly visible on the screen horizontally, it will also So if that target is not partly visible on the screen horizontally, it will also
                        // appear partly visible when rendered vertically even tho every thing fits vertifally.
                        // So we need to move the rect in to the screen, so that there is room to render everthing horizontally,
                        // and that when it's rotated, everything is rendered. And bring it back into to correct position.
                        // There are propably better ways of doing it though.
                        var   prev       = GUI.matrix;
                        float prevCenter = rect.x + rect.width * 0.5f;
                        rect   = rect.AlignCenter(rect.height, rect.height);
                        rect.x = 0;
                        float newCenter = rect.x + rect.width * 0.5f;
                        GUIUtility.RotateAroundPivot(-90, rect.center);
                        GUI.matrix = GUI.matrix * Matrix4x4.TRS(new Vector3(0, prevCenter - newCenter, 0), Quaternion.identity, Vector3.one);
                        GUI.Label(rect, verticalLabel, SirenixGUIStyles.LabelCentered);
                        GUI.matrix = prev;
                    },
                    SpanY = true,
                    Width = 22
                };
            }

            if (string.IsNullOrEmpty(horizontalLabel) == false)
            {
                rowStart++;

                table[Mathf.Min(2, table.ColumnCount - 1), 0] = new GUITableCell()
                {
                    OnGUI = rect =>
                    {
                        if (Event.current.type != EventType.Repaint)
                        {
                            return;
                        }


                        var titleBgColor = SirenixGUIStyles.ListItemColorEven * 0.9f;
                        titleBgColor.a = 0.7f;
                        AllEditorGUI.DrawSolidRect(rect, titleBgColor);

                        GUI.Label(rect, horizontalLabel, SirenixGUIStyles.LabelCentered);
                        rect.width  += 1;
                        rect.height += 1;
                        AllEditorGUI.DrawBorders(rect, 1);
                    },
                    SpanX = true
                };
            }

            if (rowLabels != null)
            {
                colStart++;
            }
            if (columnLabels != null)
            {
                rowStart++;
            }

            if (rowLabels != null)
            {
                for (int y = 0; y < rows; y++)
                {
                    int localY = y;
                    table[colStart - 1, rowStart + y] = new GUITableCell()
                    {
                        OnGUI = (rect) => rowLabels.Invoke(rect, localY),
                        Width = 25,
                    };
                }

                table.ApplyListStyle(colStart - 1, rowStart, 0, rows - 1, false);
                table.ApplyTitleStyle(
                    table[colStart - 1, rowStart],
                    table[colStart - 1, rowStart + rows - 1]);
            }

            if (columnLabels != null)
            {
                for (int x = 0; x < cols; x++)
                {
                    int localX = x;
                    table[colStart + x, rowStart - 1] = new GUITableCell()
                    {
                        OnGUI = (rect) => columnLabels.Invoke(rect, localX)
                    };
                }
                table.ApplyListStyle(colStart, rowStart - 1, cols - 1, 0, false);
                table.ApplyTitleStyle(
                    table[colStart, rowStart - 1],
                    table[colStart + cols - 1, rowStart - 1]);
            }

            for (int x = 0; x < cols; x++)
            {
                for (int y = 0; y < rows; y++)
                {
                    int localX = x;
                    int localY = y;
                    table[x + colStart, y + rowStart] = new GUITableCell()
                    {
                        OnGUI = (rect) => { drawElement(rect, localX, localY); }
                    };
                }
            }

            // Make the top left corner transparent.
            // This prevents other cells from spanning into the top corner.
            for (int x = 0; x < colStart; x++)
            {
                for (int y = 0; y < rowStart; y++)
                {
                    table[x, y] = new GUITableCell();
                }
            }

            for (int i = 0; i < table.columnInfos.Length; i++)
            {
                table.columnInfos[i].Resizable = resizable;
            }

            table.ApplyListStyle(colStart, rowStart, cols - 1, rows - 1, true);
            return(table);
        }
예제 #5
0
        /// <summary>
        /// Ends drawing a property tree, and handles management of undo, as well as marking scenes and drawn assets dirty.
        /// </summary>
        /// <param name="tree">The tree.</param>
        public static void EndDrawPropertyTree(PropertyTree tree)
        {
            tree.InvokeDelayedActions();

            if (tree.UnitySerializedObject != null)
            {
                if (mPropertyFieldGetter != null)
                {
                    var    obj = tree.UnitySerializedObject;
                    IntPtr ptr = mPropertyFieldGetter(ref obj);

                    if (ptr == IntPtr.Zero)
                    {
                        // SerializedObject has been disposed, likely due to a scene change invoked from GUI code.
                        // BAIL THE F**K OUT! :D Crashes will happen.
                        return;
                    }
                }

                if (tree.WillUndo)
                {
                    tree.UnitySerializedObject.ApplyModifiedProperties();
                }
                else
                {
                    tree.UnitySerializedObject.ApplyModifiedPropertiesWithoutUndo();
                }
            }

            bool appliedOdinChanges = false;

            if (tree.ApplyChanges())
            {
                appliedOdinChanges = true;
                GUIHelper.RequestRepaint();

                if (tree.TargetType.ImplementsOrInherits(typeof(UnityEngine.Object)))
                {
                    var targets = tree.WeakTargets;

                    for (int i = 0; i < targets.Count; i++)
                    {
                        var target = (UnityEngine.Object)targets[i];

                        if (AssetDatabase.Contains(target))
                        {
                            EditorUtility.SetDirty(target);
                        }
                        else if (Application.isPlaying == false)
                        {
#if UNITY_5_3_OR_NEWER
                            if (tree.TargetType.ImplementsOrInherits(typeof(Component)))
                            {
                                Component component = (Component)target;
                                UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(component.gameObject.scene);
                            }
                            else
                            {
                                // We can't find out where this thing is from
                                // It is probably a "temporary" UnityObject created from a script somewhere
                                // Just to be safe, mark it as dirty, and mark all scenes as dirty

                                EditorUtility.SetDirty(target);
                                UnityEditor.SceneManagement.EditorSceneManager.MarkAllScenesDirty();
                            }
#else
                            EditorApplication.MarkSceneDirty();
#endif
                        }
                    }
                }
            }

            // This is very important, as applying changes may cause more actions to be delayed
            tree.InvokeDelayedActions();

            if (appliedOdinChanges)
            {
                tree.InvokeOnValidate();
            }

            drawnInspectorDepthCount--;

#if ODIN_TRIAL_VERSION
            if (drawnInspectorDepthCount == 0)
            {
                float height = OdinTrialVersionInfo.IsExpired ? 22 : 17;
                var   rect   = GUILayoutUtility.GetRect(16, height, GUILayoutOptions.ExpandWidth().Height(height));

                var bgRect = rect;
                bgRect.xMin -= 20;
                bgRect.xMax += 20;
                bgRect.y    += 2;
                AllEditorGUI.DrawBorders(bgRect, 0, 0, 1, 0, SirenixGUIStyles.LightBorderColor);

                rect.y += 2;
                if (OdinTrialVersionInfo.IsExpired)
                {
                    EditorGUI.DrawRect(bgRect, Color.black);
                    GUIHelper.PushContentColor(Color.red);

                    GUI.Label(rect.AddY(3), "ODIN Inspector Trial expired!", SirenixGUIStyles.Label);
                    GUIHelper.PopContentColor();
                    var btnRect = rect.AlignRight(EditorStyles.miniButton.CalcSize(new GUIContent("Purchase ODIN Inspector")).x);
                    btnRect.yMin += 2;
                    btnRect.yMax -= 2;
                    GUIHelper.PushColor(Color.green);
                    if (GUI.Button(btnRect, "Purchase ODIN Inspector", EditorStyles.miniButton))
                    {
                        UnityEditorInternal.AssetStore.Open("content/89041");
                    }
                    GUIHelper.PopColor();
                }
                else
                {
                    GUI.Label(rect, "ODIN Inspector Trial Version", SirenixGUIStyles.LeftAlignedGreyMiniLabel);
                    GUI.Label(rect, "Expires " + OdinTrialVersionInfo.ExpirationDate.ToShortDateString(), EditorStyles.centeredGreyMiniLabel);
                    GUI.Label(rect, OdinTrialVersionInfo.ExpirationDate.Subtract(System.DateTime.Now).TotalHours.ToString("F2") + " hours remaining.", SirenixGUIStyles.RightAlignedGreyMiniLabel);
                }
            }
#endif
        }
예제 #6
0
        public static float Draw <T>(OdinDrawer drawerInstance, IPropertyValueEntry <T> entry, float progress, ProgressBarAttribute attribute, GUIContent label)
        {
            PropertyContext <ProgressBarContext <T> > contextBuffer;

            if (entry.Context.Get <ProgressBarContext <T> >(drawerInstance, "ProgressBarContext", out contextBuffer))
            {
                var parentType = entry.Property.FindParent(PropertyValueCategory.Member, true).ParentType;
                contextBuffer.Value = new ProgressBarContext <T>();

                if (!attribute.ColorMember.IsNullOrWhitespace())
                {
                    MemberInfo member;
                    if (MemberFinder.Start(parentType)
                        .IsNamed(attribute.ColorMember)
                        .HasReturnType <Color>()
                        .TryGetMember(out member, out contextBuffer.Value.ErrorMessage))
                    {
                        if (member is FieldInfo || member is PropertyInfo)
                        {
                            if (member.IsStatic())
                            {
                                contextBuffer.Value.StaticColorGetter = DeepReflection.CreateValueGetter <Color>(parentType, attribute.ColorMember);
                            }
                            else
                            {
                                contextBuffer.Value.InstanceColorGetter = DeepReflection.CreateWeakInstanceValueGetter <Color>(parentType, attribute.ColorMember);
                            }
                        }
                        else if (member is MethodInfo)
                        {
                            if (member.IsStatic())
                            {
                                contextBuffer.Value.ErrorMessage = "Static method members are currently not supported.";
                            }
                            else
                            {
                                var method = member as MethodInfo;
                                var p      = method.GetParameters();

                                if (p.Length == 0)
                                {
                                    contextBuffer.Value.InstanceColorMethod = EmitUtilities.CreateWeakInstanceMethodCallerFunc <Color>(method);
                                }
                                else if (p.Length == 1 && p[0].ParameterType == typeof(T))
                                {
                                    contextBuffer.Value.InstanceColorParameterMethod = EmitUtilities.CreateWeakInstanceMethodCallerFunc <T, Color>(method);
                                }
                            }
                        }
                        else
                        {
                            contextBuffer.Value.ErrorMessage = "Unsupported member type.";
                        }
                    }
                }
                if (!attribute.BackgroundColorMember.IsNullOrWhitespace())
                {
                    MemberInfo member;
                    if (MemberFinder.Start(parentType)
                        .IsNamed(attribute.BackgroundColorMember)
                        .HasReturnType <Color>()
                        .TryGetMember(out member, out contextBuffer.Value.ErrorMessage))
                    {
                        if (member is FieldInfo || member is PropertyInfo)
                        {
                            if (member.IsStatic())
                            {
                                contextBuffer.Value.StaticBackgroundColorGetter = DeepReflection.CreateValueGetter <Color>(parentType, attribute.BackgroundColorMember);
                            }
                            else
                            {
                                contextBuffer.Value.InstanceBackgroundColorGetter = DeepReflection.CreateWeakInstanceValueGetter <Color>(parentType, attribute.BackgroundColorMember);
                            }
                        }
                        else if (member is MethodInfo)
                        {
                            if (member.IsStatic())
                            {
                                contextBuffer.Value.ErrorMessage = "Static method members are currently not supported.";
                            }
                            else
                            {
                                var method = member as MethodInfo;
                                var p      = method.GetParameters();

                                if (p.Length == 0)
                                {
                                    contextBuffer.Value.InstanceBackgroundColorMethod = EmitUtilities.CreateWeakInstanceMethodCallerFunc <Color>(method);
                                }
                                else if (p.Length == 1 && p[0].ParameterType == typeof(T))
                                {
                                    contextBuffer.Value.InstanceBackgroundColorParameterMethod = EmitUtilities.CreateWeakInstanceMethodCallerFunc <T, Color>(method);
                                }
                            }
                        }
                        else
                        {
                            contextBuffer.Value.ErrorMessage = "Unsupported member type.";
                        }
                    }
                }
            }

            var context = contextBuffer.Value;

            // Error message
            if (context.ErrorMessage != null)
            {
                AllEditorGUI.ErrorMessageBox(context.ErrorMessage);
            }

            // Construct rect.
            Rect rect;

            if (label != null)
            {
                rect = EditorGUILayout.GetControlRect(true, attribute.Height > EditorGUIUtility.singleLineHeight ? attribute.Height : EditorGUIUtility.singleLineHeight);
                rect = EditorGUI.PrefixLabel(rect, label);
                rect = rect.AlignMiddle(attribute.Height);
            }
            else
            {
                rect = EditorGUILayout.GetControlRect(false, attribute.Height);
                GUIHelper.IndentRect(ref rect);
            }

            // Draw
            if (Event.current.type == EventType.Repaint)
            {
                var parent = entry.Property.FindParent(PropertyValueCategory.Member, true).ParentValues[0];

                Color color =
                    context.StaticColorGetter != null?context.StaticColorGetter() :
                        context.InstanceColorGetter != null?context.InstanceColorGetter(parent) :
                            context.InstanceColorMethod != null?context.InstanceColorMethod(parent) :
                                context.InstanceColorParameterMethod != null?context.InstanceColorParameterMethod(parent, entry.SmartValue) :
                                    new Color(attribute.R, attribute.G, attribute.B, 1f);

                Color backgroundColor =
                    context.StaticBackgroundColorGetter != null?context.StaticBackgroundColorGetter() :
                        context.InstanceBackgroundColorGetter != null?context.InstanceBackgroundColorGetter(parent) :
                            context.InstanceBackgroundColorMethod != null?context.InstanceBackgroundColorMethod(parent) :
                                context.InstanceBackgroundColorParameterMethod != null?context.InstanceBackgroundColorParameterMethod(parent, entry.SmartValue) :
                                    new Color(0.16f, 0.16f, 0.16f, 1f);

                AllEditorGUI.DrawSolidRect(rect, backgroundColor);
                AllEditorGUI.DrawSolidRect(rect.AlignLeft(rect.width * Mathf.Clamp01(progress)), color);
                AllEditorGUI.DrawBorders(rect, 1, new Color(0.16f, 0.16f, 0.16f, 1f));
            }

            if (GUI.enabled)
            {
                int controlID = GUIUtility.GetControlID(FocusType.Passive);
                if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && rect.Contains(Event.current.mousePosition) ||
                    GUIUtility.hotControl == controlID && (Event.current.type == EventType.MouseMove || Event.current.type == EventType.MouseDrag))
                {
                    Event.current.Use();
                    GUIUtility.hotControl = controlID;
                    GUIHelper.RequestRepaint();
                    GUI.changed = true;

                    progress = (Event.current.mousePosition.x - rect.xMin) / rect.width;
                }
                else if (GUIUtility.hotControl == controlID && Event.current.rawType == EventType.MouseUp)
                {
                    GUIUtility.hotControl = 0;
                }
            }

            return(progress);
        }
예제 #7
0
            public void UpdateTable(InspectorProperty property, TableListAttribute attribute, string label)
            {
                if (this.Table == null)
                {
                    this.update = true;
                }

                if (this.SwitchView && Event.current.type == EventType.Layout)
                {
                    this.DrawList.Value = !this.DrawList.Value;
                    this.SwitchView     = false;
                    if (!this.DrawList.Value)
                    {
                        this.update = true;
                    }
                }

                if (this.Paging.ElementCount != property.Children.Count)
                {
                    this.update = true;
                }

                this.Paging.Update(property.Children.Count);

                if (!this.update)
                {
                    return;
                }

                this.update     = false;
                this.WasUpdated = true;

                HashSet <string>         seenColumns      = new HashSet <string>();
                List <InspectorProperty> columnProperties = new List <InspectorProperty>();

                for (int i = this.Paging.StartIndex; i < this.Paging.EndIndex; i++)
                {
                    var listItem = property.Children[i];

                    if (listItem.Children.Count != 0)
                    {
                        for (int j = 0; j < listItem.Children.Count; j++)
                        {
                            var child = listItem.Children[j];
                            if (seenColumns.Add(child.Name))
                            {
                                columnProperties.Add(child);
                            }
                        }
                    }
                }

                columnProperties.Sort((a, b) => (a.Info.Order + a.Index * 0.01f).CompareTo(b.Info.Order + b.Index * 0.01f));

                GUITableColumn[] columns = new GUITableColumn[columnProperties.Count + 1];

                for (int i = 0; i < columnProperties.Count; i++)
                {
                    int columnIndex = i;
                    var p           = columnProperties[i];

                    TableColumnWidthAttribute attr = null;

                    if (p.Info.PropertyType == PropertyType.Group)
                    {
                        attr = EnumerateGroupMembers(p)
                               .Select(c => c.Info.GetAttribute <TableColumnWidthAttribute>())
                               .FirstOrDefault(x => x != null);
                    }
                    else
                    {
                        attr = p.Info.GetAttribute <TableColumnWidthAttribute>();
                    }

                    float width = 0;

                    if (attr != null)
                    {
                        width = attr.Width;
                    }

                    columns[i] = new GUITableColumn()
                    {
                        OnGUI = (rect, index) =>
                        {
                            var listItem        = property.Children[index + this.Paging.StartIndex];
                            var listItemElement = listItem.Children[p.Name];
                            if (listItemElement != null)
                            {
                                rect.x = (int)rect.x; // Fixes text flickering
                                GUILayout.BeginArea(rect);
                                var height     = EditorGUILayout.BeginVertical(SirenixGUIStyles.OdinEditorWrapper).height + 3;
                                var labelWidth = rect.width * 0.3f;
                                GUIHelper.PushLabelWidth(labelWidth);
                                listItemElement.Draw(null);
                                GUIHelper.PopLabelWidth();
                                EditorGUILayout.EndVertical();

                                if (Event.current.type == EventType.Repaint)
                                {
                                    var cell = this.Table[columnIndex, index + 2];
                                    if (cell.Height != height)
                                    {
                                        cell.Height = height;
                                        this.Table.MarkDirty();
                                    }
                                }

                                GUILayout.EndArea();
                            }
                        },
                        Width       = width,
                        ColumnTitle = p.Label == null ? p.NiceName : p.Label.text
                    };
                }

                columns[columnProperties.Count] = new GUITableColumn()
                {
                    OnGUI = (rect, index) =>
                    {
                        if (Event.current.type == EventType.Repaint)
                        {
                            rect = rect.AlignCenter(14, 14);
                        }
                        if (AllEditorGUI.IconButton(rect, EditorIcons.X))
                        {
                            this.ListChanger.RemoveListElementAt(this.Paging.StartIndex + index, CHANGE_ID);
                        }
                    },
                    ColumnTitle = "",
                    Width       = 20,
                    Resizable   = false
                };

                this.Table = GUITable.Create(this.Paging.EndIndex - this.Paging.StartIndex, label, columns);

                this.Table[0, 0].OnGUI = rect =>
                {
                    var fullRect = rect;

                    rect = rect.AlignRight(20);
                    AllEditorGUI.DrawBorders(rect, 1, 0, 0, 0);
                    if (AllEditorGUI.IconButton(rect.AlignCenter(19, 19), EditorIcons.Plus))
                    {
                        if (this.ListChanger.ElementType.InheritsFrom <UnityEngine.Object>() && Event.current.modifiers == EventModifiers.Control)
                        {
                            this.ListChanger.AddListElement(new object[this.ListChanger.ValueCount], "Add Unity Null Value");
                        }
                        else
                        {
                            this.ObjectPicker.ShowObjectPicker(
                                property.Info.GetAttribute <AssetsOnlyAttribute>() == null,
                                rect,
                                property.ValueEntry.SerializationBackend == SerializationBackend.Unity);
                        }
                    }

                    rect.x    -= 24;
                    rect.width = 24;
                    AllEditorGUI.DrawBorders(rect, 1, 0, 0, 0);
                    if (AllEditorGUI.IconButton(rect.AlignCenter(23, 23), EditorIcons.List))
                    {
                        this.SwitchView = true;
                    }

                    rect.x    -= 24;
                    rect.width = 24;
                    AllEditorGUI.DrawBorders(rect, 1, 0, 0, 0);
                    if (AllEditorGUI.IconButton(rect.AlignCenter(20, 20), EditorIcons.Refresh))
                    {
                        this.update = true;
                    }

                    if (this.Paging.PageCount > 1)
                    {
                        rect.x    -= 24;
                        rect.width = 24;
                        AllEditorGUI.DrawBorders(rect, 1, 0, 0, 0);

                        if (this.Paging.IsOnLastPage)
                        {
                            GUIHelper.PushGUIEnabled(false);
                        }

                        if (AllEditorGUI.IconButton(rect.AlignCenter(20, 20), EditorIcons.TriangleRight))
                        {
                            property.Tree.DelayActionUntilRepaint(() =>
                            {
                                this.Paging.CurrentPage++;
                                this.update = true;
                            });
                        }

                        if (this.Paging.IsOnLastPage)
                        {
                            GUIHelper.PopGUIEnabled();
                        }

                        rect.x    -= 27;
                        rect.width = 27;
                        AllEditorGUI.DrawBorders(rect, 1, 0, 0, 0);
                        GUI.Label(rect.AlignMiddle(16), " / " + this.Paging.PageCount);

                        rect.x    -= 35;
                        rect.width = 35;
                        AllEditorGUI.DrawBorders(rect, 1, 0, 0, 0);

                        EditorGUI.BeginChangeCheck();
                        this.Paging.CurrentPage = EditorGUI.IntField(rect.HorizontalPadding(4).AlignMiddle(16), this.Paging.CurrentPage + 1) - 1;
                        if (EditorGUI.EndChangeCheck())
                        {
                            this.update = true;
                        }

                        if (this.Paging.IsOnFirstPage)
                        {
                            GUIHelper.PushGUIEnabled(false);
                        }

                        rect.x    -= 24;
                        rect.width = 24;
                        AllEditorGUI.DrawBorders(rect, 1, 0, 0, 0);
                        if (AllEditorGUI.IconButton(rect.AlignCenter(20, 20), EditorIcons.TriangleLeft))
                        {
                            property.Tree.DelayActionUntilRepaint(() =>
                            {
                                this.Paging.CurrentPage--;
                                this.update = true;
                            });
                        }

                        if (this.Paging.IsOnFirstPage)
                        {
                            GUIHelper.PopGUIEnabled();
                        }
                    }

                    fullRect.xMax = rect.xMin;

                    GUI.Label(fullRect, this.Paging.ElementCount + " items", SirenixGUIStyles.RightAlignedGreyMiniLabel);
                    GUI.Label(fullRect, label, SirenixGUIStyles.LabelCentered);
                };
            }
예제 #8
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();
        }