Skip to content

Commit e2c1605

Browse files
committed
feat: add UIEffectTweener component
`UIEffectTweener` component animates `UIEffect` intensity or rate, enabling easy control over effect animations without the need for an `AnimationClip`.
1 parent 3bdc61c commit e2c1605

File tree

4 files changed

+452
-0
lines changed

4 files changed

+452
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
using UnityEngine.Profiling;
4+
5+
namespace Coffee.UIEffects.Editors
6+
{
7+
[CanEditMultipleObjects]
8+
[CustomEditor(typeof(UIEffectTweener))]
9+
internal class UIMaterialPropertyTweenerEditor : Editor
10+
{
11+
private SerializedProperty _cullingMask;
12+
private SerializedProperty _direction;
13+
private SerializedProperty _curve;
14+
private SerializedProperty _delay;
15+
private SerializedProperty _duration;
16+
private SerializedProperty _interval;
17+
private SerializedProperty _restartOnEnable;
18+
private SerializedProperty _updateMode;
19+
private SerializedProperty _wrapMode;
20+
21+
private void OnEnable()
22+
{
23+
_cullingMask = serializedObject.FindProperty("m_CullingMask");
24+
_direction = serializedObject.FindProperty("m_Direction");
25+
_curve = serializedObject.FindProperty("m_Curve");
26+
_restartOnEnable = serializedObject.FindProperty("m_RestartOnEnable");
27+
_delay = serializedObject.FindProperty("m_Delay");
28+
_duration = serializedObject.FindProperty("m_Duration");
29+
_interval = serializedObject.FindProperty("m_Interval");
30+
_wrapMode = serializedObject.FindProperty("m_WrapMode");
31+
_updateMode = serializedObject.FindProperty("m_UpdateMode");
32+
}
33+
34+
public override void OnInspectorGUI()
35+
{
36+
Profiler.BeginSample("(MPI)[MPTweenerEditor] OnInspectorGUI");
37+
serializedObject.UpdateIfRequiredOrScript();
38+
EditorGUILayout.PropertyField(_cullingMask);
39+
EditorGUILayout.PropertyField(_direction);
40+
EditorGUILayout.PropertyField(_curve);
41+
EditorGUILayout.PropertyField(_delay);
42+
EditorGUILayout.PropertyField(_duration);
43+
EditorGUILayout.PropertyField(_interval);
44+
EditorGUILayout.PropertyField(_restartOnEnable);
45+
EditorGUILayout.PropertyField(_wrapMode);
46+
EditorGUILayout.PropertyField(_updateMode);
47+
serializedObject.ApplyModifiedProperties();
48+
DrawPlayer(target as UIEffectTweener);
49+
Profiler.EndSample();
50+
}
51+
52+
private void DrawPlayer(UIEffectTweener tweener)
53+
{
54+
if (!tweener) return;
55+
56+
EditorGUILayout.BeginHorizontal();
57+
EditorGUI.BeginDisabledGroup(!Application.isPlaying);
58+
var icon = EditorGUIUtility.IconContent("icons/playbutton.png");
59+
var r = EditorGUILayout.GetControlRect(false);
60+
61+
var rButton = new Rect(r.x, r.y, 20, r.height);
62+
if (GUI.Button(rButton, icon, "IconButton"))
63+
{
64+
tweener.SetTime(0);
65+
}
66+
67+
EditorGUI.EndDisabledGroup();
68+
69+
var totalTime = tweener.totalTime;
70+
var time = tweener.time;
71+
var label = EditorGUIUtility.TrTempContent($"{time:N2}/{totalTime:N2}");
72+
var wLabel = Mathf.CeilToInt(EditorStyles.label.CalcSize(label).x / 5f) * 5f;
73+
wLabel = 80;
74+
var rLabel = new Rect(r.x + r.width - wLabel, r.y, wLabel, r.height);
75+
GUI.Label(rLabel, label, "RightLabel");
76+
EditorGUILayout.EndHorizontal();
77+
78+
EditorGUI.BeginChangeCheck();
79+
var rSlider = new Rect(r.x + 20, r.y, r.width - wLabel - 20, r.height);
80+
81+
//
82+
83+
var
84+
r0 = rSlider; //new Rect(rSlider.x, rSlider.y, rSlider.width * tweener.interval / totalTime, rSlider.height);
85+
r0.y += 4;
86+
r0.height -= 8;
87+
r0.width = rSlider.width * tweener.delay / totalTime;
88+
GUI.color = Color.blue;
89+
GUI.Label(r0, GUIContent.none, "TE DefaultTime");
90+
91+
r0.x += r0.width;
92+
r0.width = rSlider.width * tweener.duration / totalTime;
93+
GUI.color = Color.green;
94+
GUI.Label(r0, GUIContent.none, "TE DefaultTime");
95+
96+
r0.x += r0.width;
97+
r0.width = rSlider.width * tweener.interval / totalTime;
98+
GUI.color = Color.red;
99+
GUI.Label(r0, GUIContent.none, "TE DefaultTime");
100+
101+
if (UIEffectTweener.WrapMode.PingPongOnce <= tweener.wrapMode)
102+
{
103+
r0.x += r0.width;
104+
r0.width = rSlider.width * tweener.duration / totalTime;
105+
GUI.color = Color.green;
106+
GUI.Label(r0, GUIContent.none, "TE DefaultTime");
107+
}
108+
109+
if (UIEffectTweener.WrapMode.PingPongLoop <= tweener.wrapMode)
110+
{
111+
r0.x += r0.width;
112+
r0.width = rSlider.width * tweener.interval / totalTime;
113+
GUI.color = Color.red;
114+
GUI.Label(r0, GUIContent.none, "TE DefaultTime");
115+
}
116+
117+
118+
GUI.color = Color.white;
119+
120+
time = GUI.HorizontalSlider(rSlider, time, 0, totalTime);
121+
if (EditorGUI.EndChangeCheck())
122+
{
123+
tweener.SetTime(time);
124+
}
125+
126+
if (Application.isPlaying && tweener.isActiveAndEnabled)
127+
{
128+
Repaint();
129+
}
130+
}
131+
132+
// private static void PostAddElement(SerializedProperty prop, string propertyName)
133+
// {
134+
// prop.FindPropertyRelative("m_From.m_Type").intValue = -1;
135+
// prop.FindPropertyRelative("m_From.m_PropertyName").stringValue = propertyName;
136+
// prop.FindPropertyRelative("m_To.m_Type").intValue = -1;
137+
// prop.FindPropertyRelative("m_To.m_PropertyName").stringValue = propertyName;
138+
// }
139+
//
140+
// private void ResetCallback()
141+
// {
142+
// var current = serializedObject.targetObject as UIEffectTweener;
143+
// if (!current) return;
144+
//
145+
// Undo.RecordObject(current, "Reset Values");
146+
// current.ResetPropertiesToDefault();
147+
// }
148+
}
149+
}

Packages/src/Editor/UIEffectTweenerEditor.cs.meta

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)