Skip to content

Commit

Permalink
feat: add PlayOnEnable option to UIEffectTweener
Browse files Browse the repository at this point in the history
  • Loading branch information
mob-sakai committed Dec 14, 2024
1 parent 86e4c4f commit 9a75280
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 29 deletions.
9 changes: 3 additions & 6 deletions Packages/src/Editor/UIEffectTweenerEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,21 @@ internal class UIMaterialPropertyTweenerEditor : Editor
private SerializedProperty _delay;
private SerializedProperty _duration;
private SerializedProperty _interval;
private SerializedProperty _restartOnEnable;
private SerializedProperty _playOnEnable;
private SerializedProperty _updateMode;
private SerializedProperty _wrapMode;
private SerializedProperty _startMode;

private void OnEnable()
{
_cullingMask = serializedObject.FindProperty("m_CullingMask");
_direction = serializedObject.FindProperty("m_Direction");
_curve = serializedObject.FindProperty("m_Curve");
_restartOnEnable = serializedObject.FindProperty("m_RestartOnEnable");
_playOnEnable = serializedObject.FindProperty("m_PlayOnEnable");
_delay = serializedObject.FindProperty("m_Delay");
_duration = serializedObject.FindProperty("m_Duration");
_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 @@ -43,10 +41,9 @@ public override void OnInspectorGUI()
EditorGUILayout.PropertyField(_delay);
EditorGUILayout.PropertyField(_duration);
EditorGUILayout.PropertyField(_interval);
EditorGUILayout.PropertyField(_restartOnEnable);
EditorGUILayout.PropertyField(_playOnEnable);
EditorGUILayout.PropertyField(_wrapMode);
EditorGUILayout.PropertyField(_updateMode);
EditorGUILayout.PropertyField(_startMode);
serializedObject.ApplyModifiedProperties();
DrawPlayer(target as UIEffectTweener);
Profiler.EndSample();
Expand Down
42 changes: 19 additions & 23 deletions Packages/src/Runtime/UIEffectTweener.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using UnityEngine;
using UnityEngine.Serialization;

namespace Coffee.UIEffects
{
Expand All @@ -23,12 +24,6 @@ public enum UpdateMode
Manual
}

public enum StartMode
{
Automatic,
Manual
}

public enum WrapMode
{
Once,
Expand Down Expand Up @@ -70,9 +65,10 @@ public enum Direction
[Range(0f, 10)]
private float m_Interval;

[Tooltip("Whether to restart the tween when enabled.")]
[FormerlySerializedAs("m_ResetTimeOnEnable")]
[Tooltip("Play the tween when the component is enabled.")]
[SerializeField]
private bool m_RestartOnEnable = true;
private bool m_PlayOnEnable = true;

[Tooltip("The wrap mode of the tween.\n" +
" Clamp: Clamp the tween value (not loop).\n" +
Expand All @@ -89,13 +85,6 @@ 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 bool _isPaused;
private float _rate = -1;
private float _time;
Expand Down Expand Up @@ -197,10 +186,18 @@ public float totalTime
}
}

public bool playOnEnable
{
get => m_PlayOnEnable;
set => m_PlayOnEnable = value;
}

[Obsolete(
"UIEffectTweener.restartOnEnable has been deprecated. Use UIEffectTweener.playOnEnable instead (UnityUpgradable) -> playOnEnable")]
public bool restartOnEnable
{
get => m_RestartOnEnable;
set => m_RestartOnEnable = value;
get => m_PlayOnEnable;
set => m_PlayOnEnable = value;
}

public WrapMode wrapMode
Expand All @@ -215,12 +212,6 @@ public UpdateMode updateMode
set => m_UpdateMode = value;
}

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

public AnimationCurve curve
{
get => m_Curve;
Expand All @@ -247,7 +238,12 @@ public bool isTweening
private void OnEnable()
{
_isPaused = true;

#if UNITY_EDITOR
if (Application.isPlaying && playOnEnable)
#else
if (playOnEnable)
#endif
{
Play();
}
Expand Down

0 comments on commit 9a75280

Please sign in to comment.