Ejemplo n.º 1
0
    /// <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());
    }
Ejemplo n.º 2
0
 /// <summary>
 /// This routine does the movement animation.
 /// </summary>
 /// <returns>Nothing; IEnumerator is just for coroutines</returns>
 /// <param name="path">The path we want to move along</param>
 /// <param name="bCombatMenu">This combat Menu will be hide during animation</param>
 public IEnumerator MoveRoutine(BMapTile[] path, BCombatMenu bCombatMenu)
 {
     bCombatMenu.Hide();
     for (int i = 1; i < path.Length; i++)
     {
         Vector3 nextWp    = path[i].transform.position;
         Vector3 lookPoint = nextWp;
         lookPoint.y = 0;
         meshContainer.transform.LookAt(lookPoint);
         do
         {
             Vector3 translation = nextWp - transform.position;
             float   distance    = translation.magnitude;
             translation = translation.normalized * Time.deltaTime * movementSpeed;
             if (distance < translation.magnitude)
             {
                 transform.position = nextWp;
                 break;
             }
             else
             {
                 transform.Translate(transform.InverseTransformDirection(translation));
             }
             yield return(0);
         } while(transform.position != nextWp);
     }
     bCombatMenu.OpenForBUnit(parent);
     EventProxyManager.FireEvent(this, new EventDoneEvent());
 }
Ejemplo n.º 3
0
 public void MoveAlongPath(BMapTile[] path)
 {
     bCombatMenu.ActionCompleted();
     bCombatMenu.Hide();
     StartCoroutine(bUnitAnimator.MoveRoutine(path, bCombatMenu));
 }