void Start()
        {
            var rigidBody = GetComponent <Rigidbody>();

            // ジャンプボタンが入力されたら通知されるObservable
            IObservable <Unit> jumpButton =
                this.UpdateAsObservable().Where(_ => Input.GetButtonDown("Jump"));

            // ジャンプボタンが押されたら次のFixedUpdateでジャンプ処理をする
            jumpButton.BatchFrame(0, FrameCountType.FixedUpdate)
            .Subscribe(_ => { rigidBody.AddForce(Vector3.up, ForceMode.VelocityChange); });
        }
Exemplo n.º 2
0
        private void Start()
        {
            // 死んだ敵のIDがObservableで通知される(という想定)
            IObservable <int> killed = _enemyManager.OnKilledEnemyIdObservable;

            // フレーム数0、FrameCountType.EndOfFrameを指定することで、
            // このフレーム中に発生したイベントを1つにまとめることができる
            killed
            .BatchFrame(0, FrameCountType.EndOfFrame)
            .Subscribe(ids =>
            {
                // 1フレーム中に死亡した敵の数を出力する
                Debug.Log(Time.frameCount + ":" + ids.Count);
            });
        }
Exemplo n.º 3
0
 public static IObservable <T> OncePerFrame <T>(this IObservable <T> observable)
 {
     return(observable.BatchFrame().Select(batch => batch.Last()));
 }