예제 #1
0
        static Func <IList> drawEditActions(IList list, Type elementType, int index)
        {
            if (EditorLayout.MiniButtonLeft("↑"))
            {
                if (index > 0)
                {
                    return(() => {
                        var otherIndex = index - 1;
                        var other = list[otherIndex];
                        list[otherIndex] = list[index];
                        list[index] = other;
                        return list;
                    });
                }
            }

            if (EditorLayout.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 (EditorLayout.MiniButtonMid("+"))
            {
                object defaultValue;
                if (EntityDrawer.CreateDefault(elementType, out defaultValue))
                {
                    var insertAt = index + 1;
                    return(() => {
                        list.Insert(insertAt, defaultValue);
                        return list;
                    });
                }
            }

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

            return(null);
        }
예제 #2
0
        static Func <Array> drawEditActions(Array array, Type elementType, int index)
        {
            if (EditorLayout.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 (EditorLayout.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 (EditorLayout.MiniButtonMid("+"))
            {
                object defaultValue;
                if (EntityDrawer.CreateDefault(elementType, out defaultValue))
                {
                    return(() => arrayInsertAt(array, elementType, defaultValue, index + 1));
                }
            }

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

            return(null);
        }