mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-26 02:40:13 +00:00
增加Animation的speed可指定动画速度
This commit is contained in:
@@ -79,6 +79,7 @@ slug: /changelog
|
|||||||
|
|
||||||
## master
|
## master
|
||||||
|
|
||||||
|
* (2025.03.07) 增加`Animation`的`speed`可指定动画速度
|
||||||
* (2025.03.06) 优化`Animation`的新增动画表现
|
* (2025.03.06) 优化`Animation`的新增动画表现
|
||||||
* (2025.03.04) 修复`Treemap`的`label`显示异常的问题
|
* (2025.03.04) 修复`Treemap`的`label`显示异常的问题
|
||||||
* (2025.03.02) 增加`Tooltip`的`columnGapWidths`参数设置列文本间隙距离
|
* (2025.03.02) 增加`Tooltip`的`columnGapWidths`参数设置列文本间隙距离
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ namespace XCharts.Editor
|
|||||||
++EditorGUI.indentLevel;
|
++EditorGUI.indentLevel;
|
||||||
PropertyField(prop, "m_Delay");
|
PropertyField(prop, "m_Delay");
|
||||||
PropertyField(prop, "m_Duration");
|
PropertyField(prop, "m_Duration");
|
||||||
|
PropertyField(prop, "m_Speed");
|
||||||
--EditorGUI.indentLevel;
|
--EditorGUI.indentLevel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -30,6 +31,7 @@ namespace XCharts.Editor
|
|||||||
{
|
{
|
||||||
++EditorGUI.indentLevel;
|
++EditorGUI.indentLevel;
|
||||||
PropertyField(prop, "m_Duration");
|
PropertyField(prop, "m_Duration");
|
||||||
|
PropertyField(prop, "m_Speed");
|
||||||
--EditorGUI.indentLevel;
|
--EditorGUI.indentLevel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -45,6 +47,7 @@ namespace XCharts.Editor
|
|||||||
{
|
{
|
||||||
++EditorGUI.indentLevel;
|
++EditorGUI.indentLevel;
|
||||||
PropertyField(prop, "m_Duration");
|
PropertyField(prop, "m_Duration");
|
||||||
|
PropertyField(prop, "m_Speed");
|
||||||
--EditorGUI.indentLevel;
|
--EditorGUI.indentLevel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ namespace XCharts.Runtime
|
|||||||
[SerializeField][Since("v3.8.0")] private bool m_Reverse = false;
|
[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_Delay = 0;
|
||||||
[SerializeField][Since("v3.8.0")] private float m_Duration = 1000;
|
[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();
|
public AnimationInfoContext context = new AnimationInfoContext();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -34,11 +35,15 @@ namespace XCharts.Runtime
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public float delay { get { return m_Delay; } set { m_Delay = value; } }
|
public float delay { get { return m_Delay; } set { m_Delay = value; } }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// the duration of animation.
|
/// the duration of animation. Default is used to calculate the speed of animation. It can also be specified by speed.
|
||||||
/// ||动画的时长。
|
/// ||动画的时长。默认用于计算动画的速度。也可以通过speed指定速度。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public float duration { get { return m_Duration; } set { m_Duration = value; } }
|
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>
|
/// <summary>
|
||||||
/// the callback function of animation start.
|
/// the callback function of animation start.
|
||||||
/// ||动画开始的回调。
|
/// ||动画开始的回调。
|
||||||
@@ -208,7 +213,7 @@ namespace XCharts.Runtime
|
|||||||
if (!context.start)
|
if (!context.start)
|
||||||
return false;
|
return false;
|
||||||
else
|
else
|
||||||
return (m_Delay > 0 && Time.time - context.startTime < m_Delay / 1000);
|
return m_Delay > 0 && Time.time - context.startTime < m_Delay / 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -285,8 +290,7 @@ namespace XCharts.Runtime
|
|||||||
{
|
{
|
||||||
if (!context.start || !context.init || context.pause) return;
|
if (!context.start || !context.init || context.pause) return;
|
||||||
if (IsInDelay()) return;
|
if (IsInDelay()) return;
|
||||||
var duration = GetCurrAnimationDuration();
|
var delta = GetDelta(total, m_UnscaledTime);
|
||||||
var delta = (float)(total / duration * (m_UnscaledTime ? Time.unscaledDeltaTime : Time.deltaTime));
|
|
||||||
if (reverse)
|
if (reverse)
|
||||||
{
|
{
|
||||||
context.currProgress -= delta;
|
context.currProgress -= delta;
|
||||||
@@ -330,8 +334,7 @@ namespace XCharts.Runtime
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var duration = GetCurrAnimationDuration(dataIndex);
|
var delta = GetDelta(destProgress - startProgress, m_UnscaledTime);
|
||||||
var delta = (destProgress - startProgress) / duration * (m_UnscaledTime ? Time.unscaledDeltaTime : Time.deltaTime);
|
|
||||||
currHig += delta;
|
currHig += delta;
|
||||||
if (reverse)
|
if (reverse)
|
||||||
{
|
{
|
||||||
@@ -362,8 +365,7 @@ namespace XCharts.Runtime
|
|||||||
if (IsInDelay())
|
if (IsInDelay())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var duration = GetCurrAnimationDuration();
|
var delta = GetDelta(dest, m_UnscaledTime);
|
||||||
var delta = dest / duration * (m_UnscaledTime ? Time.unscaledDeltaTime : Time.deltaTime);
|
|
||||||
if (reverse)
|
if (reverse)
|
||||||
{
|
{
|
||||||
context.sizeProgress -= delta;
|
context.sizeProgress -= delta;
|
||||||
@@ -377,6 +379,20 @@ namespace XCharts.Runtime
|
|||||||
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>
|
/// <summary>
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ namespace XCharts.Runtime
|
|||||||
public float sizeProgress;
|
public float sizeProgress;
|
||||||
public int currPointIndex;
|
public int currPointIndex;
|
||||||
public int destPointIndex;
|
public int destPointIndex;
|
||||||
|
public float currDuration;
|
||||||
public Vector3 currPoint;
|
public Vector3 currPoint;
|
||||||
public Vector3 destPoint;
|
public Vector3 destPoint;
|
||||||
public Dictionary<int, float> dataCurrProgress = new Dictionary<int, float>();
|
public Dictionary<int, float> dataCurrProgress = new Dictionary<int, float>();
|
||||||
|
|||||||
@@ -560,7 +560,7 @@ namespace XCharts.Runtime
|
|||||||
public float GetChangeDuration()
|
public float GetChangeDuration()
|
||||||
{
|
{
|
||||||
if (m_Enable && m_Change.enable)
|
if (m_Enable && m_Change.enable)
|
||||||
return m_Change.duration;
|
return m_Change.context.currDuration > 0 ? m_Change.context.currDuration : m_Change.duration;
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -568,7 +568,7 @@ namespace XCharts.Runtime
|
|||||||
public float GetAdditionDuration()
|
public float GetAdditionDuration()
|
||||||
{
|
{
|
||||||
if (m_Enable && m_Addition.enable)
|
if (m_Enable && m_Addition.enable)
|
||||||
return m_Addition.duration;
|
return m_Addition.context.currDuration > 0 ? m_Addition.context.currDuration : m_Addition.duration;
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -576,7 +576,7 @@ namespace XCharts.Runtime
|
|||||||
public float GetInteractionDuration()
|
public float GetInteractionDuration()
|
||||||
{
|
{
|
||||||
if (m_Enable && m_Interaction.enable)
|
if (m_Enable && m_Interaction.enable)
|
||||||
return m_Interaction.duration;
|
return m_Interaction.context.currDuration > 0 ? m_Interaction.context.currDuration : m_Interaction.duration;
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user