mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-25 10:20:10 +00:00
性能优化
This commit is contained in:
@@ -259,23 +259,31 @@ namespace XCharts
|
|||||||
m_DataCurrProgress[index] = state;
|
m_DataCurrProgress[index] = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
private float GetDataCurrProgress(int index, float initValue, float destValue)
|
private float GetDataCurrProgress(int index, float initValue, float destValue, out bool isBarEnd)
|
||||||
{
|
{
|
||||||
if (IsInDelay()) return initValue;
|
if (IsInDelay())
|
||||||
|
{
|
||||||
|
isBarEnd = false;
|
||||||
|
return initValue;
|
||||||
|
}
|
||||||
if (!m_DataCurrProgress.ContainsKey(index))
|
if (!m_DataCurrProgress.ContainsKey(index))
|
||||||
{
|
{
|
||||||
m_DataCurrProgress.Add(index, initValue);
|
m_DataCurrProgress.Add(index, initValue);
|
||||||
m_DataDestProgress.Add(index, destValue);
|
m_DataDestProgress.Add(index, destValue);
|
||||||
|
isBarEnd = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
isBarEnd = m_DataCurrProgress[index] == m_DataDestProgress[index];
|
||||||
}
|
}
|
||||||
return m_DataCurrProgress[index];
|
return m_DataCurrProgress[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsFinish(int dataCount = -1)
|
public bool IsFinish()
|
||||||
{
|
{
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
if (!Application.isPlaying) return true;
|
if (!Application.isPlaying) return true;
|
||||||
#endif
|
#endif
|
||||||
if (dataCount > 0 && (!IsAllOutDelay(dataCount) || !IsAllDataFinishProgress(dataCount))) return false;
|
|
||||||
return !m_Enable || m_IsEnd || (m_CurrDataProgress > m_DestDataProgress && m_CurrDetailProgress > m_DestDetailProgress);
|
return !m_Enable || m_IsEnd || (m_CurrDataProgress > m_DestDataProgress && m_CurrDetailProgress > m_DestDetailProgress);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -387,47 +395,52 @@ namespace XCharts
|
|||||||
else return m_FadeInDuration > 0 ? m_FadeInDuration / 1000 : 1f;
|
else return m_FadeInDuration > 0 ? m_FadeInDuration / 1000 : 1f;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal float CheckBarProgress(int dataIndex, float barHig, int dataCount)
|
internal float CheckBarProgress(int dataIndex, float barHig, int dataCount, out bool isBarEnd)
|
||||||
{
|
{
|
||||||
|
isBarEnd = false;
|
||||||
var initHig = m_FadeOut ? barHig : 0;
|
var initHig = m_FadeOut ? barHig : 0;
|
||||||
var destHig = m_FadeOut ? 0 : barHig;
|
var destHig = m_FadeOut ? 0 : barHig;
|
||||||
if (IsFinish() || m_IsEnd)
|
if (IsInDelay() || IsInDataDelay(dataIndex))
|
||||||
{
|
|
||||||
return m_FadeOuted ? 0 : barHig;
|
|
||||||
}
|
|
||||||
else if (IsInDelay() || IsInDataDelay(dataIndex))
|
|
||||||
{
|
{
|
||||||
return m_FadeOut ? barHig : 0;
|
return m_FadeOut ? barHig : 0;
|
||||||
}
|
}
|
||||||
|
var currHig = GetDataCurrProgress(dataIndex, initHig, destHig, out isBarEnd);
|
||||||
|
if (isBarEnd || m_IsEnd)
|
||||||
|
{
|
||||||
|
return m_FadeOuted ? 0 : barHig;
|
||||||
|
}
|
||||||
else if (m_IsPause)
|
else if (m_IsPause)
|
||||||
{
|
{
|
||||||
return GetDataCurrProgress(dataIndex, initHig, destHig);
|
return currHig;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var duration = GetCurrAnimationDuration(dataIndex);
|
var duration = GetCurrAnimationDuration(dataIndex);
|
||||||
var delta = barHig / duration * Time.deltaTime;
|
var delta = barHig / duration * Time.deltaTime;
|
||||||
var currHig = GetDataCurrProgress(dataIndex, initHig, destHig) + (m_FadeOut ? -delta : delta);
|
currHig = currHig + (m_FadeOut ? -delta : delta);
|
||||||
if (m_FadeOut)
|
if (m_FadeOut)
|
||||||
{
|
{
|
||||||
if ((initHig > 0 && currHig <= 0) || (initHig < 0 && currHig >= 0))
|
if ((initHig > 0 && currHig <= 0) || (initHig < 0 && currHig >= 0))
|
||||||
{
|
{
|
||||||
currHig = 0;
|
currHig = 0;
|
||||||
|
isBarEnd = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (Mathf.Abs(currHig) >= Mathf.Abs(barHig))
|
else if (Mathf.Abs(currHig) >= Mathf.Abs(barHig))
|
||||||
{
|
{
|
||||||
currHig = barHig;
|
currHig = barHig;
|
||||||
|
isBarEnd = true;
|
||||||
}
|
}
|
||||||
SetDataCurrProgress(dataIndex, currHig);
|
SetDataCurrProgress(dataIndex, currHig);
|
||||||
if (IsAllOutDelay(dataCount) && IsAllDataFinishProgress(dataCount))
|
|
||||||
{
|
|
||||||
End();
|
|
||||||
}
|
|
||||||
return currHig;
|
return currHig;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal void AllBarEnd()
|
||||||
|
{
|
||||||
|
End();
|
||||||
|
}
|
||||||
|
|
||||||
internal void CheckSymbol(float dest)
|
internal void CheckSymbol(float dest)
|
||||||
{
|
{
|
||||||
if (!enable || m_IsEnd || m_IsPause || !m_IsInit) return;
|
if (!enable || m_IsEnd || m_IsPause || !m_IsInit) return;
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ namespace XCharts
|
|||||||
float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
|
float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
|
||||||
float xMinValue = xAxis.GetCurrMinValue(dataChangeDuration);
|
float xMinValue = xAxis.GetCurrMinValue(dataChangeDuration);
|
||||||
float xMaxValue = xAxis.GetCurrMaxValue(dataChangeDuration);
|
float xMaxValue = xAxis.GetCurrMaxValue(dataChangeDuration);
|
||||||
|
var isAllBarEnd = true;
|
||||||
for (int i = serie.minShow; i < maxCount; i++)
|
for (int i = serie.minShow; i < maxCount; i++)
|
||||||
{
|
{
|
||||||
if (i >= seriesHig.Count)
|
if (i >= seriesHig.Count)
|
||||||
@@ -92,8 +92,9 @@ namespace XCharts
|
|||||||
seriesHig[i] += barHig;
|
seriesHig[i] += barHig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var isBarEnd = false;
|
||||||
float currHig = CheckAnimation(serie, i, barHig);
|
float currHig = CheckAnimation(serie, i, barHig, out isBarEnd);
|
||||||
|
if (!isBarEnd) isAllBarEnd = false;
|
||||||
Vector3 plt, prt, prb, plb, top;
|
Vector3 plt, prt, prb, plb, top;
|
||||||
if (value < 0)
|
if (value < 0)
|
||||||
{
|
{
|
||||||
@@ -135,6 +136,7 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (isAllBarEnd) serie.animation.AllBarEnd();
|
||||||
if (!SeriesHelper.IsStack(m_Series, serie.stack, SerieType.Bar))
|
if (!SeriesHelper.IsStack(m_Series, serie.stack, SerieType.Bar))
|
||||||
{
|
{
|
||||||
m_BarLastOffset += barGapWidth;
|
m_BarLastOffset += barGapWidth;
|
||||||
@@ -145,9 +147,9 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private float CheckAnimation(Serie serie, int dataIndex, float barHig)
|
private float CheckAnimation(Serie serie, int dataIndex, float barHig, out bool isBarEnd)
|
||||||
{
|
{
|
||||||
float currHig = serie.animation.CheckBarProgress(dataIndex, barHig, serie.dataCount);
|
float currHig = serie.animation.CheckBarProgress(dataIndex, barHig, serie.dataCount, out isBarEnd);
|
||||||
if (!serie.animation.IsFinish())
|
if (!serie.animation.IsFinish())
|
||||||
{
|
{
|
||||||
RefreshChart();
|
RefreshChart();
|
||||||
@@ -189,6 +191,7 @@ namespace XCharts
|
|||||||
float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
|
float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
|
||||||
float yMinValue = yAxis.GetCurrMinValue(dataChangeDuration);
|
float yMinValue = yAxis.GetCurrMinValue(dataChangeDuration);
|
||||||
float yMaxValue = yAxis.GetCurrMaxValue(dataChangeDuration);
|
float yMaxValue = yAxis.GetCurrMaxValue(dataChangeDuration);
|
||||||
|
var isAllBarEnd = true;
|
||||||
for (int i = serie.minShow; i < maxCount; i++)
|
for (int i = serie.minShow; i < maxCount; i++)
|
||||||
{
|
{
|
||||||
if (i >= seriesHig.Count)
|
if (i >= seriesHig.Count)
|
||||||
@@ -230,7 +233,9 @@ namespace XCharts
|
|||||||
/ valueTotal * m_CoordinateHeight;
|
/ valueTotal * m_CoordinateHeight;
|
||||||
seriesHig[i] += barHig;
|
seriesHig[i] += barHig;
|
||||||
}
|
}
|
||||||
float currHig = CheckAnimation(serie, i, barHig);
|
var isBarEnd = false;
|
||||||
|
float currHig = CheckAnimation(serie, i, barHig, out isBarEnd);
|
||||||
|
if (!isBarEnd) isAllBarEnd = false;
|
||||||
Vector3 plb, plt, prt, prb, top;
|
Vector3 plb, plt, prt, prb, top;
|
||||||
if (value < 0)
|
if (value < 0)
|
||||||
{
|
{
|
||||||
@@ -275,6 +280,10 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (isAllBarEnd)
|
||||||
|
{
|
||||||
|
serie.animation.AllBarEnd();
|
||||||
|
}
|
||||||
if (dataChanging)
|
if (dataChanging)
|
||||||
{
|
{
|
||||||
RefreshChart();
|
RefreshChart();
|
||||||
|
|||||||
@@ -1028,13 +1028,13 @@ namespace XCharts
|
|||||||
|
|
||||||
private bool TryAddToList(bool isTurnBack, bool isYAxis, List<Vector3> list, Vector3 lastPos, Vector3 pos, bool ignoreClose = false)
|
private bool TryAddToList(bool isTurnBack, bool isYAxis, List<Vector3> list, Vector3 lastPos, Vector3 pos, bool ignoreClose = false)
|
||||||
{
|
{
|
||||||
if (pos == Vector3.zero) return false;
|
if (ChartHelper.IsZeroVector(pos)) return false;
|
||||||
if (isTurnBack)
|
if (isTurnBack)
|
||||||
{
|
{
|
||||||
list.Add(pos);
|
list.Add(pos);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (lastPos != Vector3.zero && IsInRightOrUp(isYAxis, pos, lastPos))
|
else if (!ChartHelper.IsZeroVector(lastPos) && IsInRightOrUpNotCheckZero(isYAxis, pos, lastPos))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -1046,7 +1046,7 @@ namespace XCharts
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
var end = list[list.Count - 1];
|
var end = list[list.Count - 1];
|
||||||
if (IsInRightOrUp(isYAxis, end, pos) && (!ignoreClose || !WasTooClose(isYAxis, end, pos, ignoreClose)))
|
if (IsInRightOrUpNotCheckZero(isYAxis, end, pos) && (!ignoreClose || !WasTooClose(isYAxis, end, pos, ignoreClose)))
|
||||||
{
|
{
|
||||||
list.Add(pos);
|
list.Add(pos);
|
||||||
return true;
|
return true;
|
||||||
@@ -1065,7 +1065,12 @@ namespace XCharts
|
|||||||
|
|
||||||
private bool IsInRightOrUp(bool isYAxis, Vector3 lp, Vector3 rp)
|
private bool IsInRightOrUp(bool isYAxis, Vector3 lp, Vector3 rp)
|
||||||
{
|
{
|
||||||
return lp == Vector3.zero || ((isYAxis && rp.y > lp.y) || (!isYAxis && rp.x > lp.x));
|
return ChartHelper.IsZeroVector(lp) || ((isYAxis && rp.y > lp.y) || (!isYAxis && rp.x > lp.x));
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool IsInRightOrUpNotCheckZero(bool isYAxis, Vector3 lp, Vector3 rp)
|
||||||
|
{
|
||||||
|
return (isYAxis && rp.y > lp.y) || (!isYAxis && rp.x > lp.x);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool WasTooClose(bool isYAxis, Vector3 lp, Vector3 rp, bool ignore)
|
private bool WasTooClose(bool isYAxis, Vector3 lp, Vector3 rp, bool ignore)
|
||||||
|
|||||||
@@ -455,6 +455,11 @@ namespace XCharts
|
|||||||
return color.a == 0 && color.b == 0 && color.g == 0 && color.r == 0;
|
return color.a == 0 && color.b == 0 && color.g == 0 && color.r == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool IsZeroVector(Vector3 pos)
|
||||||
|
{
|
||||||
|
return pos.x == 0 && pos.y == 0 && pos.z == 0;
|
||||||
|
}
|
||||||
|
|
||||||
public static bool CopyList<T>(List<T> toList, List<T> fromList)
|
public static bool CopyList<T>(List<T> toList, List<T> fromList)
|
||||||
{
|
{
|
||||||
if (toList == null || fromList == null) return false;
|
if (toList == null || fromList == null) return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user