Пример #1
0
 public void PlayAnimClip(BaseAnimClip clip)
 {
     currentCoroutine = StartCoroutine(PlayAnimation(clip));
 }
Пример #2
0
        private IEnumerator PlayAnimation(BaseAnimClip clip)
        {
            //Debug.Log(clip.type);
            Entity entity;

            switch (clip.type)
            {
            case AnimType.MovePath:
                var movePathClip = clip as MovePathAnimClip;
                if (!EntityManager.Instance.TryGetEntity(movePathClip.entityHash, out entity))
                {
                    break;
                }
                float     duration = movePathClip.duration * entity.MovePath.Length * animRate;
                Vector3[] path     = (from loc in movePathClip.path let pos = loc.ToPosition() select pos).ToArray();
                entity.transform.DOPath(path, duration);
                for (int i = 0; i < movePathClip.path.Length; i++)
                {
                    var pathLoc = movePathClip.path[i];
                    yield return(new WaitForSeconds(clip.duration * animRate));

                    entity.OnSortingOrderChanged?.Invoke(pathLoc.x + pathLoc.y * 8);
                }
                break;

            case AnimType.MoveInstant:
                var moveInstantClip = clip as MoveInstantAnimClip;
                if (!EntityManager.Instance.TryGetEntity(moveInstantClip.entityHash, out entity))
                {
                    break;
                }

                entity.transform.position = moveInstantClip.destination.ToPosition();
                entity.OnSortingOrderChanged?.Invoke(moveInstantClip.destination.x + moveInstantClip.destination.y * 8);
                break;

            case AnimType.Cast:
                var castClip = clip as CastAnimClip;
                if (castClip.skillHash.GetBaseSkill().castEffect.effectName == null)
                {
                    break;
                }
                VisualEffect castEffect = castClip.skillHash.GetBaseSkill().castEffect;
                GameObject   castGO;
                Vector3      endPosition = effectOffset + castClip.end.ToPosition();
                switch (castClip.castType)
                {
                case CastType.Instant:
                    castGO = Instantiate(effectPrefab, endPosition, Quaternion.identity, effectHolder);
                    castGO.GetComponent <Animator>().Play(castEffect.effectName, 0);
                    castGO.GetComponent <AudioSource>().PlayOneShot(castEffect.sound);
                    //yield return StartCoroutine(PlayAnimation(clips.Dequeue()));
                    StartCoroutine(DelayDestory(castGO, castClip.duration * animRate));
                    break;

                case CastType.Trajectory:
                    Vector3 startPosition = effectOffset + castClip.start.ToPosition();
                    castGO = Instantiate(effectPrefab, startPosition, Quaternion.identity, effectHolder);
                    castGO.GetComponent <Animator>().Play(castEffect.effectName, 0);
                    castGO.GetComponent <AudioSource>().PlayOneShot(castEffect.sound);
                    int distance = AStarSearch.Heuristic(castClip.start, castClip.end);
                    castGO.transform.DOMove(endPosition, castClip.duration * distance * animRate)
                    .OnComplete(() => Destroy(castGO));
                    yield return(new WaitForSeconds(castClip.duration * distance * animRate));

                    break;

                default:
                    break;
                }
                break;

            case AnimType.Buff:
                var buffClip = clip as BuffAnimClip;
                if (buffClip.buffHash.GetBaseBuff().buffEffect.effectName == null)
                {
                    break;
                }
                VisualEffect buffEffect = buffClip.buffHash.GetBaseBuff().buffEffect;
                GameObject   buffGO     = Instantiate(effectPrefab, buffClip.loc.ToPosition(), Quaternion.identity, effectHolder);
                buffGO.GetComponent <Animator>().Play(buffEffect.effectName, 0);
                buffGO.GetComponent <AudioSource>().PlayOneShot(buffEffect.sound);
                StartCoroutine(DelayDestory(buffGO, buffClip.duration * animRate));
                break;

            case AnimType.BuffRemovement:
                var buffRemovementClip = clip as BuffRemovementAnimClip;
                buffRemovementClip.entityHash.GetEntity().EntityBuffManager.RemoveBuff(buffRemovementClip.buffHash);
                break;

            case AnimType.HPChange:
                var hpChangeClip = clip as HPChangeAnimClip;
                if (!EntityManager.Instance.TryGetEntity(hpChangeClip.entityHash, out entity))
                {
                    break;
                }
                entity.HPChangeAnimation?.Invoke(hpChangeClip.hp, hpChangeClip.maxHP, hpChangeClip.duration * animRate);
                entity.EntitySprite.DOColor(Color.red, 0.3f).OnComplete(() => entity.EntitySprite.color = Color.white);
                yield return(new WaitForSeconds(hpChangeClip.duration * animRate));

                break;

            case AnimType.ArmourPChange:
                var apChangeClip = clip as ArmourPChangeAnimClip;
                if (!EntityManager.Instance.TryGetEntity(apChangeClip.entityHash, out entity))
                {
                    break;
                }
                if (apChangeClip.isPhysical)
                {
                    entity.ArmourPointsChangeAnimation?.Invoke(true, apChangeClip.remainedNumber);
                }
                else
                {
                    entity.ArmourPointsChangeAnimation?.Invoke(false, apChangeClip.remainedNumber);
                }
                yield return(new WaitForSeconds(apChangeClip.duration * animRate));

                break;

            case AnimType.SkillShift:
                var ssClip = clip as SkillShiftAnimClip;

                break;

            case AnimType.Delay:
                yield return(new WaitForSeconds(clip.duration));

                break;

            case AnimType.OutlineEntity:
                var outlineEntityClip = clip as OutlineEntityAnimClip;
                outlineEntityClip.entityHash.GetEntity().ChangeOutlineColor(outlineEntityClip.color);
                break;

            case AnimType.Gameover:
                yield return(new WaitForSeconds(clip.duration));

                OnGameoverEvent?.Invoke();
                break;

            default:
                break;
            }
            if (!isPlayAll)
            {
                IsPlaying = false;
                OnAnimCompleted?.Invoke();
            }
        }
Пример #3
0
 public void AddAnimClip(BaseAnimClip clip)
 {
     clips.Enqueue(clip);
 }