1
- using System . Collections . Generic ;
2
1
using System . Runtime . CompilerServices ;
3
2
using Coffee . UIEffectInternal ;
4
3
using UnityEngine ;
5
4
using UnityEngine . EventSystems ;
6
5
using UnityEngine . Profiling ;
7
6
using UnityEngine . UI ;
8
7
using UnityEditor ;
9
- #if TMP_ENABLE
10
- using TMPro ;
11
- #endif
12
8
13
9
[ assembly: InternalsVisibleTo ( "UIEffect" ) ]
14
10
[ assembly: InternalsVisibleTo ( "Coffee.UIEffect.Editor" ) ]
@@ -19,9 +15,6 @@ namespace Coffee.UIEffects
19
15
[ DisallowMultipleComponent ]
20
16
public abstract class UIEffectBase : UIBehaviour , IMeshModifier , IMaterialModifier , ICanvasRaycastFilter
21
17
{
22
- private static readonly VertexHelper s_VertexHelper = new VertexHelper ( ) ;
23
- private static Mesh s_Mesh ;
24
-
25
18
private static readonly InternalObjectPool < UIEffectContext > s_ContextPool =
26
19
new InternalObjectPool < UIEffectContext > ( ( ) => new UIEffectContext ( ) , x => true , x => x . Reset ( ) ) ;
27
20
@@ -52,27 +45,13 @@ public virtual UIEffectContext context
52
45
53
46
protected override void OnEnable ( )
54
47
{
55
- #if TMP_ENABLE
56
- if ( graphic is TextMeshProUGUI )
57
- {
58
- _prevLossyScaleY = transform . lossyScale . y ;
59
- Canvas . willRenderCanvases += CheckSDFScaleForTMP ;
60
- UIExtraCallbacks . onScreenSizeChanged += SetVerticesDirtyForTMP ;
61
- }
62
- #endif
63
-
64
48
UpdateContext ( context ) ;
65
49
SetMaterialDirty ( ) ;
66
50
SetVerticesDirty ( ) ;
67
51
}
68
52
69
53
protected override void OnDisable ( )
70
54
{
71
- #if TMP_ENABLE
72
- Canvas . willRenderCanvases -= CheckSDFScaleForTMP ;
73
- UIExtraCallbacks . onScreenSizeChanged -= SetVerticesDirtyForTMP ;
74
- #endif
75
-
76
55
MaterialRepository . Release ( ref _material ) ;
77
56
SetMaterialDirty ( ) ;
78
57
SetVerticesDirty ( ) ;
@@ -159,24 +138,10 @@ protected override void OnDidApplyAnimationProperties()
159
138
160
139
public virtual void SetVerticesDirty ( )
161
140
{
162
- #if TMP_ENABLE
163
- if ( graphic is TextMeshProUGUI textMeshProUGUI && textMeshProUGUI . isActiveAndEnabled )
164
- {
165
- if ( isActiveAndEnabled )
166
- {
167
- OnTMPChanged ( textMeshProUGUI ) ;
168
- }
169
- else if ( 0 < textMeshProUGUI . textInfo ? . meshInfo ? . Length
170
- && 0 < textMeshProUGUI . textInfo . meshInfo [ 0 ] . vertexCount )
171
- {
172
- textMeshProUGUI . UpdateVertexData ( ) ;
173
- }
174
- }
175
- else
176
- #endif
177
141
if ( graphic )
178
142
{
179
143
graphic . SetVerticesDirty ( ) ;
144
+ GraphicProxy . Find ( graphic ) . SetVerticesDirty ( graphic ) ;
180
145
#if UNITY_EDITOR
181
146
EditorApplication . QueuePlayerLoopUpdate ( ) ;
182
147
#endif
@@ -211,122 +176,6 @@ public virtual void ApplyContextToMaterial()
211
176
#endif
212
177
}
213
178
214
- #if TMP_ENABLE
215
- #if UNITY_EDITOR
216
- [ InitializeOnLoadMethod ]
217
- #else
218
- [ RuntimeInitializeOnLoadMethod ( RuntimeInitializeLoadType . BeforeSceneLoad ) ]
219
- #endif
220
- private static void InitializeOnLoad ( )
221
- {
222
- TMPro_EventManager . TEXT_CHANGED_EVENT . Add ( obj =>
223
- {
224
- if ( obj is TextMeshProUGUI textMeshProUGUI )
225
- {
226
- OnTMPChanged ( textMeshProUGUI ) ;
227
- }
228
- } ) ;
229
- }
230
-
231
- private static void OnTMPChanged ( TextMeshProUGUI textMeshProUGUI )
232
- {
233
- if ( ! textMeshProUGUI . TryGetComponent < UIEffectBase > ( out var effect ) ) return ;
234
- if ( ! effect || ! effect . isActiveAndEnabled ) return ;
235
-
236
- if ( ! s_Mesh )
237
- {
238
- s_Mesh = new Mesh ( ) ;
239
- s_Mesh . MarkDynamic ( ) ;
240
- }
241
-
242
- var target = effect is UIEffect uiEffect
243
- ? uiEffect
244
- : effect is UIEffectReplica parentReplica
245
- ? parentReplica . target
246
- : null ;
247
- var subMeshes = InternalListPool < TMP_SubMeshUI > . Rent ( ) ;
248
- var modifiers = InternalListPool < IMeshModifier > . Rent ( ) ;
249
- textMeshProUGUI . GetComponentsInChildren ( subMeshes , 1 ) ;
250
- for ( var i = 0 ; i < textMeshProUGUI . textInfo . meshInfo . Length ; i ++ )
251
- {
252
- var meshInfo = textMeshProUGUI . textInfo . meshInfo [ i ] ;
253
- s_VertexHelper . Clear ( ) ;
254
- meshInfo . mesh . CopyTo ( s_VertexHelper , meshInfo . vertexCount , meshInfo . vertexCount * 6 / 4 ) ;
255
- if ( i == 0 )
256
- {
257
- textMeshProUGUI . GetComponents ( modifiers ) ;
258
- foreach ( var modifier in modifiers )
259
- {
260
- modifier . ModifyMesh ( s_VertexHelper ) ;
261
- }
262
-
263
- s_VertexHelper . FillMesh ( s_Mesh ) ;
264
- textMeshProUGUI . canvasRenderer . SetMesh ( s_Mesh ) ;
265
- }
266
- else if ( i - 1 < subMeshes . Count )
267
- {
268
- var subMeshUI = GetSubMeshUI ( subMeshes , meshInfo . material , i - 1 ) ;
269
- if ( ! target || ! subMeshUI ) break ;
270
-
271
- var replica = subMeshUI . GetOrAddComponent < UIEffectReplica > ( ) ;
272
- replica . target = target ;
273
-
274
- subMeshUI . GetComponents ( modifiers ) ;
275
- foreach ( var modifier in modifiers )
276
- {
277
- modifier . ModifyMesh ( s_VertexHelper ) ;
278
- }
279
-
280
- s_VertexHelper . FillMesh ( s_Mesh ) ;
281
- replica . ApplyContextToMaterial ( ) ;
282
- subMeshUI . canvasRenderer . SetMesh ( s_Mesh ) ;
283
- }
284
- else
285
- {
286
- break ;
287
- }
288
- }
289
-
290
- InternalListPool < IMeshModifier > . Return ( ref modifiers ) ;
291
- InternalListPool < TMP_SubMeshUI > . Return ( ref subMeshes ) ;
292
- s_Mesh . Clear ( false ) ;
293
- }
294
-
295
- private static TMP_SubMeshUI GetSubMeshUI ( List < TMP_SubMeshUI > subMeshes , Material material , int start )
296
- {
297
- var count = subMeshes . Count ;
298
- for ( var j = 0 ; j < count ; j ++ )
299
- {
300
- var s = subMeshes [ ( j + start + count ) % count ] ;
301
- if ( s . sharedMaterial == material ) return s ;
302
- }
303
-
304
- return null ;
305
- }
306
-
307
- private void SetVerticesDirtyForTMP ( )
308
- {
309
- if ( graphic && graphic . isActiveAndEnabled )
310
- {
311
- graphic . SetVerticesDirty ( ) ;
312
- }
313
- }
314
-
315
- private void CheckSDFScaleForTMP ( )
316
- {
317
- var lossyScaleY = transform . lossyScale . y ;
318
- if ( Mathf . Approximately ( _prevLossyScaleY , lossyScaleY ) ) return ;
319
-
320
- _prevLossyScaleY = lossyScaleY ;
321
- if ( graphic is TextMeshProUGUI textMeshProUGUI && graphic . isActiveAndEnabled )
322
- {
323
- OnTMPChanged ( textMeshProUGUI ) ;
324
- }
325
- }
326
-
327
- private float _prevLossyScaleY ;
328
- #endif
329
-
330
179
public abstract void SetRate ( float rate , UIEffectTweener . CullingMask cullingMask ) ;
331
180
public abstract bool IsRaycastLocationValid ( Vector2 sp , Camera eventCamera ) ;
332
181
}
0 commit comments