Exemplo n.º 1
0
    // Use this for initialization
    void Start()
    {
        // Score Delta
        var scoreDelayed = score.Throttle(TimeSpan.FromMilliseconds(500)).ToReactiveProperty();
        var scoreDelta   = score.Select(x => x - scoreDelayed.Value);

        // Change deltaScoreText and format it so that if the number is positive it has a "+" in front of it
        scoreDelta.SubscribeToText(deltaScoreText, x => (x > 0 ? ("+" + x) : x.ToString()));

        // Add animation everytime score delta changes
        scoreDelta.Subscribe(_ => AnimateObj(deltaScoreText.gameObject));


        scoreDelayed.Subscribe(delayedScore => {
            // Change text
            scoreText.text = delayedScore.ToString(); // You can also set by doing scoreDelayed.SubscribeToText(scoreText);

            // Start animation
            AnimateObj(scoreText.gameObject);

            // Clear deltaScore ocne we've updated the score
            deltaScoreText.text = "";
        });


        // Button actions ------------------------
        addButton.onClick.AddListener(() => score.Value++);
        resetButton.onClick.AddListener(() => score.Value = 0);
    }
Exemplo n.º 2
0
    private void SetupGame(Level level)
    {
        GetComponent <BaseLauncher>().Setup(level);

        DestroyedTargetCount.Value = 0;
        TargetsToDestory.Value     = level.Targets.Length;
        HitCount.Select(x => x.ToString()).SubscribeToText(HitCountText);
        HitCount.Value = level.MaxHitCount;
        SubscribeTo(level);
    }
Exemplo n.º 3
0
    // Use this for initialization
    void Start()
    {
        // ----------------------------------
        // Activate mainMenu
        // ----------------------------------
        mainMenu.SetActive(true);
        endMenu.SetActive(false);
        gameMenu.SetActive(false);


        // ----------------------------------
        // Setup scoreDelayed + scoreDelta
        // ----------------------------------

        // Score Delayed
        scoreDelayed = score.Throttle(TimeSpan.FromSeconds(1)).ToReactiveProperty();

        // Score Delta ( no need to have it as a private value since we're not gonna need to use it again in another function )
        var scoreDelta = score.Select(x => x - scoreDelayed.Value);

        // Change deltaScoreText and format it so that if the number is positive it has a "+" in front of it
        scoreDelta.SubscribeToText(deltaScoreText, x => (x > 0 ? ("+" + x) : x.ToString()));

        // Add animation everytime score delta changes
        scoreDelta.Subscribe(_ => AnimateObj(deltaScoreText.gameObject));

        scoreDelayed.Subscribe(delayedScore => {
            // Change text
            scoreText.text = delayedScore.ToString(); // You can also set it using scoreDelayed.SubscribeToText(scoreText);

            // Start animation
            AnimateObj(scoreText.gameObject);

            // Clear deltaScore ocne we've updated the score
            deltaScoreText.text = "";
        });

        // ----------------------------------
        // Setup highscore ( and save values )
        // ----------------------------------
        int lastHighScore = PlayerPrefs.GetInt("highscore");

        highscore = score.StartWith(lastHighScore).DistinctUntilChanged().Scan(int.MinValue, Math.Max).Do(x => PlayerPrefs.SetInt("highscore", x)).ToReactiveProperty();

        // ----------------------------------
        // Setup levels
        // ----------------------------------
        level.SubscribeToText(levelText, x => "Level " + x.ToString());

        // ----------------------------------
        // Button actions
        // ----------------------------------
        startButton.onClick.AddListener(StartGame);
        restartButton.onClick.AddListener(StartGame);
    }
Exemplo n.º 4
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 = "死んだ");
    }
Exemplo n.º 5
0
    void CreateObservables()
    {
        // trigger an observable based on when the player's position changes
        playerLocation = new BehaviorSubject <Vector2>(Vector2.zero);
        latitude.Merge(longitude)
        .Select((float _) => {
            // value could be either lat or lng, so just cheat and grab the current property values
            return(new Vector2(longitude.Value, latitude.Value));
        })
        .Subscribe((Vector2 coords) => {
            playerLocation.OnNext(coords);
        });

        activeStar           = new BehaviorSubject <StarController>(null);
        deliveryDestinations = new BehaviorSubject <Dictionary <int, int> >(GenerateDeliveries());

        fuelAvailable
        .Select((x) => x < 3 && fuelTimeRemaining.Value == 0)
        .Subscribe((x) => {
            StartFuelTimer();
        });
    }
Exemplo n.º 6
0
 public EnemyModel(int hp)
 {
     //初始化
     HP             = new IntReactiveProperty(hp);
     isInteractable = HP.Select(HP => HP <= 0).ToReadOnlyReactiveProperty();
 }
Exemplo n.º 7
0
 private void Awake()
 {
     IsDead = hp.Select(x => x <= 0).ToReadOnlyReactiveProperty();
 }