Skip to content

Commit

Permalink
fix: properties may not update correctly when changed via code or ani…
Browse files Browse the repository at this point in the history
…mation

close #300
  • Loading branch information
mob-sakai committed Jan 25, 2025
1 parent b2d70af commit f61cee6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 37 deletions.
68 changes: 33 additions & 35 deletions Packages/src/Runtime/UIEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public ToneFilter toneFilter
{
if (m_ToneFilter == value) return;
context.toneFilter = m_ToneFilter = value;
ApplyContextToMaterial();
SetMaterialDirty();
}
}

Expand All @@ -192,7 +192,7 @@ public float toneIntensity
value = Mathf.Clamp(value, 0, 1);
if (Mathf.Approximately(m_ToneIntensity, value)) return;
context.toneIntensity = m_ToneIntensity = value;
ApplyContextToMaterial();
SetMaterialDirty();
}
}

Expand All @@ -206,7 +206,7 @@ public ColorFilter colorFilter
{
if (m_ColorFilter == value) return;
context.colorFilter = m_ColorFilter = value;
ApplyContextToMaterial();
SetMaterialDirty();
}
}

Expand All @@ -221,7 +221,7 @@ public float colorIntensity
value = Mathf.Clamp(value, 0, 1);
if (Mathf.Approximately(m_ColorIntensity, value)) return;
context.colorIntensity = m_ColorIntensity = value;
ApplyContextToMaterial();
SetMaterialDirty();
}
}

Expand All @@ -233,7 +233,7 @@ public Color color
m_Color.a = 1;
if (m_Color == value) return;
context.color = m_Color = value;
ApplyContextToMaterial();
SetMaterialDirty();
}
}

Expand All @@ -244,7 +244,7 @@ public bool colorGlow
{
if (m_ColorGlow == value) return;
context.colorGlow = m_ColorGlow = value;
ApplyContextToMaterial();
SetMaterialDirty();
}
}

Expand All @@ -259,7 +259,7 @@ public SamplingFilter samplingFilter
if (m_SamplingFilter == value) return;
context.samplingFilter = m_SamplingFilter = value;
SetVerticesDirty();
ApplyContextToMaterial();
SetMaterialDirty();
}
}

Expand All @@ -274,7 +274,7 @@ public float samplingIntensity
value = Mathf.Clamp(value, 0, 1);
if (Mathf.Approximately(m_SamplingIntensity, value)) return;
context.samplingIntensity = m_SamplingIntensity = value;
ApplyContextToMaterial();
SetMaterialDirty();
}
}

Expand All @@ -286,7 +286,7 @@ public float samplingScale
value = Mathf.Clamp(value, 0.01f, 100);
if (Mathf.Approximately(m_SamplingScale, value)) return;
m_SamplingScale = value;
ApplyContextToMaterial();
SetMaterialDirty();
}
}

Expand All @@ -305,7 +305,7 @@ public TransitionFilter transitionFilter
if (m_TransitionFilter == value) return;
context.transitionFilter = m_TransitionFilter = value;
SetVerticesDirty();
ApplyContextToMaterial();
SetMaterialDirty();
}
}

Expand All @@ -320,7 +320,7 @@ public float transitionRate
value = Mathf.Clamp(value, 0, 1);
if (Mathf.Approximately(m_TransitionRate, value)) return;
context.transitionRate = m_TransitionRate = value;
ApplyContextToMaterial();
SetMaterialDirty();
}
}

Expand All @@ -331,7 +331,7 @@ public bool transitionReverse
{
if (m_TransitionReverse == value) return;
context.transitionReverse = m_TransitionReverse = value;
ApplyContextToMaterial();
SetMaterialDirty();
}
}

Expand All @@ -342,7 +342,7 @@ public Texture transitionTexture
{
if (m_TransitionTex == value) return;
context.transitionTex = m_TransitionTex = value;
ApplyContextToMaterial();
SetMaterialDirty();
}
}

Expand All @@ -353,7 +353,7 @@ public Vector2 transitionTextureScale
{
if (m_TransitionTexScale == value) return;
context.transitionTexScale = m_TransitionTexScale = value;
ApplyContextToMaterial();
SetMaterialDirty();
}
}

Expand All @@ -364,7 +364,7 @@ public Vector2 transitionTextureOffset
{
if (m_TransitionTexOffset == value) return;
context.transitionTexOffset = m_TransitionTexOffset = value;
ApplyContextToMaterial();
SetMaterialDirty();
}
}

Expand Down Expand Up @@ -398,7 +398,7 @@ public float transitionWidth
value = Mathf.Clamp(value, 0, 1);
if (Mathf.Approximately(m_TransitionWidth, value)) return;
context.transitionWidth = m_TransitionWidth = value;
ApplyContextToMaterial();
SetMaterialDirty();
}
}

Expand All @@ -410,7 +410,7 @@ public float transitionSoftness
value = Mathf.Clamp(value, 0, 1);
if (Mathf.Approximately(m_TransitionSoftness, value)) return;
context.transitionSoftness = m_TransitionSoftness = value;
ApplyContextToMaterial();
SetMaterialDirty();
}
}

Expand All @@ -421,7 +421,7 @@ public ColorFilter transitionColorFilter
{
if (m_TransitionColorFilter == value) return;
context.transitionColorFilter = m_TransitionColorFilter = value;
ApplyContextToMaterial();
SetMaterialDirty();
}
}

Expand All @@ -432,7 +432,7 @@ public Color transitionColor
{
if (m_TransitionColor == value) return;
context.transitionColor = m_TransitionColor = value;
ApplyContextToMaterial();
SetMaterialDirty();
}
}

Expand All @@ -443,7 +443,7 @@ public bool transitionColorGlow
{
if (m_TransitionColorGlow == value) return;
context.transitionColorGlow = m_TransitionColorGlow = value;
ApplyContextToMaterial();
SetMaterialDirty();
}
}

Expand All @@ -454,7 +454,7 @@ public TargetMode targetMode
{
if (m_TargetMode == value) return;
context.targetMode = m_TargetMode = value;
ApplyContextToMaterial();
SetMaterialDirty();
}
}

Expand All @@ -465,7 +465,7 @@ public Color targetColor
{
if (m_TargetColor == value) return;
context.targetColor = m_TargetColor = value;
ApplyContextToMaterial();
SetMaterialDirty();
}
}

Expand All @@ -477,7 +477,7 @@ public float targetRange
value = Mathf.Clamp(value, 0, 1);
if (Mathf.Approximately(m_TargetRange, value)) return;
context.targetRange = m_TargetRange = value;
ApplyContextToMaterial();
SetMaterialDirty();
}
}

Expand All @@ -489,7 +489,7 @@ public float targetSoftness
value = Mathf.Clamp(value, 0, 1);
if (Mathf.Approximately(m_TargetSoftness, value)) return;
context.targetSoftness = m_TargetSoftness = value;
ApplyContextToMaterial();
SetMaterialDirty();
}
}

Expand All @@ -502,7 +502,7 @@ public BlendType blendType
(m_SrcBlendMode, m_DstBlendMode) = (m_BlendType, m_SrcBlendMode, m_DstBlendMode).Convert();
context.srcBlendMode = m_SrcBlendMode;
context.dstBlendMode = m_DstBlendMode;
ApplyContextToMaterial();
SetMaterialDirty();
}
}

Expand All @@ -518,7 +518,7 @@ public BlendMode srcBlendMode
if (m_SrcBlendMode == value) return;
context.srcBlendMode = m_SrcBlendMode = value;
m_BlendType = (m_SrcBlendMode, m_DstBlendMode).Convert();
ApplyContextToMaterial();
SetMaterialDirty();
}
}

Expand All @@ -534,7 +534,7 @@ public BlendMode dstBlendMode
if (m_DstBlendMode == value) return;
context.dstBlendMode = m_DstBlendMode = value;
m_BlendType = (m_SrcBlendMode, m_DstBlendMode).Convert();
ApplyContextToMaterial();
SetMaterialDirty();
}
}

Expand Down Expand Up @@ -604,7 +604,7 @@ public float shadowBlurIntensity
value = Mathf.Clamp(value, 0, 1);
if (Mathf.Approximately(m_ShadowBlurIntensity, value)) return;
context.shadowBlurIntensity = m_ShadowBlurIntensity = value;
ApplyContextToMaterial();
SetMaterialDirty();
}
}

Expand All @@ -615,7 +615,7 @@ public ColorFilter shadowColorFilter
{
if (m_ShadowColorFilter == value) return;
context.shadowColorFilter = m_ShadowColorFilter = value;
ApplyContextToMaterial();
SetMaterialDirty();
}
}

Expand All @@ -626,7 +626,7 @@ public Color shadowColor
{
if (m_ShadowColor == value) return;
context.shadowColor = m_ShadowColor = value;
ApplyContextToMaterial();
SetMaterialDirty();
}
}

Expand All @@ -637,7 +637,7 @@ public bool shadowGlow
{
if (m_ShadowColorGlow == value) return;
context.shadowColorGlow = m_ShadowColorGlow = value;
ApplyContextToMaterial();
SetMaterialDirty();
}
}

Expand Down Expand Up @@ -726,13 +726,13 @@ protected override void OnEnable()
{
(m_SrcBlendMode, m_DstBlendMode) = (m_BlendType, m_SrcBlendMode, m_DstBlendMode).Convert();
base.OnEnable();
ApplyContextToMaterial();
SetMaterialDirty();
}

protected override void OnDisable()
{
base.OnDisable();
ApplyContextToMaterial();
SetMaterialDirty();
}

protected override void OnDestroy()
Expand Down Expand Up @@ -960,7 +960,6 @@ public void LoadPreset(UIEffect preset)
m_GradationRotation = preset.m_GradationRotation;

UpdateContext(context);
ApplyContextToMaterial();
SetVerticesDirty();
SetMaterialDirty();
}
Expand Down Expand Up @@ -1022,7 +1021,6 @@ internal void CopyFrom(UIEffectContext c)
m_GradationRotation = c.gradationRotation;

UpdateContext(context);
ApplyContextToMaterial();
SetVerticesDirty();
SetMaterialDirty();
}
Expand Down
3 changes: 2 additions & 1 deletion Packages/src/Runtime/UIEffectBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ protected override void OnRectTransformDimensionsChange()
protected override void OnDidApplyAnimationProperties()
{
UpdateContext(context);
ApplyContextToMaterial();
SetVerticesDirty();
SetMaterialDirty();
}

public virtual void SetVerticesDirty()
Expand Down
2 changes: 1 addition & 1 deletion Packages/src/Runtime/UIEffectReplica.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public float samplingScale
value = Mathf.Clamp(value, 0.01f, 100);
if (Mathf.Approximately(m_SamplingScale, value)) return;
m_SamplingScale = value;
ApplyContextToMaterial();
SetMaterialDirty();
}
}

Expand Down

0 comments on commit f61cee6

Please sign in to comment.