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));
        }
Esempio n. 2
0
    private void Awake()
    {
        agent = agentCube;

        F_Btn.onClick.AddListener(() => ChangeKeyCode(KeyType.F));
        B_Btn.onClick.AddListener(() => ChangeKeyCode(KeyType.B));
        L_Btn.onClick.AddListener(() => ChangeKeyCode(KeyType.L));
        R_Btn.onClick.AddListener(() => ChangeKeyCode(KeyType.R));

        undoBtn.onClick.AddListener(Undo);
        redoBtn.onClick.AddListener(Redo);

        cubeBtn.onClick.AddListener(() => agent   = agentCube);
        sphereBtn.onClick.AddListener(() => agent = agentSphere);

        UndoStack.ObserveCountChanged().Subscribe(x => undoBtn.interactable = x > 0 ? true : false);
        UndoStack.ObserveRemove().Subscribe(x => RedoStack.Add(x.Value));

        RedoStack.ObserveCountChanged().Subscribe(x => redoBtn.interactable = x > 0 ? true : false);
        RedoStack.ObserveRemove().Subscribe(x => UndoStack.Add(x.Value));

        commandIndex.TakeUntilDestroy(gameObject).Subscribe(x =>
        {
            if (x > -1)
            {
                commandImagesDic[x].color = Color.red;
            }
        });
    }
Esempio n. 3
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;
     }));
 }
Esempio n. 4
0
        // public void Ctor(HandModel handModel)
        // {
        //     _model = handModel;
        // }

        public void Init()
        {
            _cards = new ReactiveCollection <CardPresenter>();

            RandomSetter.interactable = true;

            RandomSetter
            .OnClickAsObservable()
            .Subscribe(_ => _cards[_id++ % _cards.Count].SetRandomValue())
            .AddTo(this);

            _cards
            .ObserveAdd()
            .Throttle(TimeSpan.FromMilliseconds(250))
            .Subscribe(c => RebuildCardPosition())
            .AddTo(this);

            _cards
            .ObserveRemove()
            .Throttle(TimeSpan.FromMilliseconds(50))
            .Subscribe(c => RebuildCardPosition())
            .AddTo(this);

            _cards
            .ObserveAdd()
            .Subscribe(c => AddDragDrop(c.Value))
            .AddTo(this);

            foreach (var cc in FindObjectsOfType <CardPresenter>())
            {
                var cardModel = new CardModel(_assetDbService);
                cc.Ctor(cardModel);

                _cards.Add(cc);
            }

            _arc = new Arc3()
            {
                p0 = Arc3Root.gameObject.transform.InverseTransformPoint(Arc3Root.GetChild(0).transform.position),
                p1 = Arc3Root.gameObject.transform.InverseTransformPoint(Arc3Root.GetChild(1).transform.position),
                p2 = Arc3Root.gameObject.transform.InverseTransformPoint(Arc3Root.GetChild(2).transform.position),
            };

            // _model.IsDead
            //     .Where(isDead => isDead)
            //     .Subscribe(_ =>
            //     {
            //         _model = null;
            //         Destroy(gameObject);
            //     })
            //     .AddTo(this);;
            //
            // AddDragDrop(this);
        }
        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));
        }
Esempio n. 6
0
        /// <summary>
        /// Sets the collection to be processed by this behaviour
        /// </summary>
        /// <param name="collection"></param>
        public void SetCollection(IReactiveCollection <T> collection)
        {
            // Delete previous collection and views
            ClearSubscriptions();
            DestroyAllViews();

            subscriptions = new CompositeDisposable();
            collection.ObserveAdd().Subscribe(evt => ProcessAdd(evt.Value)).AddTo(subscriptions);
            collection.ObserveRemove().Subscribe(evt => ProcessRemove(evt.Value)).AddTo(subscriptions);
            collection.ObserveReset().Subscribe(ProcessReset).AddTo(subscriptions);

            // Add all initial objects
            foreach (var model in collection)
            {
                ProcessAdd(model);
            }
        }
        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));
        }