mirror of
https://github.com/BlackMATov/unity-flash-tools.git
synced 2025-12-15 04:25:27 +07:00
unscaled delta time support
This commit is contained in:
@@ -26,6 +26,12 @@ namespace FTEditor.Editors {
|
||||
|
||||
void DrawControls() {
|
||||
SwfEditorUtils.DoRightHorizontalGUI(() => {
|
||||
if ( _manager.useUnscaledDt && GUILayout.Button("Use Scaled Dt") ) {
|
||||
_manager.useUnscaledDt = false;
|
||||
}
|
||||
if ( !_manager.useUnscaledDt && GUILayout.Button("Use Unscaled Dt") ) {
|
||||
_manager.useUnscaledDt = true;
|
||||
}
|
||||
if ( _manager.isPaused && GUILayout.Button("Resume") ) {
|
||||
_manager.Resume();
|
||||
}
|
||||
@@ -44,11 +50,21 @@ namespace FTEditor.Editors {
|
||||
SwfEditorUtils.DoWithEnabledGUI(false, () => {
|
||||
EditorGUILayout.TextField("Name", group_name);
|
||||
});
|
||||
EditorGUI.BeginChangeCheck();
|
||||
var new_rate_scale = EditorGUILayout.FloatField(
|
||||
"Rate Scale", _manager.GetGroupRateScale(group_name));
|
||||
if ( EditorGUI.EndChangeCheck() ) {
|
||||
_manager.SetGroupRateScale(group_name, new_rate_scale);
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
var new_rate_scale = EditorGUILayout.FloatField(
|
||||
"Rate Scale", _manager.GetGroupRateScale(group_name));
|
||||
if ( EditorGUI.EndChangeCheck() ) {
|
||||
_manager.SetGroupRateScale(group_name, new_rate_scale);
|
||||
}
|
||||
}
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
var new_user_unscaled_dt = EditorGUILayout.Toggle(
|
||||
"Use Unscaled Dt", _manager.IsGroupUseUnscaledDt(group_name));
|
||||
if ( EditorGUI.EndChangeCheck() ) {
|
||||
_manager.SetGroupUseUnscaledDt(group_name, new_user_unscaled_dt);
|
||||
}
|
||||
}
|
||||
SwfEditorUtils.DoRightHorizontalGUI(() => {
|
||||
if ( _manager.IsGroupPaused(group_name) && GUILayout.Button("Resume") ) {
|
||||
|
||||
@@ -40,6 +40,9 @@ namespace FTRuntime {
|
||||
[SerializeField]
|
||||
bool _autoPlay = true;
|
||||
|
||||
[SerializeField]
|
||||
bool _useUnscaledDt = false;
|
||||
|
||||
[SerializeField, SwfFloatRange(0.0f, float.MaxValue)]
|
||||
float _rateScale = 1.0f;
|
||||
|
||||
@@ -95,6 +98,15 @@ namespace FTRuntime {
|
||||
set { _autoPlay = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether controller uses unscaled delta time
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if uses unscaled delta time; otherwise, <c>false</c></value>
|
||||
public bool useUnscaledDt {
|
||||
get { return _useUnscaledDt; }
|
||||
set { _useUnscaledDt = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the controller rate scale
|
||||
/// </summary>
|
||||
@@ -296,9 +308,9 @@ namespace FTRuntime {
|
||||
//
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
internal void Internal_Update(float dt) {
|
||||
internal void Internal_Update(float scaled_dt, float unscaled_dt) {
|
||||
if ( isPlaying ) {
|
||||
_tickTimer += dt;
|
||||
_tickTimer += useUnscaledDt ? unscaled_dt : scaled_dt;
|
||||
do {
|
||||
var frame_rate = clip ? clip.frameRate * rateScale : 0.0f;
|
||||
var frame_time = frame_rate > 0.0f ? 1.0f / frame_rate : 0.0f;
|
||||
|
||||
@@ -10,8 +10,10 @@ namespace FTRuntime {
|
||||
SwfList<SwfClipController> _safeUpdates = new SwfList<SwfClipController>();
|
||||
|
||||
bool _isPaused = false;
|
||||
bool _useUnscaledDt = false;
|
||||
float _rateScale = 1.0f;
|
||||
HashSet<string> _groupPauses = new HashSet<string>();
|
||||
HashSet<string> _groupUnscales = new HashSet<string>();
|
||||
Dictionary<string, float> _groupRateScales = new Dictionary<string, float>();
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
@@ -78,6 +80,15 @@ namespace FTRuntime {
|
||||
set { _isPaused = !value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get or set a value indicating whether animation updates uses unscaled delta time
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if uses unscaled delta time; otherwise, <c>false</c></value>
|
||||
public bool useUnscaledDt {
|
||||
get { return _useUnscaledDt; }
|
||||
set { _useUnscaledDt = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get or set the global animation rate scale
|
||||
/// </summary>
|
||||
@@ -146,6 +157,30 @@ namespace FTRuntime {
|
||||
return !IsGroupPaused(group_name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the group of animations use unscaled delta time
|
||||
/// </summary>
|
||||
/// <param name="group_name">Group name</param>
|
||||
/// <param name="yesno"><c>true</c> if group will use unscaled delta time; otherwise, <c>false</c></param>
|
||||
public void SetGroupUseUnscaledDt(string group_name, bool yesno) {
|
||||
if ( !string.IsNullOrEmpty(group_name) ) {
|
||||
if ( yesno ) {
|
||||
_groupUnscales.Add(group_name);
|
||||
} else {
|
||||
_groupUnscales.Remove(group_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether group of animations uses unscaled delta time
|
||||
/// </summary>
|
||||
/// <returns><c>true</c> if group uses unscaled delta time; otherwise, <c>false</c></returns>
|
||||
/// <param name="group_name">Group name</param>
|
||||
public bool IsGroupUseUnscaledDt(string group_name) {
|
||||
return _groupUnscales.Contains(group_name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the group of animations rate scale
|
||||
/// </summary>
|
||||
@@ -232,17 +267,19 @@ namespace FTRuntime {
|
||||
}
|
||||
}
|
||||
|
||||
void LateUpdateControllers(float dt) {
|
||||
void LateUpdateControllers(float scaled_dt, float unscaled_dt) {
|
||||
_controllers.AssignTo(_safeUpdates);
|
||||
for ( int i = 0, e = _safeUpdates.Count; i < e; ++i ) {
|
||||
var ctrl = _safeUpdates[i];
|
||||
if ( ctrl ) {
|
||||
var group_name = ctrl.groupName;
|
||||
var group_name = ctrl.groupName;
|
||||
if ( string.IsNullOrEmpty(group_name) ) {
|
||||
ctrl.Internal_Update(dt);
|
||||
ctrl.Internal_Update(scaled_dt, unscaled_dt);
|
||||
} else if ( IsGroupPlaying(group_name) ) {
|
||||
var group_rate_scale = GetGroupRateScale(group_name);
|
||||
ctrl.Internal_Update(group_rate_scale * dt);
|
||||
ctrl.Internal_Update(
|
||||
group_rate_scale * (IsGroupUseUnscaledDt(group_name) ? unscaled_dt : scaled_dt),
|
||||
group_rate_scale * unscaled_dt);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -267,8 +304,9 @@ namespace FTRuntime {
|
||||
|
||||
void LateUpdate() {
|
||||
if ( isPlaying ) {
|
||||
var dt = Time.deltaTime;
|
||||
LateUpdateControllers(rateScale * dt);
|
||||
LateUpdateControllers(
|
||||
rateScale * (useUnscaledDt ? Time.unscaledDeltaTime : Time.deltaTime),
|
||||
rateScale * Time.unscaledDeltaTime);
|
||||
}
|
||||
LateUpdateClips();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user