feat: add PlayOnEnable option for UIEffectTweener

This commit is contained in:
mob-sakai
2024-12-11 16:34:56 +09:00
parent 54825eedc8
commit 155873669d
2 changed files with 39 additions and 31 deletions
+3 -6
View File
@@ -14,23 +14,21 @@ namespace Coffee.UIEffects.Editors
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 @@ namespace Coffee.UIEffects.Editors
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();
+36 -25
View File
@@ -1,5 +1,6 @@
using System;
using UnityEngine;
using UnityEngine.Serialization;
namespace Coffee.UIEffects
{
@@ -23,12 +24,6 @@ namespace Coffee.UIEffects
Manual
}
public enum StartMode
{
Automatic,
Manual
}
public enum WrapMode
{
Once,
@@ -43,6 +38,14 @@ namespace Coffee.UIEffects
Reverse
}
public enum PlayOnEnable
{
None,
Forward,
Reverse,
KeepDirection
}
[Tooltip("The culling mask of the tween.")]
[SerializeField]
private CullingMask m_CullingMask = (CullingMask)(-1);
@@ -70,9 +73,10 @@ namespace Coffee.UIEffects
[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 PlayOnEnable m_PlayOnEnable = PlayOnEnable.Forward;
[Tooltip("The wrap mode of the tween.\n" +
" Clamp: Clamp the tween value (not loop).\n" +
@@ -89,13 +93,6 @@ namespace Coffee.UIEffects
[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 +194,17 @@ namespace Coffee.UIEffects
}
}
public PlayOnEnable playOnEnable
{
get => m_PlayOnEnable;
set => m_PlayOnEnable = value;
}
[Obsolete("UIEffectTweener.restartOnEnable has been deprecated. Use UIEffectTweener.playOnEnable instead")]
public bool restartOnEnable
{
get => m_RestartOnEnable;
set => m_RestartOnEnable = value;
get => m_PlayOnEnable != PlayOnEnable.Forward;
set => m_PlayOnEnable = value ? PlayOnEnable.None : PlayOnEnable.Forward;
}
public WrapMode wrapMode
@@ -215,12 +219,6 @@ namespace Coffee.UIEffects
set => m_UpdateMode = value;
}
public StartMode startMode
{
get => m_StartMode;
set => m_StartMode = value;
}
public AnimationCurve curve
{
get => m_Curve;
@@ -247,9 +245,22 @@ namespace Coffee.UIEffects
private void OnEnable()
{
_isPaused = true;
if (playOnEnable)
#if UNITY_EDITOR
if (!Application.isPlaying) return;
#endif
switch (playOnEnable)
{
Play();
case PlayOnEnable.KeepDirection:
Play();
break;
case PlayOnEnable.Forward:
PlayForward();
break;
case PlayOnEnable.Reverse:
PlayReverse();
break;
}
}