Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add option to not automatically plays tweener effect #280

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Packages/src/Editor/UIEffectTweenerEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ internal class UIMaterialPropertyTweenerEditor : Editor
private SerializedProperty _restartOnEnable;
private SerializedProperty _updateMode;
private SerializedProperty _wrapMode;
private SerializedProperty _startMode;

private void OnEnable()
{
Expand All @@ -29,6 +30,7 @@ private void OnEnable()
_interval = serializedObject.FindProperty("m_Interval");
_wrapMode = serializedObject.FindProperty("m_WrapMode");
_updateMode = serializedObject.FindProperty("m_UpdateMode");
_startMode = serializedObject.FindProperty("m_StartMode");
}

public override void OnInspectorGUI()
Expand All @@ -44,6 +46,7 @@ public override void OnInspectorGUI()
EditorGUILayout.PropertyField(_restartOnEnable);
EditorGUILayout.PropertyField(_wrapMode);
EditorGUILayout.PropertyField(_updateMode);
EditorGUILayout.PropertyField(_startMode);
serializedObject.ApplyModifiedProperties();
DrawPlayer(target as UIEffectTweener);
Profiler.EndSample();
Expand Down
48 changes: 41 additions & 7 deletions Packages/src/Runtime/UIEffectTweener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ public enum UpdateMode
Manual
}

public enum StartMode
{
Automatic,
Manual
}

public enum WrapMode
{
Once,
Expand Down Expand Up @@ -83,6 +89,13 @@ public enum Direction
[SerializeField]
private UpdateMode m_UpdateMode = UpdateMode.Normal;

[Tooltip("Specifies how the effect tweener will start.\n" +
" Automatic: Plays the tween automatically when it starts.\n" +
" Manual: Waits for the first `Play()` call to start.")]
[SerializeField]
private StartMode m_StartMode = StartMode.Automatic;

public bool _isAwaitingStart;
private float _rate;
private float _time;
private UIEffectBase _target;
Expand Down Expand Up @@ -208,23 +221,32 @@ public UpdateMode updateMode
set => m_UpdateMode = value;
}

public StartMode startMode
{
get => m_StartMode;
set => m_StartMode = value;
}

public AnimationCurve curve
{
get => m_Curve;
set => m_Curve = value;
}

private void Awake()
{
_isAwaitingStart = m_StartMode == StartMode.Manual;
}

private void Update()
{
switch (m_UpdateMode)
if (m_StartMode == StartMode.Manual && _isAwaitingStart)
{
case UpdateMode.Normal:
UpdateTime(Time.deltaTime);
break;
case UpdateMode.Unscaled:
UpdateTime(Time.unscaledDeltaTime);
break;
return;
}

float deltaTime = m_UpdateMode == UpdateMode.Unscaled ? Time.unscaledDeltaTime : Time.deltaTime;
UpdateTime(deltaTime);
}

private void OnEnable()
Expand All @@ -235,6 +257,18 @@ private void OnEnable()
}
}

public void Play()
{
_isAwaitingStart = false;
Restart();
}

public void Stop()
{
_isAwaitingStart = true;
Restart();
}

public void Restart()
{
SetTime(0);
Expand Down
Loading