Skip to content

Commit

Permalink
feat: fix and add features for UIEffectTweener component
Browse files Browse the repository at this point in the history
  • Loading branch information
mob-sakai committed Dec 10, 2024
1 parent 4e1ba53 commit e2d2a84
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 97 deletions.
89 changes: 31 additions & 58 deletions Packages/src/Editor/UIEffectTweenerEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ namespace Coffee.UIEffects.Editors
{
[CanEditMultipleObjects]
[CustomEditor(typeof(UIEffectTweener))]
internal class UIMaterialPropertyTweenerEditor : Editor
internal class UIEffectTweenerEditor : Editor
{
private SerializedProperty _cullingMask;
private SerializedProperty _direction;
private SerializedProperty _curve;
private SerializedProperty _delay;
private SerializedProperty _duration;
private SerializedProperty _interval;
private SerializedProperty _restartOnEnable;
private SerializedProperty _resetTimeOnEnable;
private SerializedProperty _updateMode;
private SerializedProperty _wrapMode;
private SerializedProperty _startMode;
Expand All @@ -24,7 +24,7 @@ private void OnEnable()
_cullingMask = serializedObject.FindProperty("m_CullingMask");
_direction = serializedObject.FindProperty("m_Direction");
_curve = serializedObject.FindProperty("m_Curve");
_restartOnEnable = serializedObject.FindProperty("m_RestartOnEnable");
_resetTimeOnEnable = serializedObject.FindProperty("m_ResetTimeOnEnable");
_delay = serializedObject.FindProperty("m_Delay");
_duration = serializedObject.FindProperty("m_Duration");
_interval = serializedObject.FindProperty("m_Interval");
Expand All @@ -35,15 +35,15 @@ private void OnEnable()

public override void OnInspectorGUI()
{
Profiler.BeginSample("(MPI)[MPTweenerEditor] OnInspectorGUI");
Profiler.BeginSample("(UIE)[UIEffectTweener] OnInspectorGUI");
serializedObject.UpdateIfRequiredOrScript();
EditorGUILayout.PropertyField(_cullingMask);
EditorGUILayout.PropertyField(_direction);
EditorGUILayout.PropertyField(_curve);
EditorGUILayout.PropertyField(_delay);
EditorGUILayout.PropertyField(_duration);
EditorGUILayout.PropertyField(_interval);
EditorGUILayout.PropertyField(_restartOnEnable);
EditorGUILayout.PropertyField(_resetTimeOnEnable);
EditorGUILayout.PropertyField(_wrapMode);
EditorGUILayout.PropertyField(_updateMode);
EditorGUILayout.PropertyField(_startMode);
Expand All @@ -58,68 +58,50 @@ private void DrawPlayer(UIEffectTweener tweener)

EditorGUILayout.BeginHorizontal();
EditorGUI.BeginDisabledGroup(!Application.isPlaying);
var icon = EditorGUIUtility.IconContent("icons/playbutton.png");
var r = EditorGUILayout.GetControlRect(false);
var rPlayButton = new Rect(r.x, r.y, 20, r.height);
if (GUI.Button(rPlayButton, EditorGUIUtility.IconContent("playbutton"), "IconButton"))
{
tweener.Play(false);
}

var rButton = new Rect(r.x, r.y, 20, r.height);
if (GUI.Button(rButton, icon, "IconButton"))
var rPauseButton = new Rect(r.x + 20, r.y, 20, r.height);
if (GUI.Button(rPauseButton, EditorGUIUtility.IconContent("pausebutton"), "IconButton"))
{
tweener.SetTime(0);
tweener.SetPause(!tweener.isPaused);
}

EditorGUI.EndDisabledGroup();

var totalTime = tweener.totalTime;
var time = tweener.time;
var label = EditorGUIUtility.TrTempContent($"{time:N2}/{totalTime:N2}");
var wLabel = Mathf.CeilToInt(EditorStyles.label.CalcSize(label).x / 5f) * 5f;
wLabel = 80;
var rLabel = new Rect(r.x + r.width - wLabel, r.y, wLabel, r.height);
var rLabel = new Rect(r.x + r.width - 80, r.y, 80, r.height);
GUI.Label(rLabel, label, "RightLabel");
EditorGUILayout.EndHorizontal();

EditorGUI.BeginChangeCheck();
var rSlider = new Rect(r.x + 20, r.y, r.width - wLabel - 20, r.height);

//
var rSlider = new Rect(r.x + 40, r.y, r.width - 120, r.height);
var r0 = new Rect(rSlider.x, rSlider.y + 4, rSlider.width, rSlider.height - 8);
r0.x += DrawBackground(r0, rSlider.width * tweener.delay / totalTime, Color.blue);
r0.x += DrawBackground(r0, rSlider.width * tweener.duration / totalTime, Color.green);

var
r0 = rSlider; //new Rect(rSlider.x, rSlider.y, rSlider.width * tweener.interval / totalTime, rSlider.height);
r0.y += 4;
r0.height -= 8;
r0.width = rSlider.width * tweener.delay / totalTime;
GUI.color = Color.blue;
GUI.Label(r0, GUIContent.none, "TE DefaultTime");

r0.x += r0.width;
r0.width = rSlider.width * tweener.duration / totalTime;
GUI.color = Color.green;
GUI.Label(r0, GUIContent.none, "TE DefaultTime");

r0.x += r0.width;
r0.width = rSlider.width * tweener.interval / totalTime;
GUI.color = Color.red;
GUI.Label(r0, GUIContent.none, "TE DefaultTime");
if (UIEffectTweener.WrapMode.Loop <= tweener.wrapMode)
{
r0.x += DrawBackground(r0, rSlider.width * tweener.interval / totalTime, Color.red);
}

if (UIEffectTweener.WrapMode.PingPongOnce <= tweener.wrapMode)
{
r0.x += r0.width;
r0.width = rSlider.width * tweener.duration / totalTime;
GUI.color = Color.green;
GUI.Label(r0, GUIContent.none, "TE DefaultTime");
r0.x += DrawBackground(r0, rSlider.width * tweener.duration / totalTime, Color.green);
}

if (UIEffectTweener.WrapMode.PingPongLoop <= tweener.wrapMode)
{
r0.x += r0.width;
r0.width = rSlider.width * tweener.interval / totalTime;
GUI.color = Color.red;
GUI.Label(r0, GUIContent.none, "TE DefaultTime");
r0.x += DrawBackground(r0, rSlider.width * tweener.interval / totalTime, Color.red);
}


GUI.color = Color.white;

time = GUI.HorizontalSlider(rSlider, time, 0, totalTime);
if (EditorGUI.EndChangeCheck())
{
Expand All @@ -132,21 +114,12 @@ private void DrawPlayer(UIEffectTweener tweener)
}
}

// private static void PostAddElement(SerializedProperty prop, string propertyName)
// {
// prop.FindPropertyRelative("m_From.m_Type").intValue = -1;
// prop.FindPropertyRelative("m_From.m_PropertyName").stringValue = propertyName;
// prop.FindPropertyRelative("m_To.m_Type").intValue = -1;
// prop.FindPropertyRelative("m_To.m_PropertyName").stringValue = propertyName;
// }
//
// private void ResetCallback()
// {
// var current = serializedObject.targetObject as UIEffectTweener;
// if (!current) return;
//
// Undo.RecordObject(current, "Reset Values");
// current.ResetPropertiesToDefault();
// }
private static float DrawBackground(Rect r, float width, Color color)
{
r.width = width;
GUI.color = color;
GUI.Label(r, GUIContent.none, "TE DefaultTime");
return width;
}
}
}
Loading

0 comments on commit e2d2a84

Please sign in to comment.