Ejemplo n.º 1
0
    private void SubscribeTo(Level level)
    {
        Observable.CombineLatest(HitCount, DestroyedTargetCount, TargetsToDestory)
        .Where(x => x[0] <= 0 && x[1] != x[2])
        .Take(1)
        .Subscribe(_ => {
            Debug.Log("Level Failed");
            GetComponent <SceneTransition>().ReloadScene();
        })
        .AddTo(disposables);

        Observable.CombineLatest(HitCount, DestroyedTargetCount, TargetsToDestory)
        .Where(x => x[0] >= 0 && x[1] == x[2])
        .Take(1)
        .Subscribe(_ => {
            Debug.Log("Level Completed");
            GetComponent <SceneTransition>().ReloadScene();
        })
        .AddTo(disposables);

        Observable.FromEvent(
            h => level.Projectile.OnBallCollided += h,
            h => level.Projectile.OnBallCollided -= h)
        .ObserveOnMainThread()
        .TakeUntil(HitCount.Where(x => x <= 0))
        .Delay(TimeSpan.FromMilliseconds(100))
        .Subscribe(_ => {
            HitCount.Value--;
        })
        .AddTo(disposables);


        level.Targets.ToList().ForEach(target => {
            target.OnCollisonEntered += x => print("Target hit with id: " + x.GetInstanceID());

            Observable.FromEvent <BaseTarget>(
                h => target.OnCollisonEntered += h,
                h => target.OnCollisonEntered -= h)
            .ObserveOnMainThread()
            .Subscribe(x => {
                print("Target hit with id: " + x.GetInstanceID());
            })
            .AddTo(disposables);

            Observable.FromEvent <BaseTarget>(
                h => target.OnDestroy += h,
                h => target.OnDestroy -= h)
            .ObserveOnMainThread()
            .Subscribe(x => {
                print("Target destroyed with id: " + x.GetInstanceID());
                x.Destroy();
                DestroyedTargetCount.Value++;
            })
            .AddTo(disposables);
        });
    }
Ejemplo n.º 2
0
    void Start()
    {
        mainText       = GameObject.Find("/GameManager/PlayerCanvas/MainText").GetComponentInChildren <Text>();
        mainText.text  = "";
        timerText      = GameObject.Find("/GameManager/PlayerCanvas/TimerText").GetComponentInChildren <Text>();
        timerText.text = minute.ToString("00") + "." + seconds.ToString("00.000");;

        //スタートカウントダウン
        Observable.Interval(System.TimeSpan.FromSeconds(1))
        .Take(4)
        .Subscribe(_ =>
        {
            mainText.text = countDown.ToString();
            if (countDown == 0)
            {
                AudioManager.Instance.PlaySE("SE_START");
            }
            else
            {
                AudioManager.Instance.PlaySE("SE_COUNTDOWN");
            }
            countDown--;
        }, () =>
        {
            mainText.text = "Start!";
            timerflag     = true;
            countDownFinish.OnNext(Unit.Default);
            Observable.Timer(System.TimeSpan.FromSeconds(1))
            .Subscribe(_ =>
            {
                mainText.text = "";
                AudioManager.Instance.PlayBGM("BGM_MAIN");
            });

            Observable.EveryUpdate()
            .Where(_ => timerflag)
            .Subscribe(_ =>
            {
                seconds += Time.deltaTime;
                if (seconds >= 60f)
                {
                    minute++;
                    seconds = seconds - 60;
                }

                timerText.text = minute.ToString("00") + "." + seconds.ToString("00.000");
            });
        });

        enemynumber.Where(e => e == 0)
        .Subscribe(_ =>
        {
            timerflag     = false;
            mainText.text = "Clear!\nTime : " + minute.ToString("00") + "." + seconds.ToString("00.000");
        });
    }
Ejemplo n.º 3
0
    private void Start()
    {
        // HPが0以下になったら通知
        isDead = currentHP.Select(hp => hp <= 0).ToReactiveProperty();

        // HPの変更があったらhpTextを(現在のHPに)変更する
        currentHP.Where(_ => !isDead.Value).Subscribe(hp => hpText.text = hp.ToString());

        // ボタンをおしたらHPが1減るようにする
        damageButton.OnClickAsObservable().Subscribe(_ => currentHP.Value -= 1);

        // 死んだら死んだと表示する
        isDead.Where(d => d).Subscribe(_ => hpText.text = "死んだ");
    }
Ejemplo n.º 4
0
    void HandleEndGame()
    {
        timeRemaining
        .Where((x) => x == 0)
        .Subscribe((x) => {
            currentView.SetValueAndForceNotify("endScreen");
        });

        deliveriesRemaining
        .Where((x) => x == 0)
        .Subscribe((x) => {
            currentView.SetValueAndForceNotify("endScreen");
        });
    }
Ejemplo n.º 5
0
 private void Start()
 {
     ProgressObservable
     .Where(_ => isTutorial)
     .Distinct()
     .DelayFrame(1)
     .Subscribe(async x =>
     {
         flowchart.SetIntegerVariable(key, x);
         await UniTask.WaitUntil(() => !flowchart.GetExecutingBlocks().Any(b => b.BlockName == "Tutorial"));
         flowchart.ExecuteBlock("Tutorial");
     }).AddTo(gameObject);
     flowchart.ObserveEveryValueChanged(f => f.GetIntegerVariable(key))
     .Subscribe(v => ProgressObservable.Value = v).AddTo(gameObject);
 }
Ejemplo n.º 6
0
    void StageIntro()
    {
        GameStartPanel.SetActive(true);
        hero.SetMoveable(false);
        stageJson = SGUtils.GetJsonArrayForKey(JsonMapper.ToObject(stageJsonAsset.text), "stage", SceneManager.GetActiveScene().name);
        stageTime = int.Parse(stageJson["playtime"].ToString());

        if (!SGGameData.Instance.inifinityMode)
        {
            timerSlider.SetTimerText(stageTime);
        }

        for (int s = 0; s < stageJson["waveInfo"].Count; s++)
        {
            monsterCount.Value += int.Parse(stageJson["waveInfo"][s]["Count"].ToString());
        }

        monsterCount.Where(_ => _ <= 0).Subscribe(_ => {
            if (gameState.Value == SGE_GameState.STAGE_START)
            {
                gameState.Value = SGE_GameState.STAGE_CLEAR;
            }
        });
    }
    private void Start()
    {
        if (this.gameObject.transform.parent.gameObject.tag == "Player1")
        {
            thisPlayerNo = 1;
        }
        if (this.gameObject.transform.parent.gameObject.tag == "Player2")
        {
            thisPlayerNo = 2;
        }

        GameManager.PPlayerTurn
        .Where(x => x != thisPlayerNo)
        .Subscribe(_ => searchCount.Value--)
        .AddTo(this);

        searchCount
        .Where(x => x < 0)
        .Subscribe(_ => {
            this.gameObject.layer = this.gameObject.transform.parent.gameObject.layer;
            LayerChange();
        })
        .AddTo(this);
    }
Ejemplo n.º 8
0
 public void OnEnable()
 {
     TickEvery_ms.Where(x => x != _lastTickEvery_ms).Subscribe(OnTickEveryChange).AddTo(this);
     GameModel.Set(this);
 }