Пример #1
0
        public static IDisposable BindOptionsTo(this Dropdown input, IReactiveCollection <string> options)
        {
            var addSubscription = options.ObserveAdd().Subscribe(x =>
            {
                var newOption = new Dropdown.OptionData {
                    text = x.Value
                };
                input.options.Insert(x.Index, newOption);
            });

            var updateSubscription = options.ObserveReplace().Subscribe(x =>
            {
                var existingOption  = input.options[x.Index];
                existingOption.text = x.NewValue;
            });

            var removeSubscription = options.ObserveRemove().Subscribe(x => input.options.RemoveAt(x.Index));

            input.options.Clear();

            foreach (var option in options)
            {
                var newOption = new Dropdown.OptionData {
                    text = option
                };
                input.options.Add(newOption);
            }

            return(new CompositeDisposable(addSubscription, updateSubscription, removeSubscription).AddTo(input));
        }
        public static IDisposable BindOptionsTo <T>(this TMP_Dropdown input, IReactiveCollection <T> options,
                                                    Func <T, string> textLocator, Func <T, Sprite> spriteLocator = null)
        {
            var addSubscription = options.ObserveAdd().Subscribe(x =>
            {
                var newOption = new TMP_Dropdown.OptionData {
                    text = textLocator(x.Value)
                };
                if (spriteLocator != null)
                {
                    newOption.image = spriteLocator(x.Value);
                }

                input.options.Insert(x.Index, newOption);
            });

            var updateSubscription = options.ObserveReplace().Subscribe(x =>
            {
                var existingOption  = input.options[x.Index];
                existingOption.text = textLocator(x.NewValue);

                if (spriteLocator != null)
                {
                    existingOption.image = spriteLocator(x.NewValue);
                }
            });

            var removeSubscription = options.ObserveRemove().Subscribe(x => input.options.RemoveAt(x.Index));

            input.options.Clear();

            foreach (var option in options)
            {
                var newOption = new TMP_Dropdown.OptionData {
                    text = textLocator(option)
                };

                if (spriteLocator != null)
                {
                    newOption.image = spriteLocator(option);
                }

                input.options.Add(newOption);
            }

            return(new CompositeDisposable(addSubscription, updateSubscription, removeSubscription).AddTo(input));
        }
Пример #3
0
        public static IDisposable BindOptionsTo(this Dropdown input, IReactiveCollection <Dropdown.OptionData> options)
        {
            var addSubscription    = options.ObserveAdd().Subscribe(x => input.options.Insert(x.Index, x.Value));
            var removeSubscription = options.ObserveRemove().Subscribe(x => input.options.RemoveAt(x.Index));
            var updateSubscription = options.ObserveReplace().Subscribe(x =>
            {
                input.options.RemoveAt(x.Index);
                input.options.Insert(x.Index, x.NewValue);
            });

            input.options.Clear();

            foreach (var option in options)
            {
                input.options.Add(option);
            }

            return(new CompositeDisposable(addSubscription, updateSubscription, removeSubscription).AddTo(input));
        }
Пример #4
0
 //用于重新搜索全表
 public static UniRx.IObservable <IReactiveCollection <T> > ObserveItemChanged <T>(this IReactiveCollection <T> reactCollection)
 {
     return(reactCollection.ObserveAdd().CombineLatest(reactCollection.ObserveRemove(), reactCollection.ObserveMove(), reactCollection.ObserveReplace(), reactCollection.ObserveReset(),
                                                       (add, remove, move, replace, reset) =>
     {
         return reactCollection;
     }));
 }