Exemplo n.º 1
0
        public static void RemoveStencilMaterial(Material stencilMaterial)
        {
            int num = MaterialManager.m_materialList.FindIndex((MaterialManager.MaskingMaterial item) => item.stencilMaterial == stencilMaterial);

            if (num != -1)
            {
                MaterialManager.m_materialList.RemoveAt(num);
            }
            MaterialManager.ListMaterials();
        }
Exemplo n.º 2
0
        protected override void OnDisable()
        {
            //Debug.Log("*** SubObject OnDisable() ***");

            //m_canvasRenderer.Clear();
            TMP_UpdateRegistry.UnRegisterCanvasElementForRebuild(this);

            if (m_MaskMaterial != null)
            {
                MaterialManager.ReleaseStencilMaterial(m_MaskMaterial);
                m_MaskMaterial = null;
            }

            base.OnDisable();
        }
Exemplo n.º 3
0
        public static void ReleaseStencilMaterial(Material stencilMaterial)
        {
            int num = MaterialManager.m_materialList.FindIndex((MaterialManager.MaskingMaterial item) => item.stencilMaterial == stencilMaterial);

            if (num != -1)
            {
                if (MaterialManager.m_materialList.get_Item(num).count > 1)
                {
                    MaterialManager.m_materialList.get_Item(num).count--;
                }
                else
                {
                    Object.DestroyImmediate(MaterialManager.m_materialList.get_Item(num).stencilMaterial);
                    MaterialManager.m_materialList.RemoveAt(num);
                }
            }
            MaterialManager.ListMaterials();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Function returning the modified material for masking if necessary.
        /// </summary>
        /// <param name="baseMaterial"></param>
        /// <returns></returns>
        public override Material GetModifiedMaterial(Material baseMaterial)
        {
            Material mat = baseMaterial;

            if (m_ShouldRecalculateStencil)
            {
                m_StencilValue             = MaterialManager.GetStencilID(gameObject);
                m_ShouldRecalculateStencil = false;
            }

            if (m_StencilValue > 0)
            {
                mat = MaterialManager.GetStencilMaterial(baseMaterial, m_StencilValue);
                if (m_MaskMaterial != null)
                {
                    MaterialManager.ReleaseStencilMaterial(m_MaskMaterial);
                }

                m_MaskMaterial = mat;
            }

            return(mat);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Method called when Stencil Mask needs to be updated on this element and parents.
        /// </summary>
        public override void RecalculateMasking()
        {
            //Debug.Log("***** RecalculateMasking() *****");

            if (m_fontAsset == null)
            {
                return;
            }

            //if (m_canvas == null) m_canvas = GetComponentInParent<Canvas>();


            if (!m_isAwake)
            {
                return;
            }

            m_stencilID = MaterialManager.GetStencilID(gameObject);
            //m_stencilID = MaskUtilities.GetStencilDepth(this.transform, m_canvas.transform);
            //Debug.Log("Stencil ID: " + m_stencilID + "  Stencil ID (2): " + MaskUtilities.GetStencilDepth(this.transform, m_canvas.transform));

            if (m_stencilID == 0)
            {
                if (m_maskingMaterial != null)
                {
                    MaterialManager.ReleaseStencilMaterial(m_maskingMaterial);
                    m_maskingMaterial = null;

                    m_sharedMaterial = m_baseMaterial;
                }
                else if (m_fontMaterial != null)
                {
                    m_sharedMaterial = MaterialManager.SetStencil(m_fontMaterial, 0);
                }
                else
                {
                    m_sharedMaterial = m_baseMaterial;
                }
            }
            else
            {
                ShaderUtilities.GetShaderPropertyIDs();

                if (m_fontMaterial != null)
                {
                    m_sharedMaterial = MaterialManager.SetStencil(m_fontMaterial, m_stencilID);
                }
                else if (m_maskingMaterial == null)
                {
                    m_maskingMaterial = MaterialManager.GetStencilMaterial(m_baseMaterial, m_stencilID);
                    m_sharedMaterial  = m_maskingMaterial;
                }
                else if (m_maskingMaterial.GetInt(ShaderUtilities.ID_StencilID) != m_stencilID || m_isNewBaseMaterial)
                {
                    MaterialManager.ReleaseStencilMaterial(m_maskingMaterial);

                    m_maskingMaterial = MaterialManager.GetStencilMaterial(m_baseMaterial, m_stencilID);
                    m_sharedMaterial  = m_maskingMaterial;
                }


                if (m_isMaskingEnabled)
                {
                    EnableMasking();
                }

                //Debug.Log("Masking Enabled. Assigning " + m_maskingMaterial.name + " with ID " + m_maskingMaterial.GetInstanceID());
            }

            m_uiRenderer.SetMaterial(m_sharedMaterial, m_sharedMaterial.mainTexture);
            m_padding = ShaderUtilities.GetPadding(m_sharedMaterial, m_enableExtraPadding, m_isUsingBold);
            //m_alignmentPadding = ShaderUtilities.GetFontExtent(m_sharedMaterial);
        }
Exemplo n.º 6
0
        //public override Material defaultMaterial
        //{
        //    get { Debug.Log("Default Material called."); return m_sharedMaterial; }
        //}


        //public bool MaskEnabled()
        //{
        //    Debug.Log("MaskEnabled() called.");
        //    return true;
        //}


        public void ParentMaskStateChanged()
        {
            //Debug.Log("***** PARENT MASK STATE CHANGED *****");
            if (m_fontAsset == null)
            {
                return;
            }

            m_stencilID = MaterialManager.GetStencilID(gameObject);

            if (!m_isAwake)
            {
                return;
            }

            if (m_stencilID == 0)
            {
                if (m_maskingMaterial != null)
                {
                    MaterialManager.ReleaseStencilMaterial(m_maskingMaterial);
                    m_maskingMaterial = null;

                    m_sharedMaterial = m_baseMaterial;
                }
                else if (m_fontMaterial != null)
                {
                    m_sharedMaterial = MaterialManager.SetStencil(m_fontMaterial, 0);
                }
            }
            else
            {
                ShaderUtilities.GetShaderPropertyIDs();

                if (m_fontMaterial != null)
                {
                    m_sharedMaterial = MaterialManager.SetStencil(m_fontMaterial, m_stencilID);
                }
                else if (m_maskingMaterial == null)
                {
                    m_maskingMaterial = MaterialManager.GetStencilMaterial(m_baseMaterial, m_stencilID);
                    m_sharedMaterial  = m_maskingMaterial;
                }
                else if (m_maskingMaterial.GetInt(ShaderUtilities.ID_StencilID) != m_stencilID || m_isNewBaseMaterial)
                {
                    MaterialManager.ReleaseStencilMaterial(m_maskingMaterial);

                    m_maskingMaterial = MaterialManager.GetStencilMaterial(m_baseMaterial, m_stencilID);
                    m_sharedMaterial  = m_maskingMaterial;
                }


                if (m_isMaskingEnabled)
                {
                    EnableMasking();
                }

                //Debug.Log("Masking Enabled. Assigning " + m_maskingMaterial.name + " with ID " + m_maskingMaterial.GetInstanceID());
            }

            m_uiRenderer.SetMaterial(m_sharedMaterial, null);
            m_padding          = ShaderUtilities.GetPadding(m_sharedMaterial, m_enableExtraPadding, m_isUsingBold);
            m_alignmentPadding = ShaderUtilities.GetFontExtent(m_sharedMaterial);
        }