@@ -175,6 +175,15 @@ public class UIEffectContext
175
175
public Color shadowColor ;
176
176
public bool shadowColorGlow ;
177
177
178
+ public GradationMode gradationMode ;
179
+ public Color gradationColor1 ;
180
+ public Color gradationColor2 ;
181
+ public Gradient gradationGradient ;
182
+ public float gradationOffset ;
183
+ public float gradationScale ;
184
+ private List < float > _keyTimes ;
185
+ private List < float > _splitTimes ;
186
+
178
187
public bool allowExtendVertex ;
179
188
180
189
@@ -188,6 +197,7 @@ public class UIEffectContext
188
197
189
198
public void Reset ( )
190
199
{
200
+ InternalListPool < float > . Return ( ref _keyTimes ) ;
191
201
CopyFrom ( s_DefaultContext ) ;
192
202
}
193
203
@@ -237,9 +247,21 @@ public void CopyFrom(UIEffectContext preset)
237
247
shadowColor = preset . shadowColor ;
238
248
shadowColorGlow = preset . shadowColorGlow ;
239
249
250
+ gradationMode = preset . gradationMode ;
251
+ gradationColor1 = preset . gradationColor1 ;
252
+ gradationColor2 = preset . gradationColor2 ;
253
+ gradationGradient = preset . gradationGradient ;
254
+ gradationOffset = preset . gradationOffset ;
255
+ gradationScale = preset . gradationScale ;
256
+
240
257
allowExtendVertex = preset . allowExtendVertex ;
241
258
}
242
259
260
+ public void SetGradationDirty ( )
261
+ {
262
+ InternalListPool < float > . Return ( ref _keyTimes ) ;
263
+ }
264
+
243
265
public void ApplyToMaterial ( Material material , float actualSamplingScale = 1f )
244
266
{
245
267
if ( ! material ) return ;
@@ -353,6 +375,7 @@ public void ModifyMesh(Graphic graphic, RectTransform transitionRoot, VertexHelp
353
375
// Get the rectangle to calculate the normalized position.
354
376
vh . GetUIVertexStream ( verts ) ;
355
377
var bundleSize = isText ? 6 : count ;
378
+ var rectMatrix = Matrix4x4 . identity ;
356
379
var rot = Matrix4x4 . Rotate ( Quaternion . Euler ( 0 , 0 , transitionRotation ) ) ;
357
380
var v1 = rot . MultiplyPoint3x4 ( new Vector3 ( 1 , 1 , 0 ) ) ;
358
381
var multiplier = Mathf . Max ( Mathf . Abs ( v1 . x ) , Mathf . Abs ( v1 . y ) ) ;
@@ -361,9 +384,10 @@ public void ModifyMesh(Graphic graphic, RectTransform transitionRoot, VertexHelp
361
384
if ( transitionRoot )
362
385
{
363
386
rect = transitionRoot . rect ;
387
+ rectMatrix = transitionRoot . worldToLocalMatrix
388
+ * graphic . transform . localToWorldMatrix ;
364
389
rot *= Matrix4x4 . Scale ( new Vector3 ( 1 / multiplier , 1 / multiplier , 1 ) )
365
- * transitionRoot . worldToLocalMatrix
366
- * graphic . rectTransform . localToWorldMatrix ;
390
+ * rectMatrix ;
367
391
}
368
392
else
369
393
{
@@ -401,13 +425,74 @@ public void ModifyMesh(Graphic graphic, RectTransform transitionRoot, VertexHelp
401
425
}
402
426
}
403
427
428
+ // Apply gradation.
429
+ ApplyGradation ( verts , transitionRoot . rect , rectMatrix ) ;
430
+
404
431
// Apply shadow.
405
432
ApplyShadow ( transitionRoot , verts ) ;
406
433
407
434
vh . Clear ( ) ;
408
435
vh . AddUIVertexTriangleStream ( verts ) ;
409
436
}
410
437
438
+ private void ApplyGradation ( List < UIVertex > verts , Rect rect , Matrix4x4 m )
439
+ {
440
+ var a = gradationColor1 ;
441
+ var b = gradationColor2 ;
442
+ var offset = gradationOffset ;
443
+ var scale = gradationScale ;
444
+ var grad = gradationGradient ;
445
+ switch ( gradationMode )
446
+ {
447
+ case GradationMode . Horizontal :
448
+ GradientUtil . DoHorizontalGradient ( verts , a , b , offset , scale , rect , m ) ;
449
+ break ;
450
+ case GradationMode . Vertical :
451
+ GradientUtil . DoVerticalGradient ( verts , a , b , offset , scale , rect , m ) ;
452
+ break ;
453
+ case GradationMode . DiagonalToRightBottom :
454
+ GradientUtil . DoDiagonalGradientToRightBottom ( verts , a , b , offset , scale , rect , m ) ;
455
+ break ;
456
+ case GradationMode . DiagonalToLeftBottom :
457
+ GradientUtil . DoDiagonalGradientToLeftBottom ( verts , a , b , offset , scale , rect , m ) ;
458
+ break ;
459
+ case GradationMode . RadialFast :
460
+ GradientUtil . DoRadialGradient ( verts , a , b , offset , scale , rect , m , 4 ) ;
461
+ break ;
462
+ case GradationMode . RadialDetail :
463
+ GradientUtil . DoRadialGradient ( verts , a , b , offset , scale , rect , m , 12 ) ;
464
+ break ;
465
+ case GradationMode . HorizontalGradient :
466
+ {
467
+ if ( _keyTimes == null )
468
+ {
469
+ _keyTimes = InternalListPool < float > . Rent ( ) ;
470
+ GradientUtil . GetKeyTimes ( grad , _keyTimes ) ;
471
+ }
472
+
473
+ var splitTimes = InternalListPool < float > . Rent ( ) ;
474
+ GradientUtil . SplitKeyTimes ( _keyTimes , splitTimes , offset , scale ) ;
475
+ GradientUtil . DoHorizontalGradient ( verts , grad , splitTimes , offset , scale , rect , m ) ;
476
+ InternalListPool < float > . Return ( ref splitTimes ) ;
477
+ break ;
478
+ }
479
+ case GradationMode . VerticalGradient :
480
+ {
481
+ if ( _keyTimes == null )
482
+ {
483
+ _keyTimes = InternalListPool < float > . Rent ( ) ;
484
+ GradientUtil . GetKeyTimes ( grad , _keyTimes ) ;
485
+ }
486
+
487
+ var splitTimes = InternalListPool < float > . Rent ( ) ;
488
+ GradientUtil . SplitKeyTimes ( _keyTimes , splitTimes , offset , scale ) ;
489
+ GradientUtil . DoVerticalGradient ( verts , grad , splitTimes , offset , scale , rect , m ) ;
490
+ InternalListPool < float > . Return ( ref splitTimes ) ;
491
+ break ;
492
+ }
493
+ }
494
+ }
495
+
411
496
private void ApplyShadow ( RectTransform transitionRoot , List < UIVertex > verts )
412
497
{
413
498
switch ( shadowMode )
0 commit comments