diff --git a/Scripts/Unmask.cs b/Scripts/Unmask.cs
index ab079d8..ea6e3ce 100644
--- a/Scripts/Unmask.cs
+++ b/Scripts/Unmask.cs
@@ -27,10 +27,10 @@ namespace Coffee.UIExtensions
[SerializeField] RectTransform m_FitTarget;
[Tooltip("Fit graphic's transform to target transform on LateUpdate every frame.")]
[SerializeField] bool m_FitOnLateUpdate;
- [Tooltip("Show the graphic that is associated with the unmask render area.")]
- [SerializeField] bool m_ShowUnmaskGraphic = false;
[Tooltip ("Unmask affects only for children.")]
[SerializeField] bool m_OnlyForChildren = false;
+ [Tooltip("Show the graphic that is associated with the unmask render area.")]
+ [SerializeField] bool m_ShowUnmaskGraphic = false;
//################################
@@ -72,7 +72,6 @@ namespace Coffee.UIExtensions
}
}
-
///
/// Unmask affects only for children.
///
@@ -108,9 +107,9 @@ namespace Coffee.UIExtensions
var canvasRenderer = graphic.canvasRenderer;
if (m_OnlyForChildren)
{
- canvasRenderer.hasPopInstruction = true;
StencilMaterial.Remove (_revertUnmaskMaterial);
_revertUnmaskMaterial = StencilMaterial.Add (baseMaterial, (1 << stencilDepth) - 1, StencilOp.Replace, CompareFunction.NotEqual, (ColorWriteMask)0);
+ canvasRenderer.hasPopInstruction = true;
canvasRenderer.popMaterialCount = 1;
canvasRenderer.SetPopMaterial (_revertUnmaskMaterial, 0);
}
@@ -171,9 +170,13 @@ namespace Coffee.UIExtensions
_unmaskMaterial = null;
_revertUnmaskMaterial = null;
- var canvasRenderer = graphic.canvasRenderer;
- canvasRenderer.hasPopInstruction = false;
- canvasRenderer.popMaterialCount = 0;
+ if (graphic)
+ {
+ var canvasRenderer = graphic.canvasRenderer;
+ canvasRenderer.hasPopInstruction = false;
+ canvasRenderer.popMaterialCount = 0;
+ graphic.SetMaterialDirty();
+ }
SetDirty ();
}
@@ -182,16 +185,17 @@ namespace Coffee.UIExtensions
///
void LateUpdate()
{
- #if UNITY_EDITOR
+#if UNITY_EDITOR
if (m_FitTarget && (m_FitOnLateUpdate || !Application.isPlaying))
- #else
+#else
if (m_FitTarget && m_FitOnLateUpdate)
- #endif
+#endif
{
FitTo(m_FitTarget);
}
}
+#if UNITY_EDITOR
///
/// This function is called when the script is loaded or a value is changed in the inspector (Called in the editor only).
///
@@ -199,6 +203,7 @@ namespace Coffee.UIExtensions
{
SetDirty();
}
+#endif
///
/// Mark the graphic as dirty.