Example #1
0
    /// <summary>
    /// 初期化
    /// </summary>
    public void Initialize()
    {
        _rigidbody = GetComponent <Rigidbody2D>();
        _cc        = GetComponent <PlayerCharacterContoroller>();

        //初期化するときはレディ状態へ
        ChangeState(PlayerState.Ready);

        //CurrentStateを購読して、変更が加えられたときに実行する関数を登録しておく
        //stateにはいまのstateが入っている
        _PlayerState.Subscribe(state =>
        {
            OnStateChanged(state);
        });

        //死ぬ条件(めっちゃwhereだらけ)
        this.UpdateAsObservable()
        .Where(x => _PlayerState.Value == PlayerState.Normal)
        .Where(x => _cc.IsGrounded.Value == true)
        .Where(x => _cc.IsStopped.Value == true)
        .Subscribe(_ => {
            _PlayerState.Value = PlayerState.Dead;
        });

        //Q:
        //ここがいまいちよくわからない。一応すべてのInitiate関数をよんでいるのはわかるのだが。
        //
        _onInitializeAsyncSubject.OnNext(1);
        _onInitializeAsyncSubject.OnCompleted();
    }
Example #2
0
    /// <summary>
    /// 初期化だよ
    /// </summary>
    protected override void OnInitialize()
    {
        //コントローラ
        cc = GetComponent <PlayerCharacterContoroller>();

        //左矢印キー
        InputEventProvider.LeftArrow
        .Where(x => x == true)
        .Subscribe(x =>
        {
            cc.Move(new Vector3(1f, 0f, 0f) * MoveSpeed);
        });

        //右矢印キー
        InputEventProvider.RightArrow
        .Where(x => x == true)
        .Subscribe(x =>
        {
            cc.Move(new Vector3(-1f, 0f, 0f) * MoveSpeed);
        });

        //バグモードの時の動きを制御する
        this.FixedUpdateAsObservable()
        .Where(_ => Core._PlayerState.Value == PlayerState.GabageBugMode)
        .DistinctUntilChanged()
        .Subscribe(_ =>
        {
            cc.ApplyForce(new Vector2(0f, 50f));
        }).AddTo(this);

        //バグモードの時の動きを制御する
        this.FixedUpdateAsObservable()
        .Where(_ => Core._PlayerState.Value == PlayerState.GabageBugMode)
        .Subscribe(_ =>
        {
            cc.ApplyRotateForce();
        }).AddTo(this);;
    }