/// <summary> /// Routine to perfome a attack animation /// </summary> /// <returns>IEnumerator is needed for co-routines.<</returns> /// <param name="target">The BUnit whom is the attack target.</param> /// <param name="attack">The attack which will be performed.</param> /// <param name="efficeny">0 = not effectiv, 1 = normal efficeny, 2 = very effectiv</param> /// <param name="damage">The amount of damage dealt by this attack.</param> public IEnumerator AttackRoutine(UnitAttackedEvent e, BMapTile target, BUnit[] victims, BCombatMenu bCombatMenu) { meshContainer.transform.LookAt(target.transform.position); bCombatMenu.Hide(); // sound effect attackSound.Play(); // animation animator.SetTrigger("AttackTrigger"); // wait some time before starting the attack effect yield return(new WaitForSeconds(e.attack.effectDelay)); // caluclate the direction of the attack and project it on one of the 4 vectors: (0,1),(1,0),(0,-1),(-1,0) Vector direction = new Vector(Mathf.FloorToInt(target.transform.position.x - this.transform.position.x), Mathf.FloorToInt(target.transform.position.z - this.transform.position.z)); direction.NormalizeTo4Direction(); BParticleManager.PlayEffect(e.attack.attackName, target.transform.position, new Vector3(direction.x, 0, direction.y)); // wait some time before trigger the hit animtion/effect yield return(new WaitForSeconds(e.attack.hitDelay)); for (int i = 0; i < victims.Length; i++) { victims[i].PlayHitAnimation(e.efficiency, e.damage[i]); victims[i].unitUI.ShowDamage(e.damage[i]); } // wait the rest of the time for the animation before contuine with next event yield return(new WaitForSeconds(e.attack.fullAnimationTime - e.attack.effectDelay - e.attack.hitDelay)); EventProxyManager.FireEvent(this, new EventDoneEvent()); }
void HandleUnitAttacked(object sender, EventArgs args) { UnitAttackedEvent e = args as UnitAttackedEvent; BUnit[] bUnits = new BUnit[e.victims.Count]; for (int i = 0; i < e.victims.Count; i++) { bUnits[i] = GetBUnit(e.victims[i]); } BMapTile bMapTile = GetBMapTile(e.target); GetBUnit(e.source).PlayAttack(e, bMapTile, bUnits); CleanMap(); }
public void PlayAttack(UnitAttackedEvent e, BMapTile target, BUnit[] victims) { StartCoroutine(bUnitAnimator.AttackRoutine(e, target, victims, bCombatMenu)); }