mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-19 15:00:08 +00:00
重构Animation动画系统,增加Addition新增动画支持
This commit is contained in:
@@ -4,6 +4,10 @@ using UnityEngine;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// the animation info.
|
||||
/// |动画配置参数。
|
||||
/// </summary>
|
||||
[Since("v3.8.0")]
|
||||
[System.Serializable]
|
||||
public class AnimationInfo
|
||||
@@ -14,17 +18,53 @@ namespace XCharts.Runtime
|
||||
[SerializeField][Since("v3.8.0")] private float m_Duration = 1000;
|
||||
public AnimationInfoContext context = new AnimationInfoContext();
|
||||
|
||||
/// <summary>
|
||||
/// whether enable animation.
|
||||
/// |是否开启动画效果。
|
||||
/// </summary>
|
||||
public bool enable { get { return m_Enable; } set { m_Enable = value; } }
|
||||
/// <summary>
|
||||
/// whether enable reverse animation.
|
||||
/// |是否开启反向动画效果。
|
||||
/// </summary>
|
||||
public bool reverse { get { return m_Reverse; } set { m_Reverse = value; } }
|
||||
/// <summary>
|
||||
/// the delay time before animation start.
|
||||
/// |动画开始前的延迟时间。
|
||||
/// </summary>
|
||||
public float delay { get { return m_Delay; } set { m_Delay = value; } }
|
||||
/// <summary>
|
||||
/// the duration of animation.
|
||||
/// |动画的时长。
|
||||
/// </summary>
|
||||
public float duration { get { return m_Duration; } set { m_Duration = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// the callback function of animation start.
|
||||
/// |动画开始的回调。
|
||||
/// </summary>
|
||||
public Action OnAnimationStart { get; set; }
|
||||
/// <summary>
|
||||
/// the callback function of animation end.
|
||||
/// |动画结束的回调。
|
||||
/// </summary>
|
||||
public Action OnAnimationEnd { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// the delegate function of animation delay.
|
||||
/// |动画延迟的委托函数。
|
||||
/// </summary>
|
||||
public AnimationDelayFunction delayFunction { get; set; }
|
||||
/// <summary>
|
||||
/// the delegate function of animation duration.
|
||||
/// |动画时长的委托函数。
|
||||
/// </summary>
|
||||
public AnimationDurationFunction durationFunction { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Reset animation.
|
||||
/// |重置动画。
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
if (!enable) return;
|
||||
@@ -36,6 +76,11 @@ namespace XCharts.Runtime
|
||||
context.itemCurrProgress.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start animation.
|
||||
/// |开始动画。
|
||||
/// </summary>
|
||||
/// <param name="reset">是否重置上一次的参数</param>
|
||||
public void Start(bool reset = true)
|
||||
{
|
||||
if (!enable) return;
|
||||
@@ -65,6 +110,10 @@ namespace XCharts.Runtime
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pause animation.
|
||||
/// |暂停动画。
|
||||
/// </summary>
|
||||
public void Pause()
|
||||
{
|
||||
if (!enable) return;
|
||||
@@ -72,6 +121,10 @@ namespace XCharts.Runtime
|
||||
context.pause = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resume animation.
|
||||
/// |恢复动画。
|
||||
/// </summary>
|
||||
public void Resume()
|
||||
{
|
||||
if (!enable) return;
|
||||
@@ -79,6 +132,10 @@ namespace XCharts.Runtime
|
||||
context.pause = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// End animation.
|
||||
/// |结束动画。
|
||||
/// </summary>
|
||||
public void End()
|
||||
{
|
||||
if (!enable) return;
|
||||
@@ -93,6 +150,14 @@ namespace XCharts.Runtime
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize animation.
|
||||
/// |初始化动画。
|
||||
/// </summary>
|
||||
/// <param name="curr">当前进度</param>
|
||||
/// <param name="dest">目标进度</param>
|
||||
/// <param name="totalPointIndex">目标索引</param>
|
||||
/// <returns></returns>
|
||||
public bool Init(float curr, float dest, int totalPointIndex)
|
||||
{
|
||||
if (!enable || !context.start) return false;
|
||||
@@ -113,6 +178,10 @@ namespace XCharts.Runtime
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether animation is finish.
|
||||
/// |动画是否结束。
|
||||
/// </summary>
|
||||
public bool IsFinish()
|
||||
{
|
||||
if (!context.start) return true;
|
||||
@@ -121,6 +190,10 @@ namespace XCharts.Runtime
|
||||
return context.currProgress == context.destProgress;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether animation is in delay.
|
||||
/// |动画是否在延迟中。
|
||||
/// </summary>
|
||||
public bool IsInDelay()
|
||||
{
|
||||
if (!context.start)
|
||||
@@ -129,6 +202,12 @@ namespace XCharts.Runtime
|
||||
return (m_Delay > 0 && Time.time - context.startTime < m_Delay / 1000);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether animation is in index delay.
|
||||
/// |动画是否在索引延迟中。
|
||||
/// </summary>
|
||||
/// <param name="dataIndex"></param>
|
||||
/// <returns></returns>
|
||||
public bool IsInIndexDelay(int dataIndex)
|
||||
{
|
||||
if (context.start)
|
||||
@@ -137,6 +216,12 @@ namespace XCharts.Runtime
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get animation delay.
|
||||
/// |获取动画延迟。
|
||||
/// </summary>
|
||||
/// <param name="dataIndex"></param>
|
||||
/// <returns></returns>
|
||||
public float GetIndexDelay(int dataIndex)
|
||||
{
|
||||
if (!context.start) return 0;
|
||||
@@ -279,24 +364,40 @@ namespace XCharts.Runtime
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fade in animation.
|
||||
/// |淡入动画。
|
||||
/// </summary>
|
||||
[Since("v3.8.0")]
|
||||
[System.Serializable]
|
||||
public class AnimationFadeIn : AnimationInfo
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fade out animation.
|
||||
/// |淡出动画。
|
||||
/// </summary>
|
||||
[Since("v3.8.0")]
|
||||
[System.Serializable]
|
||||
public class AnimationFadeOut : AnimationInfo
|
||||
public class AnimationFadeout : AnimationInfo
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Data change animation.
|
||||
/// |数据变更动画。
|
||||
/// </summary>
|
||||
[Since("v3.8.0")]
|
||||
[System.Serializable]
|
||||
public class AnimationChange : AnimationInfo
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Data addition animation.
|
||||
/// |数据新增动画。
|
||||
/// </summary>
|
||||
[Since("v3.8.0")]
|
||||
[System.Serializable]
|
||||
public class AnimationAddition : AnimationInfo
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace XCharts.Runtime
|
||||
[SerializeField] private int m_Threshold = 2000;
|
||||
[SerializeField][Since("v3.4.0")] private bool m_UnscaledTime;
|
||||
[SerializeField][Since("v3.8.0")] private AnimationFadeIn m_Fadein = new AnimationFadeIn();
|
||||
[SerializeField][Since("v3.8.0")] private AnimationFadeOut m_Fadeout = new AnimationFadeOut() { reverse = true };
|
||||
[SerializeField][Since("v3.8.0")] private AnimationFadeout m_Fadeout = new AnimationFadeout() { reverse = true };
|
||||
[SerializeField][Since("v3.8.0")] private AnimationChange m_Change = new AnimationChange() { duration = 500 };
|
||||
[SerializeField][Since("v3.8.0")] private AnimationAddition m_Addition = new AnimationAddition() { duration = 500 };
|
||||
|
||||
@@ -103,7 +103,7 @@ namespace XCharts.Runtime
|
||||
/// Fade out animation configuration.
|
||||
/// |渐出动画配置。
|
||||
/// </summary>
|
||||
public AnimationFadeOut fadeout { get { return m_Fadeout; } }
|
||||
public AnimationFadeout fadeout { get { return m_Fadeout; } }
|
||||
/// <summary>
|
||||
/// Update data animation configuration.
|
||||
/// |数据变更动画配置。
|
||||
@@ -133,6 +133,10 @@ namespace XCharts.Runtime
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The actived animation.
|
||||
/// |当前激活的动画。
|
||||
/// </summary>
|
||||
public AnimationInfo activedAnimation
|
||||
{
|
||||
get
|
||||
@@ -145,12 +149,20 @@ namespace XCharts.Runtime
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start fadein animation.
|
||||
/// |开始渐入动画。
|
||||
/// </summary>
|
||||
public void Fadein()
|
||||
{
|
||||
if (m_Fadeout.context.start) return;
|
||||
m_Fadein.Start();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restart the actived animation.
|
||||
/// |重启当前激活的动画。
|
||||
/// </summary>
|
||||
public void Restart()
|
||||
{
|
||||
var anim = activedAnimation;
|
||||
@@ -161,11 +173,19 @@ namespace XCharts.Runtime
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start fadeout animation.
|
||||
/// |开始渐出动画。
|
||||
/// </summary>
|
||||
public void Fadeout()
|
||||
{
|
||||
m_Fadeout.Start();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start additon animation.
|
||||
/// |开始数据新增动画。
|
||||
/// </summary>
|
||||
public void Addition()
|
||||
{
|
||||
if (!enable) return;
|
||||
@@ -175,6 +195,10 @@ namespace XCharts.Runtime
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pause all animations.
|
||||
/// |暂停所有动画。
|
||||
/// </summary>
|
||||
public void Pause()
|
||||
{
|
||||
foreach (var anim in animations)
|
||||
@@ -183,6 +207,10 @@ namespace XCharts.Runtime
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resume all animations.
|
||||
/// |恢复所有动画。
|
||||
/// </summary>
|
||||
public void Resume()
|
||||
{
|
||||
foreach (var anim in animations)
|
||||
@@ -191,12 +219,23 @@ namespace XCharts.Runtime
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reset all animations.
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
m_Fadein.Reset();
|
||||
m_Fadeout.Reset();
|
||||
foreach (var anim in animations)
|
||||
{
|
||||
anim.Reset();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize animation configuration.
|
||||
/// |初始化动画配置。
|
||||
/// </summary>
|
||||
/// <param name="curr">当前进度</param>
|
||||
/// <param name="dest">目标进度</param>
|
||||
public void InitProgress(float curr, float dest)
|
||||
{
|
||||
var anim = activedAnimation;
|
||||
@@ -220,6 +259,12 @@ namespace XCharts.Runtime
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize animation configuration.
|
||||
/// |初始化动画配置。
|
||||
/// </summary>
|
||||
/// <param name="paths">路径坐标点列表</param>
|
||||
/// <param name="isY">是Y轴还是X轴</param>
|
||||
public void InitProgress(List<Vector3> paths, bool isY)
|
||||
{
|
||||
if (paths.Count < 1) return;
|
||||
|
||||
@@ -382,8 +382,8 @@ namespace XCharts.Runtime
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether series animation enabel.
|
||||
/// |启用或关闭起始动画。
|
||||
/// Whether enable serie animations.
|
||||
/// |是否启用Serie动画。
|
||||
/// </summary>
|
||||
/// <param name="flag"></param>
|
||||
public void AnimationEnable(bool flag)
|
||||
@@ -392,24 +392,24 @@ namespace XCharts.Runtime
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// fadeIn animation.
|
||||
/// |开始渐入动画。
|
||||
/// Start all serie fadein animations.
|
||||
/// |开始所有Serie的渐入动画。
|
||||
/// </summary>
|
||||
/// <param name="reset">reset animation</param>
|
||||
public void AnimationFadein(bool reset = true)
|
||||
{
|
||||
if (reset)
|
||||
AnimationReset();
|
||||
if (reset) AnimationReset();
|
||||
foreach (var serie in m_Series) serie.AnimationFadein();
|
||||
}
|
||||
|
||||
|
||||
[Obsolete("Use AnimationFadein() instead.", true)]
|
||||
public void AnimationFadeIn(bool reset = true)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// fadeIn animation.
|
||||
/// |开始渐出动画。
|
||||
/// Start all serie fadeout animations.
|
||||
/// |开始所有Serie的渐出动画。
|
||||
/// </summary>
|
||||
public void AnimationFadeout()
|
||||
{
|
||||
@@ -422,8 +422,8 @@ namespace XCharts.Runtime
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pause animation.
|
||||
/// |暂停动画。
|
||||
/// Pause all animations.
|
||||
/// |暂停所有Serie的动画。
|
||||
/// </summary>
|
||||
public void AnimationPause()
|
||||
{
|
||||
@@ -431,8 +431,8 @@ namespace XCharts.Runtime
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stop play animation.
|
||||
/// |继续动画。
|
||||
/// Resume all animations.
|
||||
/// |继续所有Serie的动画。
|
||||
/// </summary>
|
||||
public void AnimationResume()
|
||||
{
|
||||
@@ -440,8 +440,8 @@ namespace XCharts.Runtime
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reset animation.
|
||||
/// |重置动画。
|
||||
/// Reset all animations.
|
||||
/// |重置所有Serie的动画。
|
||||
/// </summary>
|
||||
public void AnimationReset()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user