コード例 #1
0
        void Start()
        {
            setup();

            //フリーズ条件:talk
            game.talkEvent.Subscribe(f =>
            {
                freezed.Value = f;
            }).AddTo(gameObject);
            //フリーズ条件:GameClear
            game.clearEvent.Subscribe(f =>
            {
                if (f)
                {
                    freezed.Value  = true;
                    animator.speed = 0;
                }
            }).AddTo(gameObject);

            //アニメーション遷移
            FreezableUpdate.Subscribe(_ =>
            {
                animator.SetFloat("YSpeed", rb2d.velocity.y);
            });

            //横移動
            this.UpdateAsObservable().Select(_ => Input.GetButton("DASH") && is_grounded.Value).Subscribe(b => speed_walk = b ? 5.0f : 3.0f);
            FreezableUpdate.Subscribe(_ =>
            {
                input_lr.Value = enable_input ? Input.GetAxis("Horizontal") : 0;
            });
            input_lr.Subscribe(i =>
            {
                animator.SetBool("isRunning", input_lr.Value != 0);
                front_way = input_lr.Value != 0 ? input_lr.Value.CompareTo(0) : front_way;
            });
            FreezableFixedUpdate.Subscribe(_ =>
            {
                if (is_grounded.Value)
                {
                    walk_to_lr(input_lr.Value);
                }
                else
                {
                    fly_to_lr(input_lr.Value);
                }
            });

            //接地判定
            this.OnTriggerStay2DAsObservable().Where(c => c.tag == "Ground").ThrottleFrame(2).Subscribe(_ => is_grounded.Value = false);
            this.OnTriggerStay2DAsObservable().Where(c => c.tag == "Ground").Subscribe(_ => is_grounded.Value = true);
            is_grounded.Subscribe(i => animator.SetBool("isGrounded", i));

            //ジャンプ
            FreezableUpdate.Where(_ => Input.GetButtonDown("Fire1")).Where(_ => is_grounded.Value).Subscribe(p =>
            {
                animator.SetTrigger("Leap");
                Observable.NextFrame(FrameCountType.FixedUpdate).Subscribe(_ => rb2d.AddForce(new Vector2(0, speed_jump) * rb2d.mass, ForceMode2D.Impulse));
            });
        }
コード例 #2
0
        void Start()
        {
            setup();
            front_way  = -1;
            speed_walk = 1.0f;

            //フリーズ条件:timestop,talk
            Observable.CombineLatest(game.TimeStopEvent, game.talkEvent).Select(list => list.Any(b => b)).Subscribe(f => {
                freezed.Value = f;
            }).AddTo(gameObject);

            //時間停止
            game.TimeStopEvent.Subscribe(i => {
                if (i)
                {
                    tag = "Ground";
                    gameObject.layer = LayerMask.NameToLayer("Ground");
                    animator.enabled = false;
                }
                else
                {
                    tag = "Enemy";
                    gameObject.layer = LayerMask.NameToLayer("Enemy");
                    animator.enabled = true;
                }
            }).AddTo(gameObject);

            //被弾
            this.OnTriggerEnter2DAsObservable().Where(c => c.tag == "Bullet").Subscribe(collider => {
                FreezableUpdate.First().Subscribe(_ =>
                {
                    Instantiate(bomb, rb2d.transform.position, rb2d.transform.rotation);
                    Destroy(gameObject);
                });
            });

            //移動
            FreezableFixedUpdate.Subscribe(_ => {
                walk_to_lr(front_way);
            });
            this.OnTriggerEnter2DAsObservable().Where(c => c.tag == "Ground").Subscribe(collider => {
                front_way = -front_way;
            });
        }