using System.Collections.Generic; using Animancer; using DG.Tweening; using UnityEditor.UI; using UnityEngine; namespace ET { [FriendClass(typeof(BattleUnitViewComponent))] public static class BattleActionSegmentHelper { public static Tweener CreateAttackerToTargetTweener(BattleUnitViewComponent source, BattleUnitViewComponent target, float time) { Vector3 targetPos = target.DisplayGameObject.transform.position; if (source.Left) { targetPos += new Vector3(-1, 0, 0); } else { targetPos += new Vector3(1, 0, 0); } return source.DisplayGameObject.transform.DOMove(targetPos, time); } public static Tweener CreateInterveneToTargetTweener(BattleUnitViewComponent source, BattleUnitViewComponent target, float time) { Vector3 targetPos = target.DisplayGameObject.transform.position; if (source.Left) { targetPos += new Vector3(0.5f, 0, 0); } else { targetPos += new Vector3(-0.5f, 0, 0); } return source.DisplayGameObject.transform.DOMove(targetPos, time); } public static Tweener CreateMoveBackTweener(BattleUnitViewComponent source, float time) { var battleSceneView = source.ZoneScene().CurrentScene().GetComponent(); var pos = battleSceneView.GetUnitPosByIndex(source.Index, source.Left); return source.DisplayGameObject.transform.DOMove(pos, time).OnComplete(() => { source.AnimancerComp.TryPlay(BattleAnimName.Idle); }); } public static Animancer.AnimancerState PlayAnim(BattleUnitViewComponent source, BattleUnitViewComponent target, string animName) { var state = source.AnimancerComp.TryPlay(animName); return state; } public static (Animancer.AnimancerState, float) PlayAttackAnim(BattleUnitViewComponent source, BattleUnitViewComponent target, List hurtInfoViews, string animName) { var state = source.AnimancerComp.TryPlay(animName); float time = state.Duration; if (state.Clip.events.Length > 0) { source.SEventReceiver.OnEvent.Set(state, (animationEvent) => { // Log.Error(animationEvent.functionName + "|" + animationEvent.stringParameter); if (animationEvent.stringParameter.Equals("BeHit")) { foreach (var hurtInfotView in hurtInfoViews) { var hurtTarget = hurtInfotView.Target; hurtTarget.BeHit(); } SoundComponent.Instance.PlayClip("hit"); } if (animationEvent.stringParameter.Equals("ShowHurt")) { foreach (var hurtInfotView in hurtInfoViews) { var hurtTarget = hurtInfotView.Target; EmitManager.inst.Emit(hurtTarget.DisplayGameObject.transform, 1, hurtInfotView.DamageValue, hurtInfotView.IsCritical); } } if (animationEvent.stringParameter.Equals("Projectile")) { var prefab = YooAssetComponent.Instance.LoadAssetSync("staff"); GameObject bullet = Util.GameObjectPoolHelper.SpawnGameObject(prefab); YooAssetComponent.Instance.Release(prefab); bullet.transform.position = source.ThrowPoint.position; bullet.transform.DOMove(target.DisplayGameObject.transform.position, 0.5f).OnComplete(() => { Util.GameObjectPoolHelper.ReturnObjectToPool(bullet); foreach (var hurtInfotView in hurtInfoViews) { var hurtTarget = hurtInfotView.Target; hurtTarget.BeHit(); EmitManager.inst.Emit(hurtTarget.DisplayGameObject.transform, 1, hurtInfotView.DamageValue, hurtInfotView.IsCritical); } SoundComponent.Instance.PlayClip("hit"); }); } }); foreach (AnimationEvent animationEvent in state.Clip.events) { if (animationEvent.stringParameter.Equals("Projectile")) { time = animationEvent.time + 0.6f; } } } // state.Events.OnEnd = () => // { // source.AnimancerComp.TryPlay(BattleAnimName.Idle); // }; state.Events.endEvent = new AnimancerEvent(1, () => { source.AnimancerComp.TryPlay(BattleAnimName.Idle); }); return (state, time); } } }