diff --git a/Demo/Scripts/Demo10_LineSimple.cs b/Demo/Scripts/Demo10_LineSimple.cs index 220047ba..a3171cf2 100644 --- a/Demo/Scripts/Demo10_LineSimple.cs +++ b/Demo/Scripts/Demo10_LineSimple.cs @@ -5,7 +5,8 @@ using XCharts; [ExecuteInEditMode] public class Demo10_LineSimple : MonoBehaviour { - void Awake() + //void Awake() + void Start() { var chart = gameObject.GetComponent(); if (chart == null) return; diff --git a/Scripts/UI/Component/Series.cs b/Scripts/UI/Component/Series.cs index eb85cef7..c6a72c36 100644 --- a/Scripts/UI/Component/Series.cs +++ b/Scripts/UI/Component/Series.cs @@ -46,6 +46,7 @@ namespace XCharts /// public void ClearData() { + AnimationStop(); foreach (var serie in m_Series) { serie.ClearData(); @@ -200,6 +201,7 @@ namespace XCharts /// public void RemoveAll() { + AnimationStop(); m_Series.Clear(); } @@ -793,6 +795,9 @@ namespace XCharts } } + /// + /// 开始初始动画 + /// public void AnimationStart() { foreach (var serie in m_Series) @@ -804,6 +809,17 @@ namespace XCharts } } + /// + /// 停止初始动画 + /// + public void AnimationStop() + { + foreach (var serie in m_Series) + { + if (serie.animation.enable) serie.animation.Stop(); + } + } + /// /// 从json中解析数据 /// diff --git a/Scripts/UI/Internal/Animation.cs b/Scripts/UI/Internal/Animation.cs index 55357061..f7b65390 100644 --- a/Scripts/UI/Internal/Animation.cs +++ b/Scripts/UI/Internal/Animation.cs @@ -57,7 +57,8 @@ namespace XCharts /// public int delay { get { return m_Delay; } set { m_Delay = value; if (m_Delay < 0) m_Delay = 0; } } - private Dictionary m_DataAnimationState = new Dictionary(); + private Dictionary m_DataAnimationState = new Dictionary(); + private bool m_IsStart = false; private bool m_IsEnd = true; private bool m_Inited = false; @@ -70,7 +71,9 @@ namespace XCharts public void Start() { + if (m_IsStart) return; startTime = Time.time; + m_IsStart = true; m_IsEnd = false; m_Inited = false; m_CurrDataProgress = 1; @@ -81,6 +84,14 @@ namespace XCharts m_DataAnimationState.Clear(); } + public void Stop() + { + m_IsStart = false; + m_IsEnd = true; + m_Inited = false; + m_DataAnimationState.Clear(); + } + public void End() { if (m_IsEnd) return; @@ -89,8 +100,6 @@ namespace XCharts m_IsEnd = true; } - - public void InitProgress(int data, float curr, float dest) { if (!m_Inited) @@ -110,15 +119,17 @@ namespace XCharts } } - public void SetDataState(int index,float state) + public void SetDataState(int index, float state) { m_DataAnimationState[index] = state; } - public float GetDataState(int index){ - if(IsInDelay()) return 0; - if(!m_DataAnimationState.ContainsKey(index)){ - m_DataAnimationState.Add(index,0); + public float GetDataState(int index) + { + if (IsInDelay()) return 0; + if (!m_DataAnimationState.ContainsKey(index)) + { + m_DataAnimationState.Add(index, 0); } return m_DataAnimationState[index]; } @@ -186,11 +197,13 @@ namespace XCharts return m_CurrSymbolProgress; } - public float GetCurrDetail(){ + public float GetCurrDetail() + { return m_CurrDetailProgress; } - public float GetCurrData(){ + public float GetCurrData() + { return m_CurrDataProgress; } } diff --git a/Scripts/UI/Internal/BaseChart.cs b/Scripts/UI/Internal/BaseChart.cs index 59ee2ead..dce2a955 100644 --- a/Scripts/UI/Internal/BaseChart.cs +++ b/Scripts/UI/Internal/BaseChart.cs @@ -54,6 +54,7 @@ namespace XCharts [NonSerialized] private bool m_RefreshChart = false; [NonSerialized] private bool m_RefreshLabel = false; [NonSerialized] private bool m_ReinitLabel = false; + [NonSerialized] private bool m_CheckAnimation = false; protected Vector2 chartAnchorMax { get { return rectTransform.anchorMax; } } protected Vector2 chartAnchorMin { get { return rectTransform.anchorMin; } } @@ -79,6 +80,7 @@ namespace XCharts InitSerieLabel(); InitTooltip(); TransferOldVersionData(); + m_Series.AnimationStop(); m_Series.AnimationStart(); } @@ -96,6 +98,7 @@ namespace XCharts CheckTooltip(); CheckRefreshChart(); CheckRefreshLabel(); + CheckAnimation(); } protected override void OnEnable() @@ -315,7 +318,7 @@ namespace XCharts var backgroundColor = serie.label.backgroundColor; var labelObj = ChartHelper.AddSerieLabel(textName, labelObject.transform, m_ThemeInfo.font, color, backgroundColor, serie.label.fontSize, serie.label.fontStyle, serie.label.rotate, - serie.label.backgroundWidth,serie.label.backgroundHeight); + serie.label.backgroundWidth, serie.label.backgroundHeight); var isAutoSize = serie.label.backgroundWidth == 0 || serie.label.backgroundHeight == 0; serieData.InitLabel(labelObj, isAutoSize, serie.label.paddingLeftRight, serie.label.paddingTopBottom); serieData.SetLabelActive(false); @@ -469,6 +472,15 @@ namespace XCharts } } + protected void CheckAnimation() + { + if (!m_CheckAnimation) + { + m_CheckAnimation = true; + m_Series.AnimationStart(); + } + } + protected virtual void OnRefreshLabel() { diff --git a/Scripts/UI/Internal/BaseChart_API.cs b/Scripts/UI/Internal/BaseChart_API.cs index 8a7375ad..6c3fab7d 100644 --- a/Scripts/UI/Internal/BaseChart_API.cs +++ b/Scripts/UI/Internal/BaseChart_API.cs @@ -79,7 +79,7 @@ namespace XCharts /// /// public float lineSmoothStyle { get { return m_LineSmoothStyle; } set { m_LineSmoothStyle = value; } } - + /// /// Set the size of chart. /// 设置图表的大小。 @@ -106,6 +106,7 @@ namespace XCharts { m_Series.ClearData(); m_Legend.ClearData(); + m_CheckAnimation = false; RefreshChart(); } @@ -118,6 +119,7 @@ namespace XCharts { m_Legend.ClearData(); m_Series.RemoveAll(); + m_CheckAnimation = false; RefreshChart(); } @@ -422,5 +424,22 @@ namespace XCharts OnThemeChanged(); RefreshChart(); } + + /// + /// 开始初始动画 + /// + public void AnimationStart() + { + m_Series.AnimationStart(); + } + + /// + /// 停止初始化动画 + /// + public void AnimationStop() + { + m_CheckAnimation = false; + m_Series.AnimationStop(); + } } }