Files
XCharts/Runtime/Component/Animation/AnimationStyleHelper.cs

77 lines
3.0 KiB
C#
Raw Normal View History

2021-12-12 18:05:26 +08:00
using UnityEngine;
using XUGL;
2022-02-19 22:37:57 +08:00
namespace XCharts.Runtime
2021-12-12 18:05:26 +08:00
{
public static class AnimationStyleHelper
{
2022-02-19 17:35:22 +08:00
public static float CheckDataAnimation(BaseChart chart, Serie serie, int dataIndex, float destProgress, float startPorgress = 0)
2021-12-12 18:05:26 +08:00
{
if (!serie.animation.IsDataAnimation())
2021-12-12 18:05:26 +08:00
{
serie.animation.context.isAllItemAnimationEnd = false;
return destProgress;
}
if (serie.animation.IsFinish())
{
serie.animation.context.isAllItemAnimationEnd = false;
return destProgress;
}
var isDataAnimationEnd = true;
var currHig = serie.animation.CheckItemProgress(dataIndex, destProgress, ref isDataAnimationEnd, startPorgress);
2021-12-12 18:05:26 +08:00
if (!isDataAnimationEnd)
{
serie.animation.context.isAllItemAnimationEnd = false;
}
return currHig;
}
public static void UpdateSerieAnimation(Serie serie)
{
var serieType = serie.GetType();
var animationType = AnimationType.LeftToRight;
var enableSerieDataAnimation = true;
2021-12-12 18:05:26 +08:00
if (serieType.IsDefined(typeof(DefaultAnimationAttribute), false))
{
var attribute = serieType.GetAttribute<DefaultAnimationAttribute>();
animationType = attribute.type;
enableSerieDataAnimation = attribute.enableSerieDataAddedAnimation;
2021-12-12 18:05:26 +08:00
}
2024-05-15 13:19:34 +08:00
UpdateAnimationType(serie.animation, animationType, enableSerieDataAnimation);
2021-12-12 18:05:26 +08:00
}
public static void UpdateAnimationType(AnimationStyle animation, AnimationType defaultType, bool enableSerieDataAnimation)
2021-12-12 18:05:26 +08:00
{
2022-05-22 22:17:38 +08:00
animation.context.type = animation.type == AnimationType.Default ?
defaultType :
animation.type;
animation.context.enableSerieDataAddedAnimation = enableSerieDataAnimation;
2021-12-12 18:05:26 +08:00
}
2024-05-15 13:19:34 +08:00
public static bool GetAnimationPosition(AnimationStyle animation, bool isY, Vector3 lp, Vector3 cp, float progress, ref Vector3 ip, ref float rate)
2021-12-12 18:05:26 +08:00
{
if (animation.context.type == AnimationType.AlongPath)
{
var dist = Vector3.Distance(lp, cp);
2024-05-15 13:19:34 +08:00
rate = (dist - animation.context.currentPathDistance + animation.GetCurrDetail()) / dist;
2021-12-12 18:05:26 +08:00
ip = Vector3.Lerp(lp, cp, rate);
return true;
}
else
{
var startPos = isY ? new Vector3(-10000, progress) : new Vector3(progress, -10000);
var endPos = isY ? new Vector3(10000, progress) : new Vector3(progress, 10000);
2024-05-15 13:19:34 +08:00
if (UGLHelper.GetIntersection(lp, cp, startPos, endPos, ref ip))
{
rate = Vector3.Distance(lp, ip) / Vector3.Distance(lp, cp);
return true;
}
else
{
return false;
}
2021-12-12 18:05:26 +08:00
}
}
}
}