private static Func <IList> DrawEditActions(IList list, Type elementType, int index)
        {
            if (EditorGUILayoutTools.MiniButtonLeft("↑"))
            {
                if (index > 0)
                {
                    return(() =>
                    {
                        var otherIndex = index - 1;
                        var other = list[otherIndex];
                        list[otherIndex] = list[index];
                        list[index] = other;
                        return list;
                    });
                }
            }

            if (EditorGUILayoutTools.MiniButtonMid("↓"))
            {
                if (index < list.Count - 1)
                {
                    return(() =>
                    {
                        var otherIndex = index + 1;
                        var other = list[otherIndex];
                        list[otherIndex] = list[index];
                        list[index] = other;
                        return list;
                    });
                }
            }

            if (EditorGUILayoutTools.MiniButtonMid("+"))
            {
                if (EntityDrawer.CreateDefault(elementType, out var defaultValue))
                {
                    var insertAt = index + 1;
                    return(() =>
                    {
                        list.Insert(insertAt, defaultValue);
                        return list;
                    });
                }
            }

            if (EditorGUILayoutTools.MiniButtonRight("-"))
            {
                var removeAt = index;
                return(() =>
                {
                    list.RemoveAt(removeAt);
                    return list;
                });
            }

            return(null);
        }
예제 #2
0
        private static Func <Array> DrawEditActions(Array array, Type elementType, int index)
        {
            if (EditorGUILayoutTools.MiniButtonLeft("↑"))
            {
                if (index > 0)
                {
                    return(() =>
                    {
                        var otherIndex = index - 1;
                        var other = array.GetValue(otherIndex);
                        array.SetValue(array.GetValue(index), otherIndex);
                        array.SetValue(other, index);
                        return array;
                    });
                }
            }

            if (EditorGUILayoutTools.MiniButtonMid("↓"))
            {
                if (index < array.Length - 1)
                {
                    return(() =>
                    {
                        var otherIndex = index + 1;
                        var other = array.GetValue(otherIndex);
                        array.SetValue(array.GetValue(index), otherIndex);
                        array.SetValue(other, index);
                        return array;
                    });
                }
            }

            if (EditorGUILayoutTools.MiniButtonMid("+"))
            {
                if (EntityDrawer.CreateDefault(elementType, out var defaultValue))
                {
                    return(() => ArrayInsertAt(
                               array,
                               elementType,
                               defaultValue,
                               index + 1));
                }
            }

            if (EditorGUILayoutTools.MiniButtonRight("-"))
            {
                return(() => ArrayRemoveAt(array, elementType, index));
            }

            return(null);
        }