重构Animation动画系统,增加Addition新增动画支持

This commit is contained in:
monitor1394
2023-07-12 13:18:58 +08:00
parent e515908f9b
commit e103c87d10
4 changed files with 31 additions and 22 deletions

View File

@@ -73,7 +73,7 @@ namespace XCharts.Runtime
context.pause = false;
context.end = false;
context.startTime = 0;
context.itemCurrProgress.Clear();
context.dataCurrProgress.Clear();
}
/// <summary>
@@ -101,8 +101,8 @@ namespace XCharts.Runtime
context.destProgress = 1;
context.totalProgress = 0;
context.sizeProgress = 0;
context.itemCurrProgress.Clear();
context.itemDestProgress.Clear();
context.dataCurrProgress.Clear();
context.dataDestProgress.Clear();
}
if (OnAnimationStart != null)
{
@@ -242,7 +242,7 @@ namespace XCharts.Runtime
internal void SetDataCurrProgress(int index, float state)
{
context.itemCurrProgress[index] = state;
context.dataCurrProgress[index] = state;
}
@@ -253,23 +253,23 @@ namespace XCharts.Runtime
isBarEnd = false;
return initValue;
}
var c1 = !context.itemCurrProgress.ContainsKey(index);
var c2 = !context.itemDestProgress.ContainsKey(index);
var c1 = !context.dataCurrProgress.ContainsKey(index);
var c2 = !context.dataDestProgress.ContainsKey(index);
if (c1 || c2)
{
if (c1)
context.itemCurrProgress.Add(index, initValue);
context.dataCurrProgress.Add(index, initValue);
if (c2)
context.itemDestProgress.Add(index, destValue);
context.dataDestProgress.Add(index, destValue);
isBarEnd = false;
}
else
{
isBarEnd = context.itemCurrProgress[index] == context.itemDestProgress[index];
isBarEnd = context.dataCurrProgress[index] == context.dataDestProgress[index];
}
return context.itemCurrProgress[index];
return context.dataCurrProgress[index];
}
internal void CheckProgress(double total, bool m_UnscaledTime)

View File

@@ -17,7 +17,7 @@ namespace XCharts.Runtime
public float sizeProgress;
public int currPointIndex;
public int destPointIndex;
public Dictionary<int, float> itemCurrProgress = new Dictionary<int, float>();
public Dictionary<int, float> itemDestProgress = new Dictionary<int, float>();
public Dictionary<int, float> dataCurrProgress = new Dictionary<int, float>();
public Dictionary<int, float> dataDestProgress = new Dictionary<int, float>();
}
}

View File

@@ -45,7 +45,8 @@ namespace XCharts.Runtime
/// <summary>
/// the animation of serie. support animation type: fadeIn, fadeOut, change, addition.
/// |动画系统。支持配置四种动画表现FadeIn渐入动画FadeOut渐出动画Change变更动画Addition新增动画
/// |动画组件,用于控制图表的动画播放。支持配置四种动画表现FadeIn渐入动画FadeOut渐出动画Change变更动画Addition新增动画
/// 按作用的对象可以分为两类SerieAnimation系列动画和DataAnimation数据动画
/// </summary>
[System.Serializable]
public class AnimationStyle : ChildComponent
@@ -241,7 +242,7 @@ namespace XCharts.Runtime
var anim = activedAnimation;
if (anim == null) return;
var isAddedAnim = anim is AnimationAddition;
if (IsIndexAnimation())
if (IsSerieAnimation())
{
if (isAddedAnim)
{
@@ -331,13 +332,13 @@ namespace XCharts.Runtime
return true;
}
}
if (IsIndexAnimation())
if (IsSerieAnimation())
{
if (m_FadeOut.context.start) return m_FadeOut.context.currProgress <= m_FadeOut.context.destProgress;
else if (m_Addition.context.start) return m_Addition.context.currProgress >= m_Addition.context.destProgress;
else return m_FadeIn.context.currProgress >= m_FadeIn.context.destProgress;
}
else if (IsItemAnimation())
else if (IsDataAnimation())
{
return false;
}
@@ -352,12 +353,20 @@ namespace XCharts.Runtime
return false;
}
public bool IsItemAnimation()
/// <summary>
/// whther animaiton is data animation. BottomToTop and InsideOut are data animation.
/// |是否为数据动画。BottomToTop和InsideOut类型的为数据动画。
/// </summary>
public bool IsDataAnimation()
{
return context.type == AnimationType.BottomToTop || context.type == AnimationType.InsideOut;
}
public bool IsIndexAnimation()
/// <summary>
/// whther animaiton is serie animation. LeftToRight, AlongPath and Clockwise are serie animation.
/// |是否为系列动画。LeftToRight、AlongPath和Clockwise类型的为系列动画。
/// </summary>
public bool IsSerieAnimation()
{
return context.type == AnimationType.LeftToRight ||
context.type == AnimationType.AlongPath || context.type == AnimationType.Clockwise;
@@ -365,7 +374,7 @@ namespace XCharts.Runtime
public bool CheckDetailBreak(float detail)
{
if (!IsIndexAnimation())
if (!IsSerieAnimation())
return false;
foreach (var animation in animations)
{
@@ -377,7 +386,7 @@ namespace XCharts.Runtime
public bool CheckDetailBreak(Vector3 pos, bool isYAxis)
{
if (!IsIndexAnimation())
if (!IsSerieAnimation())
return false;
if (IsFinish())
@@ -400,7 +409,7 @@ namespace XCharts.Runtime
public void CheckProgress()
{
if (IsItemAnimation() && context.isAllItemAnimationEnd)
if (IsDataAnimation() && context.isAllItemAnimationEnd)
{
foreach (var animation in animations)
{

View File

@@ -7,7 +7,7 @@ namespace XCharts.Runtime
{
public static float CheckDataAnimation(BaseChart chart, Serie serie, int dataIndex, float destProgress, float startPorgress = 0)
{
if (!serie.animation.IsItemAnimation())
if (!serie.animation.IsDataAnimation())
{
serie.animation.context.isAllItemAnimationEnd = false;
return destProgress;