feat: add ResetOnEnable option for UIEffectTweener

#299
This commit is contained in:
mob-sakai
2025-01-23 16:27:58 +09:00
parent 7a765c32d8
commit e326bb7753
2 changed files with 36 additions and 13 deletions
@@ -16,6 +16,7 @@ namespace Coffee.UIEffects.Editors
private SerializedProperty _duration;
private SerializedProperty _interval;
private SerializedProperty _playOnEnable;
private SerializedProperty _resetTimeOnEnable;
private SerializedProperty _updateMode;
private SerializedProperty _wrapMode;
private SerializedProperty _onComplete;
@@ -28,6 +29,7 @@ namespace Coffee.UIEffects.Editors
_direction = serializedObject.FindProperty("m_Direction");
_curve = serializedObject.FindProperty("m_Curve");
_playOnEnable = serializedObject.FindProperty("m_PlayOnEnable");
_resetTimeOnEnable = serializedObject.FindProperty("m_ResetTimeOnEnable");
_delay = serializedObject.FindProperty("m_Delay");
_duration = serializedObject.FindProperty("m_Duration");
_interval = serializedObject.FindProperty("m_Interval");
@@ -54,6 +56,7 @@ namespace Coffee.UIEffects.Editors
EditorGUILayout.PropertyField(_duration);
EditorGUILayout.PropertyField(_interval);
EditorGUILayout.PropertyField(_playOnEnable);
EditorGUILayout.PropertyField(_resetTimeOnEnable);
EditorGUILayout.PropertyField(_wrapMode);
EditorGUILayout.PropertyField(_updateMode);
EditorGUILayout.PropertyField(_onComplete);
+33 -13
View File
@@ -81,6 +81,10 @@ namespace Coffee.UIEffects
[SerializeField]
private PlayOnEnable m_PlayOnEnable = PlayOnEnable.Forward;
[Tooltip("Reset the tweening time when the component is enabled.")]
[SerializeField]
private bool m_ResetTimeOnEnable = true;
[Tooltip("The wrap mode of the tween.\n" +
" Once: Clamp the tween value (not loop).\n" +
" Loop: Loop the tween value.\n" +
@@ -220,11 +224,13 @@ namespace Coffee.UIEffects
set => m_PlayOnEnable = value;
}
[Obsolete("UIEffectTweener.restartOnEnable has been deprecated. Use UIEffectTweener.playOnEnable instead")]
public bool restartOnEnable
/// <summary>
/// Reset the tweening time when the component is enabled..
/// </summary>
public bool resetTimeOnEnable
{
get => m_PlayOnEnable != PlayOnEnable.Forward;
set => m_PlayOnEnable = value ? PlayOnEnable.None : PlayOnEnable.Forward;
get => m_ResetTimeOnEnable;
set => m_ResetTimeOnEnable = value;
}
/// <summary>
@@ -303,13 +309,13 @@ namespace Coffee.UIEffects
switch (playOnEnable)
{
case PlayOnEnable.KeepDirection:
Play();
Play(resetTimeOnEnable);
break;
case PlayOnEnable.Forward:
PlayForward();
PlayForward(resetTimeOnEnable);
break;
case PlayOnEnable.Reverse:
PlayReverse();
PlayReverse(resetTimeOnEnable);
break;
}
}
@@ -339,6 +345,11 @@ namespace Coffee.UIEffects
ResetTime();
}
Play();
}
public void Play()
{
_isPaused = false;
if (!isTweening)
@@ -347,15 +358,14 @@ namespace Coffee.UIEffects
}
}
public void Play()
public void PlayForward(bool resetTime)
{
ResetTime();
_isPaused = false;
if (!isTweening)
if (resetTime)
{
m_OnComplete.Invoke();
ResetTime();
}
PlayForward();
}
public void PlayForward()
@@ -369,6 +379,16 @@ namespace Coffee.UIEffects
}
}
public void PlayReverse(bool resetTime)
{
if (resetTime)
{
ResetTime();
}
PlayReverse();
}
public void PlayReverse()
{
direction = Direction.Reverse;