Ejemplo n.º 1
0
 private void AddEvent(HeroAction action, string functionName, float time)
 {
     if (BattleManager.Instance.InformAnimationClip(thisAnimation.GetClip(action.ToString())))
     {
         UnityEngine.AnimationEvent evt = new UnityEngine.AnimationEvent();
         evt.functionName = functionName;
         evt.time         = time;
         thisAnimation.GetClip(action.ToString()).AddEvent(evt);
     }
 }
Ejemplo n.º 2
0
 private void DoAction(HeroAction changeAction)
 {
     if (thisAnimation[action.ToString()].speed == 0)
     {
         if (changeAction == HeroAction.die)
         {
             thisAnimation[action.ToString()].speed = 1;
         }
         else
         {
             return;
         }
     }
     if (action == changeAction && thisAnimation[changeAction.ToString()].wrapMode != WrapMode.Loop)
     {
         thisAnimation[changeAction.ToString()].time = 0;
     }
     else
     {
         action = changeAction;
     }
     thisAnimation.Play(changeAction.ToString());
 }
Ejemplo n.º 3
0
    void FixedUpdate()
    {
        if (Time.timeScale == 0)
        {
            return;
        }
        if (mode == Mode.show)
        {
            if (thisAnimation.isPlaying)
            {
                return;
            }
            DoAction(HeroAction.idle);
        }
        else
        {
            if (injuryColorTime > 0)
            {
                injuryColorTime -= Time.deltaTime;
                if (injuryColorTime <= 0)
                {
                    SetBodyIllumin(Color.black);
                }
            }
            if (BattleManager.Instance.status == BattleManager.Status.start && current_hp > 0)
            {
                bool standstill = false;
                foreach (var item in dots)
                {
                    if (item.type == DotType.dazzle || item.type == DotType.freeze || item.type == DotType.knockback)
                    {
                        standstill = true;
                    }
                }
                //处理一下图标
                if (skillBtn)
                {
                    if (allowCastSkill.activeSelf)
                    {
                        if (target.current_hp <= 0 || gauge < 1000 || standstill)
                        {
                            allowCastSkill.SetActive(false);
                        }
                    }
                    else
                    {
                        if (target.current_hp > 0 && !navMeshAgent.enabled && gauge == 1000 && !standstill)
                        {
                            allowCastSkill.SetActive(true);
                        }
                    }
                }
                //普攻间隔倒计时
                atkInterval -= Time.deltaTime;
                if (!standstill)
                {
                    float dist = Vector3.Distance(transform.position, target.transform.position) - radius - target.radius;
                    if ((target.current_hp <= 0 || dist > atk_range) && action == HeroAction.idle)
                    {
                        bool twine = false;
                        foreach (var item in dots)
                        {
                            if (item.type == DotType.twine)
                            {
                                twine = true;
                            }
                        }
                        if (action == HeroAction.idle && navMeshObstacle.enabled && !twine)
                        {
                            navMeshObstacle.enabled = false;
                            //这里是为了让obstacle挖的洞先消失
                            Invoke("SearchTarget", 0.01f);
                        }
                    }
                    if (navMeshAgent.enabled)
                    {
                        if (dist <= atk_range)
                        {
                            navMeshAgent.enabled    = false;
                            navMeshObstacle.enabled = true;
                            DoAction(HeroAction.idle);
                            transform.LookAt(target.transform);
                        }
                        else if (dist >= lastDistance)
                        {
                            navMeshAgent.destination = target.transform.position;
                        }
                        lastDistance = dist;
                    }
                    else
                    {
                        if (navMeshObstacle.enabled && dist <= atk_range)
                        {
                            if (action == HeroAction.idle && atkInterval <= 0)
                            {
                                atkInterval = 1 / atk_speed;
                                DoAction(HeroAction.attack);
                            }
                            //自动释放技能
                            if (troop.auto)
                            {
                                CastSkill(null, null);
                            }
                        }
                    }
                }
                //处理DOT
                for (int i = 0; i < dots.Count; i++)
                {
                    Dot item    = dots[i];
                    int lastSec = Mathf.FloorToInt(item.duration);
                    item.duration -= Time.deltaTime;
                    if (Mathf.FloorToInt(item.duration) != lastSec)                     //伤害及治疗类DOT
                    {
                        switch (item.type)
                        {
                        case DotType.burning:
                        case DotType.bleeding:
                            Damage(item.num, item.unit, true);
                            break;

                        case DotType.heal:
                            Heal(item.num);
                            break;
                        }
                    }
                    if (item.duration <= 0)
                    {
                        switch (item.type)
                        {
                        case DotType.freeze:
                            thisAnimation[action.ToString()].speed = 1;
                            if (navMeshAgent.enabled)
                            {
                                ResumeMoving();
                            }
                            else
                            {
                                DoAction(HeroAction.idle);
                            }
                            break;

                        case DotType.dazzle:
                        case DotType.knockback:
                        case DotType.twine:
                            ResumeMoving();
                            break;

                        case DotType.atkUp:
                            atk -= item.num;
                            break;

                        case DotType.matkUp:
                            matk -= item.num;
                            break;

                        case DotType.speedDown:
                            atk_speed         /= (1 - item.num);
                            move_speed        /= (1 - item.num);
                            navMeshAgent.speed = move_speed;
                            break;

                        case DotType.speedUp:
                            atk_speed         /= (1 + item.num);
                            move_speed        /= (1 + item.num);
                            navMeshAgent.speed = move_speed;
                            break;
                        }
                        if (item.eff)
                        {
                            Destroy(item.eff);
                        }
                        dots.Remove(item);
                    }
                }
            }
            switch (action)
            {
            case HeroAction.attack:
            case HeroAction.skill_cast:
            case HeroAction.skill_attack:
            case HeroAction.hurt:
            case HeroAction.win:
                if (thisAnimation.isPlaying)
                {
                    return;
                }
                DoAction(HeroAction.idle);
                break;
            }
        }
    }