using Cal; using Cal.DataTable; using DG.Tweening; using ET.EventType; using ET; using System; using System.Collections.Generic; using UnityEngine; namespace ET { public class PlayEffectEvent : AEvent { public override async ETTask Run(PlayEffect args) { Unit unit = args.unit; Unit targetUnit = args.targetUnit; int effectId = args.effectId; EffectAttachType posType = args.posType; EffectTargetType targetType = args.targetType; int time = args.time; EffectConfig effectConfig = EffectConfigCategory.Instance.Get(effectId); if (effectConfig == null) { Log.Error($"effectConfig == null where id= {effectId}"); return; } Transform go = await ResourceViewHelper.LoadPrefabAsync(effectId); try { switch ((EffectType)effectConfig.EffectType) { case EffectType.None: break; case EffectType.BulletAtk: PlayBulletEffect(go, unit, targetUnit, time); break; case EffectType.PositionAtk: case EffectType.Acception: PlayCommonEffect(targetType, go, unit, targetUnit, posType); break; case EffectType.Continue: PlayContinueEffect(targetType, go, unit, targetUnit, posType, time); break; default: break; } } catch (Exception e) { Log.Error(e); ResourceViewHelper.DestoryPrefabAsync(go.gameObject); } } private void PlayContinueEffect(EffectTargetType targetType, Transform go, Unit unit, Unit targetUnit, EffectAttachType posType, int time) { switch (targetType) { case EffectTargetType.Target: go.GetComponent().flipX = unit.UnitType != UnitType.Player; DoTargetContinueEffect(targetUnit, posType, go,time).Coroutine(); break; case EffectTargetType.Caster: targetUnit = unit; DoTargetContinueEffect(targetUnit, posType, go,time).Coroutine(); break; case EffectTargetType.TeamPosition: break; case EffectTargetType.EnermyPosition: break; default: break; } } private void PlayBulletEffect(Transform go, Unit unit, Unit targetUnit,int time) { go.GetComponent().flipX = unit.UnitType != UnitType.Player && unit.UnitType != UnitType.TeamMember; MonoAnimancer monoAnimancer = go.GetComponent(); Vector3 startPos = unit.GetComponent().AtkPosition; Vector3 endPos = targetUnit.GetComponent().AtkPosition; go.position =startPos; monoAnimancer.PlayOther(); go.DOMove(endPos, time/1000f).OnComplete(()=> { ResourceViewHelper.DestoryPrefabAsync(go.gameObject); }); } private void PlayCommonEffect(EffectTargetType targetType, Transform go, Unit unit, Unit targetUnit, EffectAttachType posType) { switch (targetType) { case EffectTargetType.Target: go.GetComponent().flipX = unit.UnitType != UnitType.Player; DoTargetEffect(targetUnit, posType, go); break; case EffectTargetType.Caster: targetUnit = unit; DoTargetEffect(targetUnit, posType, go); break; case EffectTargetType.TeamPosition: break; case EffectTargetType.EnermyPosition: break; default: break; } } private void DoTargetEffect(Unit targetUnit, EffectAttachType posType, Transform go) { Vector3 targetPos; switch (posType) { case EffectAttachType.Top: targetPos = targetUnit.GetComponent().HeadPoint.position; break; default: case EffectAttachType.Center: targetPos = targetUnit.GetComponent().AtkPosition; break; case EffectAttachType.Foot: targetPos = targetUnit.GetComponent().FootPoint.position; break; } MonoAnimancer monoAnimancer = go.GetComponent(); go.position =targetPos; monoAnimancer.PlayOther(() => ResourceViewHelper.DestoryPrefabAsync(go.gameObject)); } private async ETVoid DoTargetContinueEffect(Unit targetUnit, EffectAttachType posType, Transform go,int time) { Vector3 targetPos; switch (posType) { case EffectAttachType.Top: targetPos = targetUnit.GetComponent().HeadPoint.position; break; default: case EffectAttachType.Center: targetPos = targetUnit.GetComponent().AtkPosition; break; case EffectAttachType.Foot: targetPos = targetUnit.GetComponent().FootPoint.position; break; } MonoAnimancer monoAnimancer = go.GetComponent(); go.position = targetPos; monoAnimancer.PlayOther(); await TimerComponent.Instance.WaitAsync(time); ResourceViewHelper.DestoryPrefabAsync(go.gameObject); } } }