Skip to content

Commit f61cee6

Browse files
committed
fix: properties may not update correctly when changed via code or animation
close #300
1 parent b2d70af commit f61cee6

File tree

3 files changed

+36
-37
lines changed

3 files changed

+36
-37
lines changed

Packages/src/Runtime/UIEffect.cs

+33-35
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public ToneFilter toneFilter
177177
{
178178
if (m_ToneFilter == value) return;
179179
context.toneFilter = m_ToneFilter = value;
180-
ApplyContextToMaterial();
180+
SetMaterialDirty();
181181
}
182182
}
183183

@@ -192,7 +192,7 @@ public float toneIntensity
192192
value = Mathf.Clamp(value, 0, 1);
193193
if (Mathf.Approximately(m_ToneIntensity, value)) return;
194194
context.toneIntensity = m_ToneIntensity = value;
195-
ApplyContextToMaterial();
195+
SetMaterialDirty();
196196
}
197197
}
198198

@@ -206,7 +206,7 @@ public ColorFilter colorFilter
206206
{
207207
if (m_ColorFilter == value) return;
208208
context.colorFilter = m_ColorFilter = value;
209-
ApplyContextToMaterial();
209+
SetMaterialDirty();
210210
}
211211
}
212212

@@ -221,7 +221,7 @@ public float colorIntensity
221221
value = Mathf.Clamp(value, 0, 1);
222222
if (Mathf.Approximately(m_ColorIntensity, value)) return;
223223
context.colorIntensity = m_ColorIntensity = value;
224-
ApplyContextToMaterial();
224+
SetMaterialDirty();
225225
}
226226
}
227227

@@ -233,7 +233,7 @@ public Color color
233233
m_Color.a = 1;
234234
if (m_Color == value) return;
235235
context.color = m_Color = value;
236-
ApplyContextToMaterial();
236+
SetMaterialDirty();
237237
}
238238
}
239239

@@ -244,7 +244,7 @@ public bool colorGlow
244244
{
245245
if (m_ColorGlow == value) return;
246246
context.colorGlow = m_ColorGlow = value;
247-
ApplyContextToMaterial();
247+
SetMaterialDirty();
248248
}
249249
}
250250

@@ -259,7 +259,7 @@ public SamplingFilter samplingFilter
259259
if (m_SamplingFilter == value) return;
260260
context.samplingFilter = m_SamplingFilter = value;
261261
SetVerticesDirty();
262-
ApplyContextToMaterial();
262+
SetMaterialDirty();
263263
}
264264
}
265265

@@ -274,7 +274,7 @@ public float samplingIntensity
274274
value = Mathf.Clamp(value, 0, 1);
275275
if (Mathf.Approximately(m_SamplingIntensity, value)) return;
276276
context.samplingIntensity = m_SamplingIntensity = value;
277-
ApplyContextToMaterial();
277+
SetMaterialDirty();
278278
}
279279
}
280280

@@ -286,7 +286,7 @@ public float samplingScale
286286
value = Mathf.Clamp(value, 0.01f, 100);
287287
if (Mathf.Approximately(m_SamplingScale, value)) return;
288288
m_SamplingScale = value;
289-
ApplyContextToMaterial();
289+
SetMaterialDirty();
290290
}
291291
}
292292

@@ -305,7 +305,7 @@ public TransitionFilter transitionFilter
305305
if (m_TransitionFilter == value) return;
306306
context.transitionFilter = m_TransitionFilter = value;
307307
SetVerticesDirty();
308-
ApplyContextToMaterial();
308+
SetMaterialDirty();
309309
}
310310
}
311311

@@ -320,7 +320,7 @@ public float transitionRate
320320
value = Mathf.Clamp(value, 0, 1);
321321
if (Mathf.Approximately(m_TransitionRate, value)) return;
322322
context.transitionRate = m_TransitionRate = value;
323-
ApplyContextToMaterial();
323+
SetMaterialDirty();
324324
}
325325
}
326326

@@ -331,7 +331,7 @@ public bool transitionReverse
331331
{
332332
if (m_TransitionReverse == value) return;
333333
context.transitionReverse = m_TransitionReverse = value;
334-
ApplyContextToMaterial();
334+
SetMaterialDirty();
335335
}
336336
}
337337

@@ -342,7 +342,7 @@ public Texture transitionTexture
342342
{
343343
if (m_TransitionTex == value) return;
344344
context.transitionTex = m_TransitionTex = value;
345-
ApplyContextToMaterial();
345+
SetMaterialDirty();
346346
}
347347
}
348348

@@ -353,7 +353,7 @@ public Vector2 transitionTextureScale
353353
{
354354
if (m_TransitionTexScale == value) return;
355355
context.transitionTexScale = m_TransitionTexScale = value;
356-
ApplyContextToMaterial();
356+
SetMaterialDirty();
357357
}
358358
}
359359

@@ -364,7 +364,7 @@ public Vector2 transitionTextureOffset
364364
{
365365
if (m_TransitionTexOffset == value) return;
366366
context.transitionTexOffset = m_TransitionTexOffset = value;
367-
ApplyContextToMaterial();
367+
SetMaterialDirty();
368368
}
369369
}
370370

@@ -398,7 +398,7 @@ public float transitionWidth
398398
value = Mathf.Clamp(value, 0, 1);
399399
if (Mathf.Approximately(m_TransitionWidth, value)) return;
400400
context.transitionWidth = m_TransitionWidth = value;
401-
ApplyContextToMaterial();
401+
SetMaterialDirty();
402402
}
403403
}
404404

@@ -410,7 +410,7 @@ public float transitionSoftness
410410
value = Mathf.Clamp(value, 0, 1);
411411
if (Mathf.Approximately(m_TransitionSoftness, value)) return;
412412
context.transitionSoftness = m_TransitionSoftness = value;
413-
ApplyContextToMaterial();
413+
SetMaterialDirty();
414414
}
415415
}
416416

@@ -421,7 +421,7 @@ public ColorFilter transitionColorFilter
421421
{
422422
if (m_TransitionColorFilter == value) return;
423423
context.transitionColorFilter = m_TransitionColorFilter = value;
424-
ApplyContextToMaterial();
424+
SetMaterialDirty();
425425
}
426426
}
427427

@@ -432,7 +432,7 @@ public Color transitionColor
432432
{
433433
if (m_TransitionColor == value) return;
434434
context.transitionColor = m_TransitionColor = value;
435-
ApplyContextToMaterial();
435+
SetMaterialDirty();
436436
}
437437
}
438438

@@ -443,7 +443,7 @@ public bool transitionColorGlow
443443
{
444444
if (m_TransitionColorGlow == value) return;
445445
context.transitionColorGlow = m_TransitionColorGlow = value;
446-
ApplyContextToMaterial();
446+
SetMaterialDirty();
447447
}
448448
}
449449

@@ -454,7 +454,7 @@ public TargetMode targetMode
454454
{
455455
if (m_TargetMode == value) return;
456456
context.targetMode = m_TargetMode = value;
457-
ApplyContextToMaterial();
457+
SetMaterialDirty();
458458
}
459459
}
460460

@@ -465,7 +465,7 @@ public Color targetColor
465465
{
466466
if (m_TargetColor == value) return;
467467
context.targetColor = m_TargetColor = value;
468-
ApplyContextToMaterial();
468+
SetMaterialDirty();
469469
}
470470
}
471471

@@ -477,7 +477,7 @@ public float targetRange
477477
value = Mathf.Clamp(value, 0, 1);
478478
if (Mathf.Approximately(m_TargetRange, value)) return;
479479
context.targetRange = m_TargetRange = value;
480-
ApplyContextToMaterial();
480+
SetMaterialDirty();
481481
}
482482
}
483483

@@ -489,7 +489,7 @@ public float targetSoftness
489489
value = Mathf.Clamp(value, 0, 1);
490490
if (Mathf.Approximately(m_TargetSoftness, value)) return;
491491
context.targetSoftness = m_TargetSoftness = value;
492-
ApplyContextToMaterial();
492+
SetMaterialDirty();
493493
}
494494
}
495495

@@ -502,7 +502,7 @@ public BlendType blendType
502502
(m_SrcBlendMode, m_DstBlendMode) = (m_BlendType, m_SrcBlendMode, m_DstBlendMode).Convert();
503503
context.srcBlendMode = m_SrcBlendMode;
504504
context.dstBlendMode = m_DstBlendMode;
505-
ApplyContextToMaterial();
505+
SetMaterialDirty();
506506
}
507507
}
508508

@@ -518,7 +518,7 @@ public BlendMode srcBlendMode
518518
if (m_SrcBlendMode == value) return;
519519
context.srcBlendMode = m_SrcBlendMode = value;
520520
m_BlendType = (m_SrcBlendMode, m_DstBlendMode).Convert();
521-
ApplyContextToMaterial();
521+
SetMaterialDirty();
522522
}
523523
}
524524

@@ -534,7 +534,7 @@ public BlendMode dstBlendMode
534534
if (m_DstBlendMode == value) return;
535535
context.dstBlendMode = m_DstBlendMode = value;
536536
m_BlendType = (m_SrcBlendMode, m_DstBlendMode).Convert();
537-
ApplyContextToMaterial();
537+
SetMaterialDirty();
538538
}
539539
}
540540

@@ -604,7 +604,7 @@ public float shadowBlurIntensity
604604
value = Mathf.Clamp(value, 0, 1);
605605
if (Mathf.Approximately(m_ShadowBlurIntensity, value)) return;
606606
context.shadowBlurIntensity = m_ShadowBlurIntensity = value;
607-
ApplyContextToMaterial();
607+
SetMaterialDirty();
608608
}
609609
}
610610

@@ -615,7 +615,7 @@ public ColorFilter shadowColorFilter
615615
{
616616
if (m_ShadowColorFilter == value) return;
617617
context.shadowColorFilter = m_ShadowColorFilter = value;
618-
ApplyContextToMaterial();
618+
SetMaterialDirty();
619619
}
620620
}
621621

@@ -626,7 +626,7 @@ public Color shadowColor
626626
{
627627
if (m_ShadowColor == value) return;
628628
context.shadowColor = m_ShadowColor = value;
629-
ApplyContextToMaterial();
629+
SetMaterialDirty();
630630
}
631631
}
632632

@@ -637,7 +637,7 @@ public bool shadowGlow
637637
{
638638
if (m_ShadowColorGlow == value) return;
639639
context.shadowColorGlow = m_ShadowColorGlow = value;
640-
ApplyContextToMaterial();
640+
SetMaterialDirty();
641641
}
642642
}
643643

@@ -726,13 +726,13 @@ protected override void OnEnable()
726726
{
727727
(m_SrcBlendMode, m_DstBlendMode) = (m_BlendType, m_SrcBlendMode, m_DstBlendMode).Convert();
728728
base.OnEnable();
729-
ApplyContextToMaterial();
729+
SetMaterialDirty();
730730
}
731731

732732
protected override void OnDisable()
733733
{
734734
base.OnDisable();
735-
ApplyContextToMaterial();
735+
SetMaterialDirty();
736736
}
737737

738738
protected override void OnDestroy()
@@ -960,7 +960,6 @@ public void LoadPreset(UIEffect preset)
960960
m_GradationRotation = preset.m_GradationRotation;
961961

962962
UpdateContext(context);
963-
ApplyContextToMaterial();
964963
SetVerticesDirty();
965964
SetMaterialDirty();
966965
}
@@ -1022,7 +1021,6 @@ internal void CopyFrom(UIEffectContext c)
10221021
m_GradationRotation = c.gradationRotation;
10231022

10241023
UpdateContext(context);
1025-
ApplyContextToMaterial();
10261024
SetVerticesDirty();
10271025
SetMaterialDirty();
10281026
}

Packages/src/Runtime/UIEffectBase.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ protected override void OnRectTransformDimensionsChange()
153153
protected override void OnDidApplyAnimationProperties()
154154
{
155155
UpdateContext(context);
156-
ApplyContextToMaterial();
156+
SetVerticesDirty();
157+
SetMaterialDirty();
157158
}
158159

159160
public virtual void SetVerticesDirty()

Packages/src/Runtime/UIEffectReplica.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public float samplingScale
5050
value = Mathf.Clamp(value, 0.01f, 100);
5151
if (Mathf.Approximately(m_SamplingScale, value)) return;
5252
m_SamplingScale = value;
53-
ApplyContextToMaterial();
53+
SetMaterialDirty();
5454
}
5555
}
5656

0 commit comments

Comments
 (0)