Esempio n. 1
0
    void Update()
    {
        switch (state)
        {
        case State.Inactive:
        {
            if (hero.CanMove && input.GetButtonDown(ButtonCode.Jet))
            {
                state = State.Ready;
                EffectOnReady();
            }
        }
        break;

        case State.Ready:
        {
            if (!hero.CanMove)
            {
                state = State.Inactive;
                break;
            }

            chargeSeconds += hero.TimeManager.DeltaTimeAroundHero;

            if (input.GetButtonUp(ButtonCode.Jet))
            {
                state = State.Jetting;

                JetParams params_    = hero.Parameters.JetParams;
                float     charge_0_1 = Mathf.Clamp01(
                    Mathf.InverseLerp
                    (
                        params_.ChargeSecondsFromMin * params_.TimeScaleBeforeJet,
                        params_.ChargeSecondsToMax * params_.TimeScaleBeforeJet,
                        chargeSeconds
                    )
                    );
                hero.Jet(charge_0_1)
                .Subscribe(_ =>
                    {
                        coolTimeLeft = hero.Parameters.JetParams.CoolTime;
                        state        = State.CoolTime;
                        EffectOnExit();
                        _JetEnded.OnNext(Unit.Default);
                    });

                EffectOnJet();

                chargeSeconds = 0;
            }
        }
        break;

        case State.Jetting:
        {
            //
        }
        break;

        case State.CoolTime:
        {
            coolTimeLeft -= hero.TimeManager.DeltaTimeAroundHero;
            if (coolTimeLeft <= 0)
            {
                state = State.Inactive;
            }
        }
        break;
        }
    }