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.
 
 
 
 
 
 

134 lines
5.4 KiB

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<BattleSceneViewComponent>();
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<HurtInfoView> 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<GameObject>("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);
}
}
}