Exemple #1
0
        private void CreateItemViewModel()
        {
            var armor  = demoItemViewModel.Armor.Value + itemsCounter;
            var damage = demoItemViewModel.Damage.Value + itemsCounter;
            var level  = demoItemViewModel.Level.Value + itemsCounter;
            var cost   = (armor + damage) + level * 100;

            var model = new DemoItemViewModel()
            {
                Armor  = new IntReactiveProperty(armor),
                Damage = new IntReactiveProperty(damage),
                Level  = new IntReactiveProperty(level),
                Cost   = new IntReactiveProperty(cost),
                Icon   = new ReactiveProperty <Sprite>(icons.Length == 0 ? null : icons[itemsCounter % icons.Length]),
                Sell   = new ReactiveCommand(),
                Remove = new ReactiveCommand(),
            };

            model.Bind(model.Sell, x => {
                resourceModel.Gold.Value += model.Cost.Value;
                listModel.ListItems.Remove(model);
            });

            model.Bind(model.Remove, x => listModel.ListItems.Remove(model));

            listModel.ListItems.Add(model);
        }
        private async UniTask <DemoItemView> CreateItem(DemoItemViewModel itemModel)
        {
            var view = await Layout.Create <DemoItemView>(itemModel);

            view.transform.SetParent(itemsParent);
            itemViews.Add(view);
            LayoutRebuilder.MarkLayoutForRebuild(itemsParent);
            return(view);
        }