From a93ba3ff85b8465ff28e26a40bc459b6a6473d4a Mon Sep 17 00:00:00 2001 From: mob-sakai Date: Fri, 25 Jan 2019 17:48:52 +0900 Subject: [PATCH] close #11; Unmask only for children option --- Scripts/Unmask.cs | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/Scripts/Unmask.cs b/Scripts/Unmask.cs index 2809e1c..ab079d8 100644 --- a/Scripts/Unmask.cs +++ b/Scripts/Unmask.cs @@ -29,6 +29,8 @@ namespace Coffee.UIExtensions [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; //################################ @@ -70,6 +72,20 @@ namespace Coffee.UIExtensions } } + + /// + /// Unmask affects only for children. + /// + public bool onlyForChildren + { + get { return m_OnlyForChildren; } + set + { + m_OnlyForChildren = value; + SetDirty (); + } + } + /// /// Perform material modification in this function. /// @@ -88,6 +104,22 @@ namespace Coffee.UIExtensions StencilMaterial.Remove(_unmaskMaterial); _unmaskMaterial = StencilMaterial.Add(baseMaterial, (1 << stencilDepth) - 1, StencilOp.Zero, CompareFunction.Always, m_ShowUnmaskGraphic ? ColorWriteMask.All : (ColorWriteMask)0, 0, (1 << stencilDepth) - 1); + // Unmask affects only for children. + 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.popMaterialCount = 1; + canvasRenderer.SetPopMaterial (_revertUnmaskMaterial, 0); + } + else + { + canvasRenderer.hasPopInstruction = false; + canvasRenderer.popMaterialCount = 0; + } + return _unmaskMaterial; } @@ -114,6 +146,7 @@ namespace Coffee.UIExtensions // Private Members. //################################ Material _unmaskMaterial; + Material _revertUnmaskMaterial; Graphic _graphic; /// @@ -133,9 +166,15 @@ namespace Coffee.UIExtensions /// void OnDisable() { - StencilMaterial.Remove(_unmaskMaterial); + StencilMaterial.Remove (_unmaskMaterial); + StencilMaterial.Remove (_revertUnmaskMaterial); _unmaskMaterial = null; - SetDirty(); + _revertUnmaskMaterial = null; + + var canvasRenderer = graphic.canvasRenderer; + canvasRenderer.hasPopInstruction = false; + canvasRenderer.popMaterialCount = 0; + SetDirty (); } ///