UI update 02

This commit is contained in:
2026-06-30 21:21:30 +08:00
parent b2a1e307a4
commit f62f643cfc
1666 changed files with 211081 additions and 22799 deletions
@@ -0,0 +1,506 @@
using System;
using UnityEngine;
namespace XCharts.Runtime
{
/// <summary>
/// the animation info.
/// ||动画配置参数。
/// </summary>
[Since("v3.8.0")]
[System.Serializable]
public class AnimationInfo
{
[SerializeField][Since("v3.8.0")] private bool m_Enable = true;
[SerializeField][Since("v3.8.0")] private bool m_Reverse = false;
[SerializeField][Since("v3.8.0")] private float m_Delay = 0;
[SerializeField][Since("v3.8.0")] private float m_Duration = 1000;
[SerializeField][Since("v3.14.0")] private float m_Speed = 0;
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. Default is used to calculate the speed of animation. It can also be specified by speed.
/// ||动画的时长。默认用于计算动画的速度。也可以通过speed指定速度。
/// </summary>
public float duration { get { return m_Duration; } set { m_Duration = value; } }
/// <summary>
/// the speed of animation. When speed is specified, duration will be invalid. Default is 0, which means no speed specified.
/// ||动画的速度。当指定speed时,duration将失效。默认为0,表示不指定速度。
/// </summary>
public float speed { get { return m_Speed; } set { m_Speed = 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;
context.init = false;
context.start = false;
context.pause = false;
context.end = false;
context.startTime = 0;
context.currProgress = 0;
context.destProgress = 0;
context.totalProgress = 0;
context.sizeProgress = 0;
context.currPointIndex = 0;
context.currPoint = Vector3.zero;
context.destPoint = Vector3.zero;
context.dataCurrProgress.Clear();
context.dataDestProgress.Clear();
}
/// <summary>
/// Start animation.
/// ||开始动画。
/// </summary>
/// <param name="reset">是否重置上一次的参数</param>
public void Start(bool reset = true)
{
if (!enable) return;
if (context.start)
{
context.pause = false;
return;
}
context.init = false;
context.start = true;
context.end = false;
context.pause = false;
context.startTime = Time.time;
if (reset)
{
context.currProgress = 0;
context.destProgress = 1;
context.totalProgress = 0;
context.sizeProgress = 0;
context.dataCurrProgress.Clear();
context.dataDestProgress.Clear();
}
if (OnAnimationStart != null)
{
OnAnimationStart();
}
}
/// <summary>
/// Pause animation.
/// ||暂停动画。
/// </summary>
public void Pause()
{
if (!enable) return;
if (!context.start || context.end) return;
context.pause = true;
}
/// <summary>
/// Resume animation.
/// ||恢复动画。
/// </summary>
public void Resume()
{
if (!enable) return;
if (!context.pause) return;
context.pause = false;
}
/// <summary>
/// End animation.
/// ||结束动画。
/// </summary>
public void End()
{
if (!enable) return;
if (!context.start || context.end) return;
context.init = false;
context.start = false;
context.end = true;
context.currPointIndex = context.destPointIndex;
context.startTime = Time.time;
if (OnAnimationEnd != null)
{
OnAnimationEnd();
}
}
/// <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;
context.totalProgress = dest - curr;
context.destPointIndex = totalPointIndex;
if (reverse)
{
if (!context.init) context.currProgress = dest;
context.destProgress = curr;
}
else
{
if (!context.init) context.currProgress = curr;
context.destProgress = dest;
}
context.init = true;
return true;
}
/// <summary>
/// Whether animation is finish.
/// ||动画是否结束。
/// </summary>
public bool IsFinish()
{
if (!context.start) return true;
if (context.end) return true;
if (context.pause) return false;
if (!context.init) return false;
return m_Reverse ? context.currProgress <= context.destProgress
: context.currProgress >= context.destProgress;
}
/// <summary>
/// Whether animation is in delay.
/// ||动画是否在延迟中。
/// </summary>
public bool IsInDelay()
{
if (!context.start)
return false;
else
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)
return Time.time - context.startTime < GetIndexDelay(dataIndex) / 1000f;
else
return false;
}
/// <summary>
/// Get animation delay.
/// ||获取动画延迟。
/// </summary>
/// <param name="dataIndex"></param>
/// <returns></returns>
public float GetIndexDelay(int dataIndex)
{
if (!context.start) return 0;
if (delayFunction != null)
return delayFunction(dataIndex);
return delay;
}
internal float GetCurrAnimationDuration(int dataIndex = -1)
{
if (dataIndex >= 0)
{
if (context.start && durationFunction != null)
return durationFunction(dataIndex) / 1000f;
}
return m_Duration > 0 ? m_Duration / 1000 : 1f;
}
internal void SetDataCurrProgress(int index, float state)
{
context.dataCurrProgress[index] = state;
}
internal float GetDataCurrProgress(int index, float initValue, float destValue, ref bool isBarEnd)
{
if (IsInDelay())
{
isBarEnd = false;
return initValue;
}
var c1 = !context.dataCurrProgress.ContainsKey(index);
var c2 = !context.dataDestProgress.ContainsKey(index);
if (c1 || c2)
{
if (c1)
context.dataCurrProgress.Add(index, initValue);
if (c2)
context.dataDestProgress.Add(index, destValue);
isBarEnd = false;
}
else
{
isBarEnd = context.dataCurrProgress[index] == context.dataDestProgress[index];
}
return context.dataCurrProgress[index];
}
internal void CheckProgress(double total, bool m_UnscaledTime)
{
if (!context.start || !context.init || context.pause) return;
if (IsInDelay()) return;
var delta = GetDelta(total, m_UnscaledTime);
if (reverse)
{
context.currProgress -= delta;
if (context.currProgress <= context.destProgress)
{
context.currProgress = context.destProgress;
End();
}
}
else
{
context.currProgress += delta;
if (context.currProgress >= context.destProgress)
{
context.currProgress = context.destProgress;
End();
}
}
}
internal float CheckItemProgress(int dataIndex, float destProgress, ref bool isEnd, float startProgress, bool m_UnscaledTime)
{
if (m_Reverse)
{
var temp = startProgress;
startProgress = destProgress;
destProgress = temp;
}
var currHig = GetDataCurrProgress(dataIndex, startProgress, destProgress, ref isEnd);
if (IsFinish())
{
return destProgress;
}
else if (IsInDelay() || IsInIndexDelay(dataIndex))
{
return startProgress;
}
else if (context.pause)
{
return currHig;
}
else
{
var delta = GetDelta(destProgress - startProgress, m_UnscaledTime);
currHig += delta;
if (reverse)
{
if ((destProgress > 0 && currHig <= 0) || (destProgress < 0 && currHig >= 0))
{
currHig = 0;
isEnd = true;
}
}
else
{
if ((destProgress - startProgress > 0 && currHig > destProgress) ||
(destProgress - startProgress < 0 && currHig < destProgress))
{
currHig = destProgress;
isEnd = true;
}
}
SetDataCurrProgress(dataIndex, currHig);
return currHig;
}
}
internal void CheckSymbol(float dest, bool m_UnscaledTime)
{
if (!context.start || !context.init || context.pause) return;
if (IsInDelay())
return;
var delta = GetDelta(dest, m_UnscaledTime);
if (reverse)
{
context.sizeProgress -= delta;
if (context.sizeProgress < 0)
context.sizeProgress = 0;
}
else
{
context.sizeProgress += delta;
if (context.sizeProgress > dest)
context.sizeProgress = dest;
}
}
private float GetDelta(double total, bool unscaledTime)
{
if (m_Speed > 0)
{
context.currDuration = (float)total / m_Speed;
return (float)(m_Speed * (unscaledTime ? Time.unscaledDeltaTime : Time.deltaTime));
}
else
{
context.currDuration = 0;
return (float)(total / GetCurrAnimationDuration() * (unscaledTime ? Time.unscaledDeltaTime : Time.deltaTime));
}
}
}
/// <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
{
}
/// <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
{
}
/// <summary>
/// Data hiding animation.
/// ||数据隐藏动画。
/// </summary>
[Since("v3.8.0")]
[System.Serializable]
public class AnimationHiding : AnimationInfo
{
}
/// <summary>
/// Interactive animation of charts.
/// ||交互动画。
/// </summary>
[Since("v3.8.0")]
[System.Serializable]
public class AnimationInteraction : AnimationInfo
{
[SerializeField][Since("v3.8.0")] private MLValue m_Width = new MLValue(1.1f);
[SerializeField][Since("v3.8.0")] private MLValue m_Radius = new MLValue(1.1f);
[SerializeField][Since("v3.8.0")] private MLValue m_Offset = new MLValue(MLValue.Type.Absolute, 5f);
/// <summary>
/// the mlvalue of width.
/// ||宽度的多样式数值。
/// </summary>
public MLValue width { get { return m_Width; } set { m_Width = value; } }
/// <summary>
/// the mlvalue of radius.
/// ||半径的多样式数值。
/// </summary>
public MLValue radius { get { return m_Radius; } set { m_Radius = value; } }
/// <summary>
/// the mlvalue of offset. Such as the offset of the pie chart when the sector is selected.
/// ||交互的多样式数值。如饼图的扇形选中时的偏移。
/// </summary>
public MLValue offset { get { return m_Offset; } set { m_Offset = value; } }
public float GetRadius(float radius)
{
return m_Radius.GetValue(radius);
}
public float GetWidth(float width)
{
return m_Width.GetValue(width);
}
public float GetOffset(float total)
{
return m_Offset.GetValue(total);
}
public float GetOffset()
{
return m_Offset.value;
}
}
/// <summary>
/// Data exchange animation. Generally used for animation of data sorting.
/// ||数据交换动画。一般用于图表数据排序时顺序变化的动画。
/// </summary>
[Since("v3.15.0")]
[System.Serializable]
public class AnimationExchange : AnimationInfo
{
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ae54b92d6276445ac9524b598bfb6e84
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace XCharts.Runtime
{
public sealed class AnimationInfoContext
{
public bool init;
public bool start;
public bool pause;
public bool end;
public float startTime;
public float currProgress;
public float destProgress;
public float totalProgress;
public float sizeProgress;
public int currPointIndex;
public int destPointIndex;
public float currDuration;
public Vector3 currPoint;
public Vector3 destPoint;
public Dictionary<int, float> dataCurrProgress = new Dictionary<int, float>();
public Dictionary<int, float> dataDestProgress = new Dictionary<int, float>();
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 023c7390605c34a72b13f5db7a647f06
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,630 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace XCharts.Runtime
{
public enum AnimationType
{
/// <summary>
/// he default. An animation playback mode will be selected according to the actual situation.
/// ||默认。内部会根据实际情况选择一种动画播放方式。
/// </summary>
Default,
/// <summary>
/// Play the animation from left to right.
/// ||从左往右播放动画。
/// </summary>
LeftToRight,
/// <summary>
/// Play the animation from bottom to top.
/// ||从下往上播放动画。
/// </summary>
BottomToTop,
/// <summary>
/// Play animations from the inside out.
/// ||由内到外播放动画。
/// </summary>
InsideOut,
/// <summary>
/// Play the animation along the path.
/// ||沿着路径播放动画。当折线图从左到右无序或有折返时,可以使用该模式。
/// </summary>
AlongPath,
/// <summary>
/// Play the animation clockwise.
/// ||顺时针播放动画。
/// </summary>
Clockwise,
}
public enum AnimationEasing
{
Linear,
}
/// <summary>
/// the animation of serie. support animation type: fadeIn, fadeOut, change, addition, exchange.
/// ||动画组件,用于控制图表的动画播放。支持配置五种动画表现:FadeIn(渐入动画),FadeOut(渐出动画),Change(变更动画),Addition(新增动画),Interaction(交互动画),Exchange(交换动画)。
/// 按作用的对象可以分为两类:SerieAnimation(系列动画)和DataAnimation(数据动画)。
/// </summary>
[System.Serializable]
public class AnimationStyle : ChildComponent
{
[SerializeField] private bool m_Enable = true;
[SerializeField] private AnimationType m_Type;
[SerializeField] private AnimationEasing m_Easting;
[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 AnimationChange m_Change = new AnimationChange() { duration = 500 };
[SerializeField][Since("v3.8.0")] private AnimationAddition m_Addition = new AnimationAddition() { duration = 500 };
[SerializeField][Since("v3.8.0")] private AnimationHiding m_Hiding = new AnimationHiding() { duration = 500 };
[SerializeField][Since("v3.8.0")] private AnimationInteraction m_Interaction = new AnimationInteraction() { duration = 250 };
[SerializeField][Since("v3.15.0")] private AnimationExchange m_Exchange = new AnimationExchange() { duration = 250 };
[Obsolete("Use animation.fadeIn.delayFunction instead.", true)]
public AnimationDelayFunction fadeInDelayFunction;
[Obsolete("Use animation.fadeIn.durationFunction instead.", true)]
public AnimationDurationFunction fadeInDurationFunction;
[Obsolete("Use animation.fadeOut.delayFunction instead.", true)]
public AnimationDelayFunction fadeOutDelayFunction;
[Obsolete("Use animation.fadeOut.durationFunction instead.", true)]
public AnimationDurationFunction fadeOutDurationFunction;
[Obsolete("Use animation.fadeIn.OnAnimationEnd() instead.", true)]
public Action fadeInFinishCallback { get; set; }
[Obsolete("Use animation.fadeOut.OnAnimationEnd() instead.", true)]
public Action fadeOutFinishCallback { get; set; }
public AnimationStyleContext context = new AnimationStyleContext();
/// <summary>
/// Whether to enable animation.
/// ||是否开启动画效果。
/// </summary>
public bool enable { get { return m_Enable; } set { m_Enable = value; } }
/// <summary>
/// The type of animation.
/// ||动画类型。
/// </summary>
public AnimationType type
{
get { return m_Type; }
set
{
m_Type = value;
if (m_Type != AnimationType.Default)
{
context.type = m_Type;
}
}
}
/// <summary>
/// Whether to set graphic number threshold to animation. Animation will be disabled when graphic number is larger than threshold.
/// ||是否开启动画的阈值,当单个系列显示的图形数量大于这个阈值时会关闭动画。
/// </summary>
public int threshold { get { return m_Threshold; } set { m_Threshold = value; } }
/// <summary>
/// Animation updates independently of Time.timeScale.
/// ||动画是否受TimeScaled的影响。默认为 false 受TimeScaled的影响。
/// </summary>
public bool unscaledTime { get { return m_UnscaledTime; } set { m_UnscaledTime = value; } }
/// <summary>
/// Fade in animation configuration.
/// ||渐入动画配置。
/// </summary>
public AnimationFadeIn fadeIn { get { return m_FadeIn; } }
/// <summary>
/// Fade out animation configuration.
/// ||渐出动画配置。
/// </summary>
public AnimationFadeOut fadeOut { get { return m_FadeOut; } }
/// <summary>
/// Update data animation configuration.
/// ||数据变更动画配置。
/// </summary>
public AnimationChange change { get { return m_Change; } }
/// <summary>
/// Add data animation configuration.
/// ||数据新增动画配置。
/// </summary>
public AnimationAddition addition { get { return m_Addition; } }
/// <summary>
/// Data hiding animation configuration.
/// ||数据隐藏动画配置。
/// </summary>
public AnimationHiding hiding { get { return m_Hiding; } }
/// <summary>
/// Interaction animation configuration.
/// ||交互动画配置。
/// </summary>
public AnimationInteraction interaction { get { return m_Interaction; } }
/// <summary>
/// Exchange animation configuration. Valid in sort bar chart.
/// ||交换动画配置。如在排序柱图中有效。
/// </summary>
public AnimationExchange exchange { get { return m_Exchange; } }
private Vector3 m_LinePathLastPos;
private List<AnimationInfo> m_Animations;
private List<AnimationInfo> animations
{
get
{
if (m_Animations == null)
{
m_Animations = new List<AnimationInfo>
{
m_FadeIn,
m_FadeOut,
m_Change,
m_Addition,
m_Hiding,
m_Exchange
};
}
return m_Animations;
}
}
/// <summary>
/// The actived animation.
/// ||当前激活的动画。
/// </summary>
public AnimationInfo activedAnimation
{
get
{
foreach (var anim in animations)
{
if (anim.context.start) return anim;
}
return null;
}
}
/// <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;
Reset();
if (anim != null)
{
anim.Start();
}
}
/// <summary>
/// Start fadeout animation.
/// ||开始渐出动画。
/// </summary>
public void FadeOut()
{
m_FadeOut.Start();
}
/// <summary>
/// Start additon animation.
/// ||开始数据新增动画。
/// </summary>
public void Addition()
{
if (!enable) return;
if (!m_FadeIn.context.start && !m_FadeOut.context.start)
{
m_Addition.Start(false);
}
}
/// <summary>
/// Pause all animations.
/// ||暂停所有动画。
/// </summary>
public void Pause()
{
foreach (var anim in animations)
{
anim.Pause();
}
}
/// <summary>
/// Resume all animations.
/// ||恢复所有动画。
/// </summary>
public void Resume()
{
foreach (var anim in animations)
{
anim.Resume();
}
}
/// <summary>
/// Reset all animations.
/// </summary>
public void 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;
if (anim == null) return;
var isAddedAnim = anim is AnimationAddition;
if (IsSerieAnimation())
{
if (isAddedAnim)
{
anim.Init(anim.context.currPointIndex, dest, (int)dest - 1);
}
else
{
m_Addition.context.currPointIndex = (int)dest - 1;
anim.Init(curr, dest, (int)dest - 1);
}
}
else
{
anim.Init(curr, dest, 0);
}
}
/// <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;
var anim = activedAnimation;
if (anim == null)
{
m_Addition.context.currPointIndex = paths.Count - 1;
return;
}
var isAddedAnim = anim is AnimationAddition;
var startIndex = 0;
if (isAddedAnim)
{
startIndex = anim.context.currPointIndex == paths.Count - 1 ?
paths.Count - 2 :
anim.context.currPointIndex;
if (startIndex < 0 || startIndex >= paths.Count - 1) return;
}
else
{
m_Addition.context.currPointIndex = paths.Count - 1;
}
var sp = paths[startIndex];
var ep = paths[paths.Count - 1];
var currDetailProgress = isY ? sp.y : sp.x;
var totalDetailProgress = isY ? ep.y : ep.x;
if (context.type == AnimationType.AlongPath)
{
currDetailProgress = 0;
totalDetailProgress = 0;
var lp = sp;
for (int i = 1; i < paths.Count; i++)
{
var np = paths[i];
totalDetailProgress += Vector3.Distance(np, lp);
lp = np;
if (startIndex > 0 && i == startIndex)
currDetailProgress = totalDetailProgress;
}
m_LinePathLastPos = sp;
context.currentPathDistance = 0;
}
if (sp == anim.context.currPoint && ep == anim.context.destPoint)
{
return;
}
if (anim.Init(currDetailProgress, totalDetailProgress, paths.Count - 1))
{
anim.context.currPoint = sp;
anim.context.destPoint = ep;
}
}
public bool IsEnd()
{
foreach (var animation in animations)
{
if (animation.context.start)
return animation.context.end;
}
return m_FadeIn.context.end;
}
public bool IsFinish()
{
#if UNITY_EDITOR
if (!Application.isPlaying)
return true;
#endif
if (!m_Enable)
return true;
var animation = activedAnimation;
if (animation != null && animation.context.end)
{
return true;
}
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 (IsDataAnimation())
{
if (animation == null) return true;
else return animation.context.end;
}
return true;
}
public bool IsInDelay()
{
var anim = activedAnimation;
if (anim != null)
return anim.IsInDelay();
return false;
}
/// <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;
}
/// <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;
}
public bool CheckDetailBreak(float detail)
{
if (!IsSerieAnimation())
return false;
foreach (var animation in animations)
{
if (animation.context.start)
return !IsFinish() && detail > animation.context.currProgress;
}
return false;
}
public bool CheckDetailBreak(Vector3 pos, bool isYAxis)
{
if (!IsSerieAnimation())
return false;
if (IsFinish())
return false;
if (context.type == AnimationType.AlongPath)
{
context.currentPathDistance += Vector3.Distance(pos, m_LinePathLastPos);
m_LinePathLastPos = pos;
return CheckDetailBreak(context.currentPathDistance);
}
else
{
if (isYAxis)
return pos.y > GetCurrDetail();
else
return pos.x > GetCurrDetail();
}
}
public void CheckProgress()
{
if (IsDataAnimation() && context.isAllItemAnimationEnd)
{
foreach (var animation in animations)
{
animation.End();
}
return;
}
foreach (var animation in animations)
{
animation.CheckProgress(animation.context.totalProgress, m_UnscaledTime);
}
}
public void CheckProgress(double total)
{
if (IsFinish())
return;
foreach (var animation in animations)
{
animation.CheckProgress(total, m_UnscaledTime);
}
}
internal float CheckItemProgress(int dataIndex, float destProgress, ref bool isEnd, float startProgress = 0)
{
isEnd = false;
var anim = activedAnimation;
if (anim == null)
{
isEnd = true;
return destProgress;
}
return anim.CheckItemProgress(dataIndex, destProgress, ref isEnd, startProgress, m_UnscaledTime);
}
public void CheckSymbol(float dest)
{
m_FadeIn.CheckSymbol(dest, m_UnscaledTime);
m_FadeOut.CheckSymbol(dest, m_UnscaledTime);
}
public float GetSysmbolSize(float dest)
{
#if UNITY_EDITOR
if (!Application.isPlaying)
return dest;
#endif
if (!enable)
return dest;
if (IsEnd())
return m_FadeOut.context.start ? 0 : dest;
return m_FadeOut.context.start ? m_FadeOut.context.sizeProgress : m_FadeIn.context.sizeProgress;
}
public float GetCurrDetail()
{
#if UNITY_EDITOR
if (!Application.isPlaying)
{
foreach (var animation in animations)
{
if (animation.context.start)
return animation.context.destProgress;
}
}
#endif
foreach (var animation in animations)
{
if (animation.context.start)
return animation.context.currProgress;
}
return m_FadeIn.context.currProgress;
}
public float GetCurrRate()
{
#if UNITY_EDITOR
if (!Application.isPlaying)
return 1;
#endif
if (!enable || IsEnd())
return 1;
return m_FadeOut.context.start ? m_FadeOut.context.currProgress : m_FadeIn.context.currProgress;
}
public int GetCurrIndex()
{
#if UNITY_EDITOR
if (!Application.isPlaying)
return -1;
#endif
if (!enable)
return -1;
var anim = activedAnimation;
if (anim == null)
return -1;
return (int)anim.context.currProgress;
}
public float GetChangeDuration()
{
if (m_Enable && m_Change.enable)
return m_Change.context.currDuration > 0 ? m_Change.context.currDuration : m_Change.duration;
else
return 0;
}
public float GetExchangeDuration()
{
if (m_Enable && m_Exchange.enable)
return m_Exchange.context.currDuration > 0 ? m_Exchange.context.currDuration : m_Exchange.duration;
else
return 0;
}
public float GetAdditionDuration()
{
if (m_Enable && m_Addition.enable)
return m_Addition.context.currDuration > 0 ? m_Addition.context.currDuration : m_Addition.duration;
else
return 0;
}
public float GetInteractionDuration()
{
if (m_Enable && m_Interaction.enable)
return m_Interaction.context.currDuration > 0 ? m_Interaction.context.currDuration : m_Interaction.duration;
else
return 0;
}
public float GetInteractionRadius(float radius)
{
if (m_Enable && m_Interaction.enable)
return m_Interaction.GetRadius(radius);
else
return radius;
}
public bool HasFadeOut()
{
return enable && m_FadeOut.context.end;
}
public bool IsFadeIn()
{
return enable && m_FadeIn.context.start;
}
public bool IsFadeOut()
{
return enable && m_FadeOut.context.start;
}
public bool CanCheckInteract()
{
return enable && interaction.enable
&& !IsFadeIn() && !IsFadeOut();
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e31c30f2ef61c48718a626f93307ce92
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace XCharts.Runtime
{
public struct AnimationStyleContext
{
public AnimationType type;
public bool enableSerieDataAddedAnimation;
public float currentPathDistance;
public bool isAllItemAnimationEnd;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b3dc504960589413fa6a76267067775c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,77 @@
using UnityEngine;
using XUGL;
namespace XCharts.Runtime
{
public static class AnimationStyleHelper
{
public static float CheckDataAnimation(BaseChart chart, Serie serie, int dataIndex, float destProgress, float startPorgress = 0)
{
if (!serie.animation.IsDataAnimation())
{
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);
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;
if (serieType.IsDefined(typeof(DefaultAnimationAttribute), false))
{
var attribute = serieType.GetAttribute<DefaultAnimationAttribute>();
animationType = attribute.type;
enableSerieDataAnimation = attribute.enableSerieDataAddedAnimation;
}
UpdateAnimationType(serie.animation, animationType, enableSerieDataAnimation);
}
public static void UpdateAnimationType(AnimationStyle animation, AnimationType defaultType, bool enableSerieDataAnimation)
{
animation.context.type = animation.type == AnimationType.Default ?
defaultType :
animation.type;
animation.context.enableSerieDataAddedAnimation = enableSerieDataAnimation;
}
public static bool GetAnimationPosition(AnimationStyle animation, bool isY, Vector3 lp, Vector3 cp, float progress, ref Vector3 ip, ref float rate)
{
if (animation.context.type == AnimationType.AlongPath)
{
var dist = Vector3.Distance(lp, cp);
rate = (dist - animation.context.currentPathDistance + animation.GetCurrDetail()) / dist;
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);
if (UGLHelper.GetIntersection(lp, cp, startPos, endPos, ref ip))
{
rate = Vector3.Distance(lp, ip) / Vector3.Distance(lp, cp);
return true;
}
else
{
return false;
}
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 54cadaee0856b4f7085787fd450eec37
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: