private void Warmup()
        {
            gameplayState.ChangeState(EGameplayState.Warmup);

            playerCtrl.MaintainPlayerSpawn();

            warmupCoroutineHandle = MEC.Timing.CallDelayed(2f, StartPlaying);
        }
	void Start() {
		var player = FindObjectOfType<Player>();
		fillPID = Shader.PropertyToID("_FillAmount");

		// Re-instantiate the material so we won't have any unwanted 'changes' shown on git
		var mat = new Material(frontImg.material);
		frontImg.material = mat;

		player.OnDamaged += (_) => {
			var prevHPPercentage = currentHPPercentage;
			currentHPPercentage = player.HP / (float) player.settings.MaxHP;

			MEC.Timing.KillCoroutines(drainHandle);
			MEC.Timing.KillCoroutines(ppAnimHandle);

			drainHandle = MEC.Timing.RunCoroutine(DrainHPBar(mat, prevHPPercentage, currentHPPercentage));
			ppAnimHandle = MEC.Timing.RunCoroutine(AnimatePostProcessing(currentHPPercentage));
		};

		player.OnDeath += () => {
			MEC.Timing.KillCoroutines(drainHandle);
			MEC.Timing.KillCoroutines(ppAnimHandle);
		};
	}
Exemplo n.º 3
0
 public void AddCoroutine(MEC.CoroutineHandle coroutineHandle) => coroutines.Add(coroutineHandle);
Exemplo n.º 4
0
    void HandleAttack()
    {
        if ((state == State.FreeToDoActions || state == State.Attacking) && currentCombo < 2 && Input.GetMouseButtonDown(0))
        {
            var  percentage = timeSincePrevAttack / (float)anim.GetCurrentAnimatorStateInfo(0).length;
            bool canAttack  = percentage >= settings.minComboSkipTime;
            if (canAttack)
            {
                PlayNextCombo();
            }
        }

        timeSincePrevAttack += Time.deltaTime;
        if (timeSincePrevAttack >= settings.maxSecondsToKeepCombo && currentCombo != -1)
        {
            ResetCombo();
        }



        void PlayNextCombo()
        {
            currentCombo++;
            timeSincePrevAttack = 0;

            state = State.Attacking;

            MEC.Timing.KillCoroutines(attackCommand);
            attackCommand = MEC.Timing.RunCoroutine(DoAttackStuff());

            var t = currentCombo == -1 ? 0 : settings.comboSkipTimeCurve.Evaluate(timeSincePrevAttack / settings.maxSecondsToKeepCombo);

            anim.CrossFadeInFixedTime(CharacterAnimationHelper.GetHashForCombo(currentCombo), 0.2f, 0, t);
        }

        void ResetCombo()
        {
            currentCombo = -1;
            if (state == State.Attacking)
            {
                state = State.FreeToDoActions;
            }
        }

        IEnumerator <float> DoAttackStuff()
        {
            const float totalTimeToRotate   = 0.25f;
            const float totalTimeToAnimMove = 0.25f;
            float       t = 0;

            var extents = hitCollider.bounds.extents;

            enemiesHit.Clear();

            while (t < totalTimeToRotate)
            {
                var targetRotY = Mathf.MoveTowardsAngle(transform.eulerAngles.y, targetLookRot.eulerAngles.y, settings.AttackRotationSpeed * Time.deltaTime);
                transform.eulerAngles = transform.eulerAngles.WithY(targetRotY);

                t += Time.deltaTime;
                yield return(0f);
            }

            var curve = CharacterAnimationHelper.GetSettingForCombo(currentCombo, settings);

            t = 0;

            while (t < totalTimeToAnimMove)
            {
                t += Time.deltaTime;
                cc.Move(curve.Evaluate(t / totalTimeToAnimMove) * transform.forward * settings.moveForcePerAttack * Time.deltaTime);

                ScanForHitsAndAttack();

                yield return(0f);
            }
        }

        void ScanForHitsAndAttack()
        {
            int hitAmount = Physics.OverlapBoxNonAlloc(hitCollider.bounds.center, hitCollider.bounds.extents, results, Quaternion.identity, LayerHelper.enemyLayer, QueryTriggerInteraction.Collide);

            for (int i = 0; i < hitAmount; i++)
            {
                var col = results[i];
                if (!col || enemiesHit.Contains(col))
                {
                    return;
                }
                var enemy = col.GetComponent <Enemy>();
                enemy.OnDamaged?.Invoke(settings.Damage);
                enemiesHit.Add(col);
            }
        }
    }