You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
4.2 KiB

using DG.Tweening;
using UnityEngine;
namespace ET
{
[FriendClass(typeof(BattleActionSegment))]
public static class BattleActionSegmentFactory
{
public static BattleActionSegment Create(Entity root, BattleActionSegmentInfo info)
{
if (info == null)
{
return null;
}
if (info.Target == null)
{
Log.Error("Inavalid Targets");
return null;
}
var bas = root.AddChild<BattleActionSegment>();
bas.Source = info.Source;
bas.Target = info.Target;
bas.Type = info.Type;
var target = bas.Target;
switch (info.Type)
{
case BattleActionSegemntType.MoveToTarget:
{
bas.TotalTime = 0.5f;
Tweener tweener = BattleActionSegmentHelper.CreateAttackerToTargetTweener(info.Source, target, bas.TotalTime);
bas.AddComponent<BattleAction_MoveToTarget>().AddTweener(tweener);
var animState = BattleActionSegmentHelper.PlayAnim(info.Source, target, BattleAnimName.Run);
var bapa = bas.AddComponent<BattleAction_PlayAnimation>();
bapa.AddAnimation(animState);
}
break;
case BattleActionSegemntType.Attack:
{
BattleViewHelper.ShowBattleUnitStateMsg(info.Source, info.AtkInfo);
var config = SkillSonConfigCategory.Instance.Get(info.SonSkillId);
string attackAnim = "Battle_" + config.Action;
var (animState, time) = BattleActionSegmentHelper.PlayAttackAnim(info.Source, info.Target, info.HurtInfoViews, attackAnim);
var bapa = bas.AddComponent<BattleAction_PlayAnimation>();
bapa.AddAnimation(animState);
bas.TotalTime = Mathf.Max(bapa.GetMaxTime(), time);
}
break;
case BattleActionSegemntType.MoveBack:
{
bas.TotalTime = 0f;
var moveTime = 0.5f;
var bamt = bas.AddComponent<BattleAction_MoveToTarget>();
var bapa = bas.AddComponent<BattleAction_PlayAnimation>();
Tweener tweener;
Animancer.AnimancerState animState;
if (info.CastPosition != ConstCastPosition.ORIGINAL_POS)
{
tweener = BattleActionSegmentHelper.CreateMoveBackTweener(info.Source, moveTime);
bamt.AddTweener(tweener);
animState = BattleActionSegmentHelper.PlayAnim(info.Source, target, BattleAnimName.Run);
bapa.AddAnimation(animState);
bas.TotalTime =moveTime;
}
if (info.Intervener != null)
{
tweener = BattleActionSegmentHelper.CreateMoveBackTweener(info.Intervener, moveTime);
bamt.AddTweener(tweener);
animState = BattleActionSegmentHelper.PlayAnim(info.Intervener, target, BattleAnimName.Run);
bapa.AddAnimation(animState);
bas.TotalTime = moveTime;
}
}
break;
case BattleActionSegemntType.Intervene:
{
bas.TotalTime = 0.5f;
var bamt = bas.AddComponent<BattleAction_MoveToTarget>();
if (info.CastPosition != ConstCastPosition.ORIGINAL_POS)
{
var a2TTweener = BattleActionSegmentHelper.CreateAttackerToTargetTweener(info.Source, target, bas.TotalTime);
bamt.AddTweener(a2TTweener);
}
var i2TTweener = BattleActionSegmentHelper.CreateInterveneToTargetTweener(info.Intervener, target, bas.TotalTime);
bamt.AddTweener(i2TTweener);
}
break;
}
return bas;
}
}
}