예제 #1
0
 private void Start()
 {
     soundArea.OnTriggerEnter2DAsObservable()
     .Where(_ => _.GetComponent <Player>() != null)
     .Subscribe(_ => pointGroup.OnSoundAreaEnter(this))
     .AddTo(this.gameObject);
     soundArea.OnTriggerExit2DAsObservable()
     .Where(_ => _.GetComponent <Player>() != null)
     .Subscribe(_ => pointGroup.OnSoundAreaExit(this))
     .AddTo(this.gameObject);
     if (isHidden)
     {
         spring.gameObject.SetActive(false);
         soil.gameObject.SetActive(false);
     }
 }
예제 #2
0
        public void Initalize(GameManager gm)
        {
            this.gameManager = gm;

            col.OnTriggerEnter2DAsObservable()
            .Where(c => c.GetComponent <Candle>() != null)
            .Select(c => c.GetComponent <Candle>())
            .Do(c => c.SwitchIcon(true))
            .Subscribe(c => targetCandle = c);
            col.OnTriggerExit2DAsObservable()
            .Where(col => col.GetComponent <Candle>() != null)
            .Do(c => c.GetComponent <Candle>().SwitchIcon(false))
            .Subscribe(_ => targetCandle = null);

            gameManager.InputProvider.OnHorizontal
            .Select(h => (litCandle?.IsStop.Value ?? true && (!litCandle?.IsAlive.Value ?? false)) ? 0 : h)
            .Select(h => gameManager.OnGameState.Value == GameState.GameOver ? 0 : h)
            .Subscribe(h => rb.velocity = new Vector2(h * speedV, rb.velocity.y));
            gameManager.InputProvider.OnVertical
            .Select(v => (litCandle?.IsStop.Value ?? true && (!litCandle?.IsAlive.Value ?? false)) ? 0 : v)
            .Select(h => gameManager.OnGameState.Value == GameState.GameOver ? 0 : h)
            .Subscribe(v => rb.velocity = new Vector2(rb.velocity.x, v * speedV));

            var fire = gameManager.InputProvider.OnFire
                       .Where(_ => targetCandle != null)
                       .Share();

            fire.Subscribe(_ => BonfireLit()).AddTo(gameObject);
            fire
            .DelayFrame(10).First()
            .Subscribe(start =>
            {
                gameManager.ChangeState(GameState.InGame);
            });

            gameManager.OnGameState
            .Where(x => x == GameState.GameOver)
            .First()
            .Subscribe(_ =>
            {
                litCandle.transform.SetParent(gameManager.candleProvider.transform);
                transform.DOScale(Vector3.zero, 3);
                rb.velocity = Vector2.zero;
            });

            _initialized.OnNext(Unit.Default);
        }