コード例 #1
0
ファイル: UnitViewModel.cs プロジェクト: KonH/UniRxGameSample
        public UnitViewModel(UnitConfig config, UnitModel model, ResourcePackViewModel resources)
        {
            Assert.IsNotNull(config, nameof(config));
            Assert.IsNotNull(model, nameof(model));
            Assert.IsNotNull(resources, nameof(resources));

            _config       = config;
            _model        = model;
            _resources    = resources;
            _sprite       = new ReactiveProperty <Sprite>();
            Sprite        = _sprite.ToReadOnlyReactiveProperty();
            _level        = new ReactiveProperty <int>(_model.Level);
            Level         = _level.ToReadOnlyReactiveProperty();
            Income        = new ResourceViewModel(model.Income);
            _upgradePrice = new ReactiveProperty <ResourceViewModel>(GetUpgradePrice());
            UpgradePrice  = _upgradePrice.ToReadOnlyReactiveProperty();
            _canUpgrade   = new ReactiveProperty <bool>(IsUpgradeAvailable());
            CanUpgrade    = _canUpgrade.ToReadOnlyReactiveProperty();
            foreach (var resource in resources.Resources)
            {
                resource.Value.Amount
                .Select(_ => IsUpgradeAvailable())
                .Subscribe(isAvailable => _canUpgrade.Value = isAvailable);
            }

            Level
            .Do(l => _model.Level = l)
            .Subscribe(OnLevelUpdated);
        }
コード例 #2
0
    public void PostInit()
    {
        SceneLoader instance = SceneLoader.Instance;

        IAPCompleted = (from completed in PersistentSingleton <IAPService> .Instance.IAPCompleted
                        select(completed)).TakeUntilDestroy(instance).ToSequentialReadOnlyReactiveProperty();
        IAPCompleted.Subscribe(delegate
        {
            if (IAPCompleted.Value.Config.Reward.Type != 0)
            {
                RewardForPurchase(IAPCompleted.Value.Config);
                PurchaseSuccess.SetValueAndForceNotify(value: true);
            }
        }).AddTo(instance);
        IAPNotCompleted = (from notCompleted in PersistentSingleton <IAPService> .Instance.IAPNotCompleted
                           where notCompleted.Status == "Failed" || notCompleted.Status == "Cancelled"
                           select(notCompleted)).TakeUntilDestroy(instance).ToSequentialReadOnlyReactiveProperty();
        IAPNotCompleted.Do(delegate
        {
        }).Subscribe(delegate
        {
            PurchaseFail.SetValueAndForceNotify(value: true);
        }).AddTo(instance);
    }