Exemplo n.º 1
0
        protected override void OnDisable()
        {
            base.OnDisable();
            m_ShouldRecalculateStencil = true;
            SetMaterialDirty();
            UpdateClipParent();
            StencilMaterial.Remove(m_MaskMaterial);
            m_MaskMaterial = null;

            if (GetComponent <Mask>() != null)
            {
                MaskUtilities.NotifyStencilStateChanged(this);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 ///   <para>See MonoBehaviour.OnDisable.</para>
 /// </summary>
 protected override void OnDisable()
 {
     base.OnDisable();
     this.m_ShouldRecalculateStencil = true;
     this.SetMaterialDirty();
     this.UpdateClipParent();
     StencilMaterial.Remove(this.m_MaskMaterial);
     this.m_MaskMaterial = (Material)null;
     if (!((UnityEngine.Object) this.GetComponent <Mask>() != (UnityEngine.Object)null))
     {
         return;
     }
     MaskUtilities.NotifyStencilStateChanged((Component)this);
 }
Exemplo n.º 3
0
        public virtual Material GetModifiedMaterial(Material baseMaterial)
        {
            Material result;

            if (!this.MaskEnabled())
            {
                result = baseMaterial;
            }
            else
            {
                Transform stopAfter    = MaskUtilities.FindRootSortOverrideCanvas(base.transform);
                int       stencilDepth = MaskUtilities.GetStencilDepth(base.transform, stopAfter);
                if (stencilDepth >= 8)
                {
                    Debug.LogError("Attempting to use a stencil mask with depth > 8", base.gameObject);
                    result = baseMaterial;
                }
                else
                {
                    int num = 1 << stencilDepth;
                    if (num == 1)
                    {
                        Material maskMaterial = StencilMaterial.Add(baseMaterial, 1, StencilOp.Replace, CompareFunction.Always, (!this.m_ShowMaskGraphic) ? ((ColorWriteMask)0) : ColorWriteMask.All);
                        StencilMaterial.Remove(this.m_MaskMaterial);
                        this.m_MaskMaterial = maskMaterial;
                        Material unmaskMaterial = StencilMaterial.Add(baseMaterial, 1, StencilOp.Zero, CompareFunction.Always, (ColorWriteMask)0);
                        StencilMaterial.Remove(this.m_UnmaskMaterial);
                        this.m_UnmaskMaterial = unmaskMaterial;
                        this.graphic.canvasRenderer.popMaterialCount = 1;
                        this.graphic.canvasRenderer.SetPopMaterial(this.m_UnmaskMaterial, 0);
                        result = this.m_MaskMaterial;
                    }
                    else
                    {
                        Material maskMaterial2 = StencilMaterial.Add(baseMaterial, num | num - 1, StencilOp.Replace, CompareFunction.Equal, (!this.m_ShowMaskGraphic) ? ((ColorWriteMask)0) : ColorWriteMask.All, num - 1, num | num - 1);
                        StencilMaterial.Remove(this.m_MaskMaterial);
                        this.m_MaskMaterial = maskMaterial2;
                        this.graphic.canvasRenderer.hasPopInstruction = true;
                        Material unmaskMaterial2 = StencilMaterial.Add(baseMaterial, num - 1, StencilOp.Replace, CompareFunction.Equal, (ColorWriteMask)0, num - 1, num | num - 1);
                        StencilMaterial.Remove(this.m_UnmaskMaterial);
                        this.m_UnmaskMaterial = unmaskMaterial2;
                        this.graphic.canvasRenderer.popMaterialCount = 1;
                        this.graphic.canvasRenderer.SetPopMaterial(this.m_UnmaskMaterial, 0);
                        result = this.m_MaskMaterial;
                    }
                }
            }
            return(result);
        }
Exemplo n.º 4
0
 protected override void OnDisable()
 {
     base.OnDisable();
     if (this.graphic != null)
     {
         this.graphic.SetMaterialDirty();
         this.graphic.canvasRenderer.hasPopInstruction = false;
         this.graphic.canvasRenderer.popMaterialCount  = 0;
     }
     StencilMaterial.Remove(this.m_MaskMaterial);
     this.m_MaskMaterial = null;
     StencilMaterial.Remove(this.m_UnmaskMaterial);
     this.m_UnmaskMaterial = null;
     MaskUtilities.NotifyStencilStateChanged(this);
 }
Exemplo n.º 5
0
        protected override void OnDisable()
        {
            // we call base OnDisable first here
            // as we need to have the IsActive return the
            // correct value when we notify the children
            // that the mask state has changed.
            base.OnDisable();
            if (graphic != null)
            {
                graphic.SetMaterialDirty();
            }

            StencilMaterial.Remove(m_MaskMaterial);
            m_MaskMaterial = null;
            MaskUtilities.NotifyStencilStateChanged(this);
        }
Exemplo n.º 6
0
        /// <summary>
        ///
        /// <para>
        /// See IMaterialModifier.GetModifiedMaterial.
        /// </para>
        ///
        /// </summary>
        /// <param name="baseMaterial"/>
        public virtual Material GetModifiedMaterial(Material baseMaterial)
        {
            Material baseMat = baseMaterial;

            if (this.m_ShouldRecalculateStencil)
            {
                this.m_StencilValue             = !this.maskable ? 0 : MaskUtilities.GetStencilDepth(this.transform, MaskUtilities.FindRootSortOverrideCanvas(this.transform));
                this.m_ShouldRecalculateStencil = false;
            }
            if (this.m_StencilValue > 0 && (UnityEngine.Object) this.GetComponent <Mask>() == (UnityEngine.Object)null)
            {
                Material material = StencilMaterial.Add(baseMat, (1 << this.m_StencilValue) - 1, StencilOp.Keep, CompareFunction.Equal, ColorWriteMask.All, (1 << this.m_StencilValue) - 1, 0);
                StencilMaterial.Remove(this.m_MaskMaterial);
                this.m_MaskMaterial = material;
                baseMat             = this.m_MaskMaterial;
            }
            return(baseMat);
        }
Exemplo n.º 7
0
        public virtual Material GetModifiedMaterial(Material baseMaterial)
        {
            Material material = baseMaterial;

            if (m_ShouldRecalculateStencil)
            {
                Transform stopAfter = MaskUtilities.FindRootSortOverrideCanvas(base.transform);
                m_StencilValue             = (maskable ? MaskUtilities.GetStencilDepth(base.transform, stopAfter) : 0);
                m_ShouldRecalculateStencil = false;
            }
            if (m_StencilValue > 0 && GetComponent <Mask>() == null)
            {
                Material maskMaterial = StencilMaterial.Add(material, (1 << m_StencilValue) - 1, StencilOp.Keep, CompareFunction.Equal, ColorWriteMask.All, (1 << m_StencilValue) - 1, 0);
                StencilMaterial.Remove(m_MaskMaterial);
                m_MaskMaterial = maskMaterial;
                material       = m_MaskMaterial;
            }
            return(material);
        }
Exemplo n.º 8
0
        public virtual Material GetModifiedMaterial(Material baseMaterial)
        {
            Material baseMat = baseMaterial;

            if (this.m_ShouldRecalculateStencil)
            {
                Transform stopAfter = MaskUtilities.FindRootSortOverrideCanvas(base.transform);
                this.m_StencilValue             = !this.maskable ? 0 : MaskUtilities.GetStencilDepth(base.transform, stopAfter);
                this.m_ShouldRecalculateStencil = false;
            }
            if ((this.m_StencilValue > 0) && (base.GetComponent <Mask>() == null))
            {
                Material material2 = StencilMaterial.Add(baseMat, (((int)1) << this.m_StencilValue) - 1, StencilOp.Keep, CompareFunction.Equal, ColorWriteMask.All, (((int)1) << this.m_StencilValue) - 1, 0);
                StencilMaterial.Remove(this.m_MaskMaterial);
                this.m_MaskMaterial = material2;
                baseMat             = this.m_MaskMaterial;
            }
            return(baseMat);
        }
Exemplo n.º 9
0
        public virtual Material GetModifiedMaterial(Material baseMaterial)
        {
            if (this.graphic == null)
            {
                return(baseMaterial);
            }
            Transform stopAfter    = MaskUtilities.FindRootSortOverrideCanvas(base.transform);
            int       stencilDepth = MaskUtilities.GetStencilDepth(base.transform, stopAfter);

            if (stencilDepth >= 8)
            {
                Debug.LogError("Attempting to use a stencil mask with depth > 8", base.gameObject);
                return(baseMaterial);
            }
            int num2 = ((int)1) << stencilDepth;

            if (num2 == 1)
            {
                Material material = StencilMaterial.Add(baseMaterial, 1, StencilOp.Replace, CompareFunction.Always, !this.m_ShowMaskGraphic ? ((ColorWriteMask)0) : ColorWriteMask.All);
                StencilMaterial.Remove(this.m_MaskMaterial);
                this.m_MaskMaterial = material;
                Material material2 = StencilMaterial.Add(baseMaterial, 1, StencilOp.Zero, CompareFunction.Always, 0);
                StencilMaterial.Remove(this.m_UnmaskMaterial);
                this.m_UnmaskMaterial = material2;
                this.graphic.canvasRenderer.popMaterialCount = 1;
                this.graphic.canvasRenderer.SetPopMaterial(this.m_UnmaskMaterial, 0);
                return(this.m_MaskMaterial);
            }
            Material material3 = StencilMaterial.Add(baseMaterial, num2 | (num2 - 1), StencilOp.Replace, CompareFunction.Equal, !this.m_ShowMaskGraphic ? ((ColorWriteMask)0) : ColorWriteMask.All, num2 - 1, num2 | (num2 - 1));

            StencilMaterial.Remove(this.m_MaskMaterial);
            this.m_MaskMaterial = material3;
            this.graphic.canvasRenderer.hasPopInstruction = true;
            Material material4 = StencilMaterial.Add(baseMaterial, num2 - 1, StencilOp.Replace, CompareFunction.Equal, 0, num2 - 1, num2 | (num2 - 1));

            StencilMaterial.Remove(this.m_UnmaskMaterial);
            this.m_UnmaskMaterial = material4;
            this.graphic.canvasRenderer.popMaterialCount = 1;
            this.graphic.canvasRenderer.SetPopMaterial(this.m_UnmaskMaterial, 0);
            return(this.m_MaskMaterial);
        }
Exemplo n.º 10
0
        public virtual Material GetModifiedMaterial(Material baseMaterial)
        {
            Material material = baseMaterial;

            if (this.m_ShouldRecalculateStencil)
            {
                Transform stopAfter = MaskUtilities.FindRootSortOverrideCanvas(base.transform);
                this.m_StencilValue             = ((!this.maskable) ? 0 : MaskUtilities.GetStencilDepth(base.transform, stopAfter));
                this.m_ShouldRecalculateStencil = false;
            }
            Mask component = base.GetComponent <Mask>();

            if (this.m_StencilValue > 0 && (component == null || !component.IsActive()))
            {
                Material maskMaterial = StencilMaterial.Add(material, (1 << this.m_StencilValue) - 1, StencilOp.Keep, CompareFunction.Equal, ColorWriteMask.All, (1 << this.m_StencilValue) - 1, 0);
                StencilMaterial.Remove(this.m_MaskMaterial);
                this.m_MaskMaterial = maskMaterial;
                material            = this.m_MaskMaterial;
            }
            return(material);
        }
Exemplo n.º 11
0
        /// <summary>
        ///
        /// <para>
        /// See: IMaterialModifier.
        /// </para>
        ///
        /// </summary>
        /// <param name="baseMaterial"/>
        public virtual Material GetModifiedMaterial(Material baseMaterial)
        {
            if ((UnityEngine.Object) this.graphic == (UnityEngine.Object)null)
            {
                return(baseMaterial);
            }
            int stencilDepth = MaskUtilities.GetStencilDepth(this.transform, MaskUtilities.FindRootSortOverrideCanvas(this.transform));

            if (stencilDepth >= 8)
            {
                Debug.LogError((object)"Attempting to use a stencil mask with depth > 8", (UnityEngine.Object) this.gameObject);
                return(baseMaterial);
            }
            int num = 1 << stencilDepth;

            if (num == 1)
            {
                Material material1 = StencilMaterial.Add(baseMaterial, 1, StencilOp.Replace, CompareFunction.Always, !this.m_ShowMaskGraphic ? (ColorWriteMask)0 : ColorWriteMask.All);
                StencilMaterial.Remove(this.m_MaskMaterial);
                this.m_MaskMaterial = material1;
                Material material2 = StencilMaterial.Add(baseMaterial, 1, StencilOp.Zero, CompareFunction.Always, (ColorWriteMask)0);
                StencilMaterial.Remove(this.m_UnmaskMaterial);
                this.m_UnmaskMaterial = material2;
                this.graphic.canvasRenderer.popMaterialCount = 1;
                this.graphic.canvasRenderer.SetPopMaterial(this.m_UnmaskMaterial, 0);
                return(this.m_MaskMaterial);
            }
            Material material3 = StencilMaterial.Add(baseMaterial, num | num - 1, StencilOp.Replace, CompareFunction.Equal, !this.m_ShowMaskGraphic ? (ColorWriteMask)0 : ColorWriteMask.All, num - 1, num | num - 1);

            StencilMaterial.Remove(this.m_MaskMaterial);
            this.m_MaskMaterial = material3;
            this.graphic.canvasRenderer.hasPopInstruction = true;
            Material material4 = StencilMaterial.Add(baseMaterial, num - 1, StencilOp.Replace, CompareFunction.Equal, (ColorWriteMask)0, num - 1, num | num - 1);

            StencilMaterial.Remove(this.m_UnmaskMaterial);
            this.m_UnmaskMaterial = material4;
            this.graphic.canvasRenderer.popMaterialCount = 1;
            this.graphic.canvasRenderer.SetPopMaterial(this.m_UnmaskMaterial, 0);
            return(this.m_MaskMaterial);
        }
Exemplo n.º 12
0
        /// <summary>
        /// See IMaterialModifier.GetModifiedMaterial
        /// </summary>
        public virtual Material GetModifiedMaterial(Material baseMaterial)
        {
            var toUse = baseMaterial;

            if (m_ShouldRecalculateStencil)
            {
                var rootCanvas = MaskUtilities.FindRootSortOverrideCanvas(transform);
                m_StencilValue             = maskable ? MaskUtilities.GetStencilDepth(transform, rootCanvas) : 0;
                m_ShouldRecalculateStencil = false;
            }

            // if we have a enabled Mask component then it will
            // generate the mask material. This is an optimization
            // it adds some coupling between components though :(
            if (m_StencilValue > 0 && !isMaskingGraphic)
            {
                var maskMat = StencilMaterial.Add(toUse, (1 << m_StencilValue) - 1, StencilOp.Keep, CompareFunction.Equal, ColorWriteMask.All, (1 << m_StencilValue) - 1, 0);
                StencilMaterial.Remove(m_MaskMaterial);
                m_MaskMaterial = maskMat;
                toUse          = m_MaskMaterial;
            }
            return(toUse);
        }
Exemplo n.º 13
0
        /// Stencil calculation time!
        public override Material GetModifiedMaterial(Material baseMaterial)
        {
            if (graphic == null)
            {
                return(baseMaterial);
            }

            var rootSortCanvas = MaskUtilities.FindRootSortOverrideCanvas(transform);
            var stencilDepth   = MaskUtilities.GetStencilDepth(transform, rootSortCanvas);

            if (stencilDepth >= 8)
            {
                Debug.LogError("Attempting to use a stencil mask with depth > 8", gameObject);
                return(baseMaterial);
            }

            int desiredStencilBit = 1 << stencilDepth;

            // if we are at the first level...
            // we want to destroy what is there
            if (desiredStencilBit == 1)
            {
                var maskMaterial = StencilMaterial.Add(baseMaterial, 1, StencilOp.Replace, CompareFunction.Always, showMaskGraphic ? ColorWriteMask.All : 0);
                StencilMaterial.Remove(m_MaskMaterial);
                m_MaskMaterial = maskMaterial;
                return(m_MaskMaterial);
            }

            //otherwise we need to be a bit smarter and set some read / write masks
            var maskMaterial2 = StencilMaterial.Add(baseMaterial, desiredStencilBit | (desiredStencilBit - 1), StencilOp.Replace, CompareFunction.Equal, showMaskGraphic ? ColorWriteMask.All : 0, desiredStencilBit - 1, desiredStencilBit | (desiredStencilBit - 1));

            StencilMaterial.Remove(m_MaskMaterial);
            m_MaskMaterial = maskMaterial2;

            return(m_MaskMaterial);
        }
Exemplo n.º 14
0
 public static Material Add(Material baseMat, int stencilID, StencilOp operation, CompareFunction compareFunction, ColorWriteMask colorWriteMask)
 {
     return(StencilMaterial.Add(baseMat, stencilID, operation, compareFunction, colorWriteMask, (int)byte.MaxValue, (int)byte.MaxValue));
 }
Exemplo n.º 15
0
 private void ClearMaskMaterial()
 {
     StencilMaterial.Remove(m_MaskMaterial);
     m_MaskMaterial = null;
 }