1
- using UnityEditor ;
1
+ using System . Linq ;
2
+ using UnityEditor ;
2
3
using UnityEngine ;
3
4
using UnityEngine . Profiling ;
4
5
5
6
namespace Coffee . UIEffects . Editors
6
7
{
7
8
[ CanEditMultipleObjects ]
8
9
[ CustomEditor ( typeof ( UIEffectTweener ) ) ]
9
- internal class UIMaterialPropertyTweenerEditor : Editor
10
+ internal class UIEffectTweenerEditor : Editor
10
11
{
11
12
private SerializedProperty _cullingMask ;
12
13
private SerializedProperty _direction ;
@@ -17,6 +18,8 @@ internal class UIMaterialPropertyTweenerEditor : Editor
17
18
private SerializedProperty _playOnEnable ;
18
19
private SerializedProperty _updateMode ;
19
20
private SerializedProperty _wrapMode ;
21
+ private bool _isPlaying = false ;
22
+ private double _lastTime ;
20
23
21
24
private void OnEnable ( )
22
25
{
@@ -29,11 +32,18 @@ private void OnEnable()
29
32
_interval = serializedObject . FindProperty ( "m_Interval" ) ;
30
33
_wrapMode = serializedObject . FindProperty ( "m_WrapMode" ) ;
31
34
_updateMode = serializedObject . FindProperty ( "m_UpdateMode" ) ;
35
+
36
+ EditorApplication . update += UpdateTweeners ;
37
+ }
38
+
39
+ private void OnDisable ( )
40
+ {
41
+ EditorApplication . update -= UpdateTweeners ;
32
42
}
33
43
34
44
public override void OnInspectorGUI ( )
35
45
{
36
- Profiler . BeginSample ( "(MPI)[MPTweenerEditor ] OnInspectorGUI" ) ;
46
+ Profiler . BeginSample ( "(UIE)[UIEffectTweener ] OnInspectorGUI" ) ;
37
47
serializedObject . UpdateIfRequiredOrScript ( ) ;
38
48
EditorGUILayout . PropertyField ( _cullingMask ) ;
39
49
EditorGUILayout . PropertyField ( _direction ) ;
@@ -53,74 +63,62 @@ private void DrawPlayer(UIEffectTweener tweener)
53
63
{
54
64
if ( ! tweener ) return ;
55
65
66
+ EditorGUILayout . Space ( 4 ) ;
67
+ GUILayout . Label ( GUIContent . none , "sv_iconselector_sep" , GUILayout . ExpandWidth ( true ) ) ;
68
+
56
69
EditorGUILayout . BeginHorizontal ( ) ;
57
- EditorGUI . BeginDisabledGroup ( ! Application . isPlaying ) ;
58
- var icon = EditorGUIUtility . IconContent ( "icons/playbutton.png" ) ;
59
70
var r = EditorGUILayout . GetControlRect ( false ) ;
71
+ var rResetTimeButton = new Rect ( r . x , r . y , 20 , r . height ) ;
72
+ if ( GUI . Button ( rResetTimeButton , EditorGUIUtility . IconContent ( "animation.firstkey" ) , "IconButton" ) )
73
+ {
74
+ SetTime ( 0 ) ;
75
+ }
60
76
61
- var rButton = new Rect ( r . x , r . y , 20 , r . height ) ;
62
- if ( GUI . Button ( rButton , icon , "IconButton" ) )
77
+ var rPlayButton = new Rect ( r . x + 20 , r . y , 20 , r . height ) ;
78
+ if ( GUI . Button ( rPlayButton , EditorGUIUtility . IconContent ( "playbutton" ) , "IconButton" ) )
63
79
{
64
- tweener . SetTime ( 0 ) ;
80
+ SetPlaying ( true ) ;
65
81
}
66
82
67
- EditorGUI . EndDisabledGroup ( ) ;
83
+ var rPauseButton = new Rect ( r . x + 40 , r . y , 20 , r . height ) ;
84
+ if ( GUI . Button ( rPauseButton , EditorGUIUtility . IconContent ( "pausebutton" ) , "IconButton" ) )
85
+ {
86
+ SetPlaying ( false ) ;
87
+ }
68
88
69
89
var totalTime = tweener . totalTime ;
70
90
var time = tweener . time ;
71
91
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 ) ;
92
+ var rLabel = new Rect ( r . x + r . width - 80 , r . y , 80 , r . height ) ;
75
93
GUI . Label ( rLabel , label , "RightLabel" ) ;
76
94
EditorGUILayout . EndHorizontal ( ) ;
77
95
78
96
EditorGUI . BeginChangeCheck ( ) ;
79
- var rSlider = new Rect ( r . x + 20 , r . y , r . width - wLabel - 20 , r . height ) ;
80
-
81
- //
97
+ var rSlider = new Rect ( r . x + 60 , r . y , r . width - 140 , r . height ) ;
98
+ var r0 = new Rect ( rSlider . x , rSlider . y + 4 , rSlider . width , rSlider . height - 8 ) ;
99
+ r0 . x += DrawBackground ( r0 , rSlider . width * tweener . delay / totalTime , Color . blue ) ;
100
+ r0 . x += DrawBackground ( r0 , rSlider . width * tweener . duration / totalTime , Color . green ) ;
82
101
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" ) ;
102
+ if ( UIEffectTweener . WrapMode . Loop <= tweener . wrapMode )
103
+ {
104
+ r0 . x += DrawBackground ( r0 , rSlider . width * tweener . interval / totalTime , Color . red ) ;
105
+ }
100
106
101
107
if ( UIEffectTweener . WrapMode . PingPongOnce <= tweener . wrapMode )
102
108
{
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" ) ;
109
+ r0 . x += DrawBackground ( r0 , rSlider . width * tweener . duration / totalTime , Color . green ) ;
107
110
}
108
111
109
112
if ( UIEffectTweener . WrapMode . PingPongLoop <= tweener . wrapMode )
110
113
{
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" ) ;
114
+ r0 . x += DrawBackground ( r0 , rSlider . width * tweener . interval / totalTime , Color . red ) ;
115
115
}
116
116
117
-
118
117
GUI . color = Color . white ;
119
-
120
118
time = GUI . HorizontalSlider ( rSlider , time , 0 , totalTime ) ;
121
119
if ( EditorGUI . EndChangeCheck ( ) )
122
120
{
123
- tweener . SetTime ( time ) ;
121
+ SetTime ( time ) ;
124
122
}
125
123
126
124
if ( Application . isPlaying && tweener . isActiveAndEnabled )
@@ -129,21 +127,56 @@ private void DrawPlayer(UIEffectTweener tweener)
129
127
}
130
128
}
131
129
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
- // }
130
+ private static float DrawBackground ( Rect r , float width , Color color )
131
+ {
132
+ r . width = width ;
133
+ GUI . color = color ;
134
+ GUI . Label ( r , GUIContent . none , "TE DefaultTime" ) ;
135
+ return width ;
136
+ }
137
+
138
+ private void SetTime ( float time )
139
+ {
140
+ foreach ( var tweener in targets . OfType < UIEffectTweener > ( ) )
141
+ {
142
+ tweener . SetTime ( time ) ;
143
+ }
144
+ }
145
+
146
+ private void SetPlaying ( bool enable )
147
+ {
148
+ if ( ! EditorApplication . isPlaying )
149
+ {
150
+ _isPlaying = enable ;
151
+ _lastTime = EditorApplication . timeSinceStartup ;
152
+ return ;
153
+ }
154
+
155
+ foreach ( var tweener in targets . OfType < UIEffectTweener > ( ) )
156
+ {
157
+ if ( enable )
158
+ {
159
+ tweener . Play ( false ) ;
160
+ }
161
+ else
162
+ {
163
+ tweener . SetPause ( true ) ;
164
+ }
165
+ }
166
+ }
167
+
168
+ private void UpdateTweeners ( )
169
+ {
170
+ if ( ! _isPlaying || EditorApplication . isPlayingOrWillChangePlaymode ) return ;
171
+
172
+ var delta = ( float ) ( EditorApplication . timeSinceStartup - _lastTime ) ;
173
+ _lastTime = EditorApplication . timeSinceStartup ;
174
+ foreach ( var tweener in targets . OfType < UIEffectTweener > ( ) )
175
+ {
176
+ tweener . UpdateTime ( tweener . direction == UIEffectTweener . Direction . Forward ? delta : - delta ) ;
177
+ }
178
+
179
+ EditorApplication . QueuePlayerLoopUpdate ( ) ;
180
+ }
148
181
}
149
182
}
0 commit comments