diff --git a/Packages/src/Runtime/UIEffect.cs b/Packages/src/Runtime/UIEffect.cs index 35c520e..e8ee1a1 100644 --- a/Packages/src/Runtime/UIEffect.cs +++ b/Packages/src/Runtime/UIEffect.cs @@ -1060,13 +1060,13 @@ namespace Coffee.UIEffects c.gradationRotation = m_GradationRotation; } - public override void ApplyContextToMaterial() + public override void ApplyContextToMaterial(Material material) { - base.ApplyContextToMaterial(); + base.ApplyContextToMaterial(material); replicas.ForEach(c => { if (!c) return; - c.ApplyContextToMaterial(); + c.ApplyContextToMaterial(material); }); } diff --git a/Packages/src/Runtime/UIEffectBase.cs b/Packages/src/Runtime/UIEffectBase.cs index 63885a4..39c7150 100644 --- a/Packages/src/Runtime/UIEffectBase.cs +++ b/Packages/src/Runtime/UIEffectBase.cs @@ -98,7 +98,7 @@ namespace Coffee.UIEffects Profiler.EndSample(); } - ApplyContextToMaterial(); + ApplyContextToMaterial(_material); Profiler.EndSample(); return _material; } @@ -107,7 +107,7 @@ namespace Coffee.UIEffects protected override void OnValidate() { UpdateContext(context); - ApplyContextToMaterial(); + ApplyContextToMaterial(graphic ? graphic.canvasRenderer.GetMaterial() : _material); SetVerticesDirty(); SetMaterialDirty(); @@ -141,7 +141,7 @@ namespace Coffee.UIEffects if (graphic) { graphic.SetVerticesDirty(); - GraphicProxy.Find(graphic).SetVerticesDirty(graphic); + GraphicProxy.Find(graphic).SetVerticesDirty(graphic, false); #if UNITY_EDITOR EditorApplication.QueuePlayerLoopUpdate(); #endif @@ -161,14 +161,14 @@ namespace Coffee.UIEffects protected abstract void UpdateContext(UIEffectContext c); - public virtual void ApplyContextToMaterial() + public virtual void ApplyContextToMaterial(Material material) { - if (!isActiveAndEnabled || context == null) return; + if (!isActiveAndEnabled || context == null || !material) return; - context.ApplyToMaterial(_material, actualSamplingScale); + context.ApplyToMaterial(material, actualSamplingScale); #if UNITY_EDITOR - UIEffectProjectSettings.shaderRegistry.RegisterVariant(_material, "UI > UIEffect"); + UIEffectProjectSettings.shaderRegistry.RegisterVariant(material, "UI > UIEffect"); if (!EditorApplication.isPlaying) { EditorApplication.QueuePlayerLoopUpdate(); diff --git a/Packages/src/Runtime/UIEffectReplica.cs b/Packages/src/Runtime/UIEffectReplica.cs index 097f7c2..d913a4d 100644 --- a/Packages/src/Runtime/UIEffectReplica.cs +++ b/Packages/src/Runtime/UIEffectReplica.cs @@ -107,11 +107,11 @@ namespace Coffee.UIEffects { } - public override void ApplyContextToMaterial() + public override void ApplyContextToMaterial(Material material) { if (!isActiveAndEnabled || !target || !target.isActiveAndEnabled) return; - base.ApplyContextToMaterial(); + base.ApplyContextToMaterial(material); } public override void SetRate(float rate, UIEffectTweener.CullingMask mask) diff --git a/Packages/src/Runtime/Utilities/GraphicProxy.cs b/Packages/src/Runtime/Utilities/GraphicProxy.cs index cebcb05..11d51b6 100644 --- a/Packages/src/Runtime/Utilities/GraphicProxy.cs +++ b/Packages/src/Runtime/Utilities/GraphicProxy.cs @@ -68,7 +68,7 @@ namespace Coffee.UIEffects } } - public virtual void SetVerticesDirty(Graphic graphic) + public virtual void SetVerticesDirty(Graphic graphic, bool enabled) { } diff --git a/Packages/src/Runtime/Utilities/TmpProxy.cs b/Packages/src/Runtime/Utilities/TmpProxy.cs index a1864dd..a7555ee 100644 --- a/Packages/src/Runtime/Utilities/TmpProxy.cs +++ b/Packages/src/Runtime/Utilities/TmpProxy.cs @@ -53,11 +53,19 @@ namespace Coffee.UIEffects } } - public override void SetVerticesDirty(Graphic graphic) + public override void SetVerticesDirty(Graphic graphic, bool enabled) { if (graphic is TextMeshProUGUI textMeshProUGUI && textMeshProUGUI.isActiveAndEnabled) { - OnChangeText(textMeshProUGUI); + if (enabled) + { + OnChangeText(textMeshProUGUI); + } + else if (0 < textMeshProUGUI.textInfo?.meshInfo?.Length + && 0 < textMeshProUGUI.textInfo.meshInfo[0].vertexCount) + { + textMeshProUGUI.UpdateVertexData(); + } } } @@ -174,6 +182,20 @@ namespace Coffee.UIEffects s_ChangedInstances.Clear(); }; + +#if UNITY_EDITOR + UnityEditor.SceneManagement.EditorSceneManager.sceneSaved += _ => + { + foreach (var textMeshProUGUI in s_RegisteredInstances) + { + if (!textMeshProUGUI || !textMeshProUGUI.isActiveAndEnabled) continue; + if (textMeshProUGUI.TryGetComponent(out var effect) && effect.isActiveAndEnabled) + { + effect.SetMaterialDirty(); + } + } + }; +#endif } private static void OnChangeText(Object obj) @@ -236,7 +258,6 @@ namespace Coffee.UIEffects } s_VertexHelper.FillMesh(s_Mesh); - replica.ApplyContextToMaterial(); subMeshUI.canvasRenderer.SetMesh(s_Mesh); } else