示例#1
0
    public void Initialize
        (int lane, GameObject actor,
        RuntimeAnimatorController idle,
        RuntimeAnimatorController play,
        float height,
        PlayerSquenceReactiveProperty squence)
    {
        _lane = lane;
        actor.transform.localScale    = Vector3.one;
        actor.transform.localPosition = Vector3.zero;
        CameraFollower.target         = actor.transform;
        PlayerAnimator = actor.GetComponent <Animator>();
        _startPosition = transform.GetChild(0).localPosition;
        _startRot      = transform.GetChild(0).localRotation;

        actor.transform.parent.localScale =
            new Vector3(actor.transform.parent.localScale.x, height, actor.transform.parent.localScale.z);
        PlayerAnimator.runtimeAnimatorController = idle;
        _playController = play;
        _actor          = actor;
        SubscribeSequence(squence);

        QBPlay.Instance
        .PlayerPositionNotifier
        .Do(x =>
        {
            switch (_appStateBroker.CurrentRound.Value)
            {
            case Rounds.R2:
                SetToMoveToIdle();
                break;

            case Rounds.R3:
                SetToMoveToIdle();
                break;
            }
        })
        .Subscribe(_ => GoBackToStartPos())
        .AddTo(_actor);

        _footBall = AddFootBall(actor);
        actor.SetActive(true);
        // _footBall = FindBall(actor);
        _footBall.SetActive(false);

        //Current App Round Stream
        _roundStream = _appStateBroker.CurrentRound;
        _roundStream
        .DistinctUntilChanged()
        .Subscribe(round =>
        {
            switch (round)
            {
            case Rounds.Idle_Hike:
                PlayerAnimator.runtimeAnimatorController = _playController;
                break;

            case Rounds.R1_Hike:
            case Rounds.R2_Hike:
            case Rounds.R3_Hike:
                SetToRun();
                break;

            case Rounds.Finish:
                _appStateBroker.SnapButonObservable
                .Take(1)
                .DoOnCompleted(() =>
                {
                    squence.Dispose();
                    GoBackToStartPos();
                    Destroy(_actor);
                })
                .Subscribe()
                .AddTo(_actor);
                break;
            }
        })
        .AddTo(_actor);
    }
示例#2
0
    private void SubscribeSequence(PlayerSquenceReactiveProperty squence)
    {
        var tlane = _lane == 0
            ? TargetLane.Lane1
            : _lane == 1
                ? TargetLane.Lane2
                : _lane == 2
                    ? TargetLane.Lane3
                    : TargetLane.Lane4;

        squence.Debug(Verbose && (GameManager.TargetLane_External & tlane) == tlane, "Player-{_lane}")
        .Subscribe(state =>
        {
            switch (state)
            {
            case AnimSequence.OnReadyEnter:
                break;

            case AnimSequence.OnReadyExit:
                break;

            case AnimSequence.CatchEnter:
                Observable
                .Timer(TimeSpan.FromMilliseconds(100), TimeSpan.FromMilliseconds(100))
                .TakeWhile(condition =>
                {
                    var b = false;
                    switch (_roundStream.Value)
                    {
                    case Rounds.R1_Hike:
                        b = thisPlayer.R1Throw;
                        break;

                    case Rounds.R2_Hike:
                        b = thisPlayer.R2Throw;
                        break;

                    case Rounds.R3_Hike:
                        b = thisPlayer.R3Throw;
                        break;
                    }
                    return(b != true);
                })
                .DoOnCompleted(() =>
                {
                    switch (_roundStream.Value)
                    {
                    case Rounds.R1_Hike:
                        if (thisPlayer.Results[0].Hit)
                        {
                            SetToHit();
                        }
                        else
                        {
                            SetToMiss();
                        }
                        break;

                    case Rounds.R2_Hike:
                        if (thisPlayer.Results[1].Hit)
                        {
                            SetToHit();
                        }
                        else
                        {
                            SetToMiss();
                        }
                        break;

                    case Rounds.R3_Hike:
                        if (thisPlayer.Results[2].Hit)
                        {
                            SetToHit();
                        }
                        else
                        {
                            SetToMiss();
                        }
                        break;
                    }
                })
                .Subscribe()
                .AddTo(_actor);
                break;

            case AnimSequence.CatchExit:
                break;

            case AnimSequence.HitEnter:
                _footBall.SetActive(true);
                Observable
                .Timer(TimeSpan.FromSeconds(1f))
                .DoOnCompleted(() =>
                {
                    switch (_roundStream.Value)
                    {
                    case Rounds.R1_Hike:
                        Ref.MakeCallBasedOnResult(thisPlayer.Results[0].Hit, _lane);
                        _appStateBroker.ComOutGoingStream.OnNext(CommunicationModule.BuildRound1Msg(thisPlayer.Lane, thisPlayer.Result1, thisPlayer.Results[0].Hit));
                        break;

                    case Rounds.R2_Hike:
                        Ref.MakeCallBasedOnResult(thisPlayer.Results[1].Hit, _lane);
                        _appStateBroker.ComOutGoingStream.OnNext(
                            CommunicationModule.BuildRound2Msg(thisPlayer.Lane, thisPlayer.Result1, thisPlayer.Results[0].Hit, thisPlayer.Result2, thisPlayer.Results[1].Hit));
                        break;

                    case Rounds.R3_Hike:
                        Ref.MakeCallBasedOnResult(thisPlayer.Results[2].Hit, _lane);
                        _appStateBroker.ComOutGoingStream
                        .OnNext(CommunicationModule
                                .BuildRound3Msg(thisPlayer.Lane, thisPlayer.Result1, thisPlayer.Results[0].Hit, thisPlayer.Result2, thisPlayer.Results[1].Hit, thisPlayer.Result3, thisPlayer.Results[2].Hit, thisPlayer.PlayerName, thisPlayer.PlayerPercentage));
                        break;
                    }
                    Ref.RefAniStream
                    .Take(1)
                    .DoOnCompleted(SetToCallRef)
                    .Subscribe()
                    .AddTo(_actor);
                })
                .Subscribe()
                .AddTo(_actor);
                break;

            case AnimSequence.HitExit:
                break;

            case AnimSequence.MissEnter:
                Observable
                .Timer(TimeSpan.FromSeconds(0.1f))
                .DoOnCompleted(() =>
                {
                    switch (_roundStream.Value)
                    {
                    case Rounds.R1_Hike:
                        Ref.MakeCallBasedOnResult(thisPlayer.Results[0].Hit, _lane);
                        _appStateBroker.ComOutGoingStream.OnNext(CommunicationModule.BuildRound1Msg(thisPlayer.Lane, thisPlayer.Result1, thisPlayer.Results[0].Hit));
                        break;

                    case Rounds.R2_Hike:
                        Ref.MakeCallBasedOnResult(thisPlayer.Results[1].Hit, _lane);
                        _appStateBroker.ComOutGoingStream.OnNext(
                            CommunicationModule.BuildRound2Msg(thisPlayer.Lane, thisPlayer.Result1, thisPlayer.Results[0].Hit, thisPlayer.Result2, thisPlayer.Results[1].Hit));
                        break;

                    case Rounds.R3_Hike:
                        Ref.MakeCallBasedOnResult(thisPlayer.Results[2].Hit, _lane);
                        _appStateBroker.ComOutGoingStream
                        .OnNext(CommunicationModule
                                .BuildRound3Msg(thisPlayer.Lane, thisPlayer.Result1, thisPlayer.Results[0].Hit, thisPlayer.Result2, thisPlayer.Results[1].Hit, thisPlayer.Result3, thisPlayer.Results[2].Hit, thisPlayer.PlayerName, thisPlayer.PlayerPercentage));
                        break;
                    }
                    Ref.RefAniStream
                    .Take(1)
                    .DoOnCompleted(SetToCallRef)
                    .Subscribe(_ => _footBall.SetActive(false))
                    .AddTo(_actor);
                })
                .Subscribe()
                .AddTo(_actor);
                break;

            case AnimSequence.MissExit:
                break;

            case AnimSequence.FinishEnter:
                _roundStream
                .Take(1)
                .Subscribe(round =>
                {
                    switch (round)
                    {
                    case Rounds.R1_Hike:
                        thisPlayer.R1Done = true;
                        break;

                    case Rounds.R2_Hike:
                        thisPlayer.R2Done = true;
                        break;

                    case Rounds.R3_Hike:
                        thisPlayer.R3Done = true;
                        break;
                    }
                })
                .AddTo(_actor);
                break;

            case AnimSequence.FinishExit:
                _footBall.SetActive(false);
                break;
            }
        })
        .AddTo(_actor);
    }