From 9a752803748dc56fff9b83792f67c97bd7656510 Mon Sep 17 00:00:00 2001 From: mob-sakai <12690315+mob-sakai@users.noreply.github.com> Date: Wed, 11 Dec 2024 16:34:56 +0900 Subject: [PATCH] feat: add `PlayOnEnable` option to UIEffectTweener --- Packages/src/Editor/UIEffectTweenerEditor.cs | 9 ++--- Packages/src/Runtime/UIEffectTweener.cs | 42 +++++++++----------- 2 files changed, 22 insertions(+), 29 deletions(-) diff --git a/Packages/src/Editor/UIEffectTweenerEditor.cs b/Packages/src/Editor/UIEffectTweenerEditor.cs index 5adf8d07..c12f8c1e 100644 --- a/Packages/src/Editor/UIEffectTweenerEditor.cs +++ b/Packages/src/Editor/UIEffectTweenerEditor.cs @@ -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() @@ -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(); diff --git a/Packages/src/Runtime/UIEffectTweener.cs b/Packages/src/Runtime/UIEffectTweener.cs index 1f0a6949..16e4549d 100644 --- a/Packages/src/Runtime/UIEffectTweener.cs +++ b/Packages/src/Runtime/UIEffectTweener.cs @@ -1,5 +1,6 @@ using System; using UnityEngine; +using UnityEngine.Serialization; namespace Coffee.UIEffects { @@ -23,12 +24,6 @@ public enum UpdateMode Manual } - public enum StartMode - { - Automatic, - Manual - } - public enum WrapMode { Once, @@ -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" + @@ -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; @@ -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 @@ -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; @@ -247,7 +238,12 @@ public bool isTweening private void OnEnable() { _isPaused = true; + +#if UNITY_EDITOR + if (Application.isPlaying && playOnEnable) +#else if (playOnEnable) +#endif { Play(); }