Esempio n. 1
0
        public IEnumerator Run(
            Model.CardList dishCardListModel,
            Model.CardList poolCardListModel)
        {
            Debug.Log("MultipleCardChoose.SetUp");
            done = false;

            dishCardList.SetUp(dishCardListModel, card => true, card => true);
            poolCardList.SetUp(
                poolCardListModel,
                card => true,
                card => dishCardListModel.IndexOf(card) < 0);

            var a1 = poolCardList.OnSelect.Subscribe(
                card => {
                if (dishCardListModel.Count < maxCount)
                {
                    dishCardListModel.Add(card);
                    poolCardList.Hide(card);
                }
            });
            var a2 = dishCardList.OnSelect.Subscribe(
                card => {
                if (minCount < dishCardListModel.Count)
                {
                    dishCardListModel.Remove(card);
                    poolCardList.Show(card);
                }
            }).AddTo(gameObject);
            var a3 = dishCardListModel.Cards.ObserveCountChanged(true)
                     .Select(x => x == maxCount || x == poolCardListModel.Count)
                     .SubscribeToInteractable(okButton);

            yield return(new WaitUntil(() => done));

            a1.Dispose();
            a2.Dispose();
            a3.Dispose();

            dishCardList.TearDown();
            poolCardList.TearDown();
        }
Esempio n. 2
0
        public void SetUp(
            Model.CardList cardList,
            Func <Data.Card, bool> filter,
            Func <Data.Card, bool> show)
        {
            Clear();

            foreach (var card in cardList.Cards)
            {
                if (filter(card))
                {
                    var c = AddCardUI(card);
                    c.gameObject.SetActive(show(card));
                }
            }

            d1 = cardList.Cards.ObserveAdd().Subscribe(
                x => {
                if (filter(x.Value))
                {
                    Debug.Log("AddCard");
                    AddCardUI(x.Value);
                }
            }).AddTo(gameObject);
            d2 = cardList.Cards.ObserveRemove().Subscribe(
                x => {
                foreach (Transform c in transform)
                {
                    if (c.GetComponent <UI.Card>().card == x.Value)
                    {
                        Destroy(c.gameObject);
                    }
                }
            }).AddTo(gameObject);
            d3 = cardList.Cards.ObserveReset().Subscribe(
                x => {
                foreach (Transform c in transform)
                {
                    Destroy(c.gameObject);
                }
            });
        }