Beispiel #1
0
    public IEnumerator AttackAnimation(SO_AttackFX sO_AttackFX, Character_AttackFX atkFX, bool atkFollowPlayerOrientation = false)
    {
        // References from the AttackFX object from the CharacterAttackFX Pool.
        atkFX.inUse = true;
        atkFX.exitAttackAnimationFX = false;
        atkFX.loopAnimation         = sO_AttackFX.loopAnimation;
        if (sO_AttackFX.stopOnStun)
        {
            atkFX.stopOnStun = true;
        }
        SpriteRenderer atkSpriteR = atkFX.spriteR;

        atkFX.gameObject.SetActive(true);
        //print ("ATK FX OBJECT set active");
        atkSpriteR.sprite = null;
        // References from the SO_AttackFX.
        Sprite[] atkSprites           = sO_AttackFX.sprites;
        float[]  atkSpriteChangeTimes = sO_AttackFX.spriteChangeTiming;
        float    totalDuration        = sO_AttackFX.totalDuration;
        // Set other variables.
        float timer              = 0f;
        int   thisSpriteIndex    = 0;
        float fxXOrientation     = atkFX.transform.localScale.x;
        float playerXOrientation = charAtk.playerSpriteTrans.localScale.x;
        bool  flipCheck          = false;

        // This was put it to avoid having the first sprite appear before the attack movement was set.
        yield return(null);

        // Go through all the attack FX sprites based on their change timings.
        while (timer < totalDuration)
        {
            timer += Time.deltaTime;
            if (timer >= atkSpriteChangeTimes[thisSpriteIndex])
            {
                atkSpriteR.sprite = atkSprites[thisSpriteIndex];
                if (thisSpriteIndex < atkSpriteChangeTimes.Length - 1)
                {
                    thisSpriteIndex++;
                }
            }
            if (atkFollowPlayerOrientation && timer >= atkSpriteChangeTimes[0] && !flipCheck)
            {
                flipCheck = true;
                if (charAtk.playerSpriteTrans.localScale.x != playerXOrientation)
                {
                    atkFX.transform.localScale = new Vector3(-fxXOrientation, 1, 1);
                }
            }
            // During this time the player will not be able to voluntarily interrupt his attack, for example they will not be able to use their dash skill.
            if (timer > sO_AttackFX.cantInterrupStart && timer < sO_AttackFX.cantInterrupEnd)
            {
                atkFX.canInterrupt = false;
            }
            else
            {
                atkFX.canInterrupt = true;
            }
            // Alternative to not have any point uninterruptable during the attack, have a point durring the attack where it will cancel the attack fx (projectile or not), for example if the player dashes before the nimble spear attack 01's projectile is fully formed it will make it disappear. Basically a point in the attack where the attack is either cancelled or continues.
            // Cancel Point, before this point the attack FX (visual, movement, collision) will be cancelled by things like getting hit aka stunned.
            if (timer > sO_AttackFX.cancelPoint)
            {
                atkFX.involuntaryCancel = false;
            }
            // If my Character_AttackFX pool object is set to stopAttackNow, exit the while loop immediately.
            if (atkFX.exitAttackAnimationFX)
            {
                break;
            }
            // If my Character_AttackFX pool object is set to loop, restart the animation.
            if (timer >= totalDuration)
            {
                if (atkFX.loopAnimation)
                {
                    timer           = 0f;
                    thisSpriteIndex = 0;
                }
            }
            yield return(null);
        }
        while (atkFX.holdLastSprite)
        {
            yield return(null);
        }
        atkSpriteR.sprite = null;
        atkFX.gameObject.SetActive(false);
        atkFX.stopOnStun        = false;
        atkFX.involuntaryCancel = true;
        atkFX.inUse             = false;
    }
 public void GetAttackFX()
 {
     atkFX         = attackPool.RequestAttackFX();
     charAtk.atkFX = atkFX;
 }
 public void Attack()
 {
     // If the attack is triggered, make sure that the grace period is set back to false since it is used.
     moIn.attackButtonActions.attackButtonTapInGrace = false;
     // Checks and adjusts the current attack chain. (Chaining attacks)
     atkChain.ChainAttacks();
     // Disallow weapon swapping.
     equippedWeapons.canSwapWeapon = false;
     // Stop the previous motion if needed.
     StopPreviousMotion();
     // Set the weapon back to its resting position and rotation. Usually the first attack chain's resting values.
     ResetWeaponLocalValues();
     // Allow character flip and the weapon to "look at" the mouse.
     ForceCharFlipAndWeaponLookAt();
     // If I want to check the weapon motion every attack. (attack chains can have different motions ex; stab, slash)
     //curWeaponMotion = weaponMotionController.CheckMotionList(weaponMotion);
     curWeaponMotion = weaponMotions[atkChain.curChain];
     // Start the attack.
     curWeaponMotion.WeaponMotionSetup(this, weaponTrans, weaponSpriteR);
     // Handles moving the player, slowing him down, etc., during the attack. (Player motion)
     atkPlyrMove.SetupPlayerAttackMotions(WeapAtkChain.sO_CharAtk_Motion);
     // Clear the character_attackFX list.
     atkFXsInUse.Clear();
     // Activate all this attack's FX's.
     foreach (SO_AttackFX sO_AttackFX in ChainAttackFXs)
     {
         // Request an attack FX from the attack FX pool, the attack FX contains a Sprite Renderer and a PolygonalCollider2D.
         atkFX = atkFXPool.RequestAttackFX();
         // Flip the attack FX Sprite if needed. (So far, for alternating Slash motions)
         // if (atkDirectionChanges) { atkFX.spriteR.flipX = atkFXFlip; } else { atkFX.spriteR.flipX = false; }
         // Try flipping the attack fx's local x scale instead.
         if (atkDirectionChanges)
         {
             atkFXFlipScale             = (atkFXFlip) ? -1 : 1;
             atkFX.transform.localScale = new Vector2(atkFXFlipScale, atkFX.transform.localScale.y);
         }
         else
         {
             atkFX.transform.localScale = new Vector2(1, atkFX.transform.localScale.y);
         }
         // The gameObject needs to be turned on before starting the coroutine on it.
         atkFX.gameObject.SetActive(true);
         // Moves the attack effect over the course of the attack.
         atkFX.StartCoroutine(atkMovement.AttackMovement(sO_AttackFX, atkFX.transform));
         // Enables and changes the attack effect over the course of the attack and dictates if the atkFX pool object is inUse then not.
         // Start the coroutine ON the pool object script, not the script holding the coroutine logic.
         atkFX.StartCoroutine(atkVisual.AttackAnimation(sO_AttackFX, atkFX, atkFollowPlayerOrientation));
         // Enables and disables the attack's collider during the "animation" and detects colliders it can hit, once, if it has one assigned.
         // Requires the sOWeapon because durability damage is general, if it was attack chain specific then just having the weaponAttackChain would be sufficient as it would hold the durability damage info.
         //print("Weapon one is active on attack trigger: "+equippedWeapons.weaponOneIsActive);
         if (sO_AttackFX.collider != null)
         {
             atkDetection.StartCoroutine(atkDetection.AttackCollider(equippedWeapons.weaponOneIsActive, weapon, WeapAtkChain, sO_AttackFX, atkFX.col, weaponOriginTrans));
         }
         // Turn the atk direction change back to false. This is done at the end because colliders will also be flipped by checking this variable. Now flipping the attack FX pool object's x scale instead of just the sprite.
         atkDirectionChanges        = false;
         atkFollowPlayerOrientation = false;
         // Player sripte to idle and stop animations
         // charMov.mySpriteAnim.Stop();
         // charMov.spriteRend.sprite = charMov.idleSprite;
         // Add the character_attackFXs used to a list to better keep track of them.
         atkFXsInUse.Add(atkFX);
     }
 }