Exemple #1
0
        // Event received when custom material editor properties are changed.
        void ON_MATERIAL_PROPERTY_CHANGED(bool isChanged, Material mat)
        {
            //Debug.Log("*** ON_MATERIAL_PROPERTY_CHANGED ***");
            int targetMaterialID         = mat.GetInstanceID();
            int sharedMaterialID         = m_sharedMaterial.GetInstanceID();
            int fallbackSourceMaterialID = m_fallbackSourceMaterial == null ? 0 : m_fallbackSourceMaterial.GetInstanceID();

            // Filter events and return if the affected material is not this object's material.
            if (targetMaterialID != sharedMaterialID)
            {
                // Check if event applies to the source fallback material
                if (m_fallbackMaterial != null && fallbackSourceMaterialID == targetMaterialID)
                {
                    TMP_MaterialManager.CopyMaterialPresetProperties(mat, m_fallbackMaterial);
                }
                else
                {
                    return;
                }
            }

            if (m_TextComponent == null)
            {
                m_TextComponent = GetComponentInParent <TextMeshPro>();
            }

            m_padding = GetPaddingForMaterial();

            m_TextComponent.havePropertiesChanged = true;
            m_TextComponent.SetVerticesDirty();
        }
Exemple #2
0
        private void ON_MATERIAL_PROPERTY_CHANGED(bool isChanged, Material mat)
        {
            int instanceID  = mat.GetInstanceID();
            int instanceID2 = m_sharedMaterial.GetInstanceID();
            int num         = (!(base.m_MaskMaterial == null)) ? base.m_MaskMaterial.GetInstanceID() : 0;
            int num2        = (!(m_fallbackSourceMaterial == null)) ? m_fallbackSourceMaterial.GetInstanceID() : 0;

            if (m_fallbackMaterial != null && num2 == instanceID)
            {
                TMP_MaterialManager.CopyMaterialPresetProperties(mat, m_fallbackMaterial);
            }
            if ((UnityEngine.Object)(object) m_TextComponent == null)
            {
                m_TextComponent = base.GetComponentInParent <TextMeshProUGUI>();
            }
            if (base.m_MaskMaterial != null)
            {
#if UNITY_EDITOR
                /*Undo.RecordObject(base.m_MaskMaterial, "Material Property Changes");
                 * Undo.RecordObject(m_sharedMaterial, "Material Property Changes");*/
#endif
                if (instanceID == instanceID2)
                {
                    float @float = base.m_MaskMaterial.GetFloat(ShaderUtilities.ID_StencilID);
                    float float2 = base.m_MaskMaterial.GetFloat(ShaderUtilities.ID_StencilComp);
                    base.m_MaskMaterial.CopyPropertiesFromMaterial(mat);
                    base.m_MaskMaterial.shaderKeywords = mat.shaderKeywords;
                    base.m_MaskMaterial.SetFloat(ShaderUtilities.ID_StencilID, @float);
                    base.m_MaskMaterial.SetFloat(ShaderUtilities.ID_StencilComp, float2);
                }
                else if (instanceID == num)
                {
                    GetPaddingForMaterial(mat);
                    m_sharedMaterial.CopyPropertiesFromMaterial(mat);
                    m_sharedMaterial.shaderKeywords = mat.shaderKeywords;
                    m_sharedMaterial.SetFloat(ShaderUtilities.ID_StencilID, 0f);
                    m_sharedMaterial.SetFloat(ShaderUtilities.ID_StencilComp, 8f);
                }
                else if (num2 == instanceID)
                {
                    float float3 = base.m_MaskMaterial.GetFloat(ShaderUtilities.ID_StencilID);
                    float float4 = base.m_MaskMaterial.GetFloat(ShaderUtilities.ID_StencilComp);
                    base.m_MaskMaterial.CopyPropertiesFromMaterial(m_fallbackMaterial);
                    base.m_MaskMaterial.shaderKeywords = m_fallbackMaterial.shaderKeywords;
                    base.m_MaskMaterial.SetFloat(ShaderUtilities.ID_StencilID, float3);
                    base.m_MaskMaterial.SetFloat(ShaderUtilities.ID_StencilComp, float4);
                }
            }
            m_padding = GetPaddingForMaterial();
            SetVerticesDirty();
            base.m_ShouldRecalculateStencil = true;
            //((MaskableGraphic)this).RecalculateClipping();
            RecalculateClipping();
            //((MaskableGraphic)this).RecalculateMasking();
            RecalculateMasking();
        }
        // Event received when custom material editor properties are changed.
        void ON_MATERIAL_PROPERTY_CHANGED(bool isChanged, Material mat)
        {
            //Debug.Log("*** ON_MATERIAL_PROPERTY_CHANGED ***");
            if (m_sharedMaterial == null)
            {
                return;
            }

            int targetMaterialID         = mat.GetInstanceID();
            int sharedMaterialID         = m_sharedMaterial.GetInstanceID();
            int fallbackSourceMaterialID = m_fallbackSourceMaterial == null ? 0 : m_fallbackSourceMaterial.GetInstanceID();

            // Sync culling with parent text object
            bool  hasCullModeProperty = m_sharedMaterial.HasProperty(ShaderUtilities.ShaderTag_CullMode);
            float cullMode            = 0;

            if (hasCullModeProperty)
            {
                cullMode = textComponent.fontSharedMaterial.GetFloat(ShaderUtilities.ShaderTag_CullMode);
                m_sharedMaterial.SetFloat(ShaderUtilities.ShaderTag_CullMode, cullMode);
            }

            // Filter events and return if the affected material is not this object's material.
            if (targetMaterialID != sharedMaterialID)
            {
                // Check if event applies to the source fallback material
                if (m_fallbackMaterial != null && fallbackSourceMaterialID == targetMaterialID && TMP_Settings.matchMaterialPreset)
                {
                    TMP_MaterialManager.CopyMaterialPresetProperties(mat, m_fallbackMaterial);

                    // Re-sync culling with parent text object
                    if (hasCullModeProperty)
                    {
                        m_fallbackMaterial.SetFloat(ShaderUtilities.ShaderTag_CullMode, cullMode);
                    }
                }
                else
                {
                    return;
                }
            }

            m_padding = GetPaddingForMaterial();

            m_TextComponent.havePropertiesChanged = true;
            m_TextComponent.SetVerticesDirty();
        }
Exemple #4
0
        private void ON_MATERIAL_PROPERTY_CHANGED(bool isChanged, Material mat)
        {
            int instanceID  = mat.GetInstanceID();
            int instanceID2 = m_sharedMaterial.GetInstanceID();
            int num         = (!(m_fallbackSourceMaterial == null)) ? m_fallbackSourceMaterial.GetInstanceID() : 0;

            if (instanceID != instanceID2)
            {
                if (!(m_fallbackMaterial != null) || num != instanceID)
                {
                    return;
                }
                TMP_MaterialManager.CopyMaterialPresetProperties(mat, m_fallbackMaterial);
            }
            if ((UnityEngine.Object)(object) m_TextComponent == null)
            {
                m_TextComponent = GetComponentInParent <TextMeshPro>();
            }
            m_padding = GetPaddingForMaterial();
            m_TextComponent.havePropertiesChanged = true;
            ((Graphic)m_TextComponent).SetVerticesDirty();
        }
        // Event received when custom material editor properties are changed.
        void ON_MATERIAL_PROPERTY_CHANGED(bool isChanged, Material mat)
        {
            //Debug.Log("*** ON_MATERIAL_PROPERTY_CHANGED ***");

            int targetMaterialID         = mat.GetInstanceID();
            int sharedMaterialID         = m_sharedMaterial.GetInstanceID();
            int maskingMaterialID        = m_MaskMaterial == null ? 0 : m_MaskMaterial.GetInstanceID();
            int fallbackSourceMaterialID = m_fallbackSourceMaterial == null ? 0 : m_fallbackSourceMaterial.GetInstanceID();

            // Filter events and return if the affected material is not this object's material.
            //if (targetMaterialID != sharedMaterialID && targetMaterialID != maskingMaterialID) return;

            // Filter events and return if the affected material is not this object's material.
            if (m_fallbackMaterial != null && fallbackSourceMaterialID == targetMaterialID)
            {
                TMP_MaterialManager.CopyMaterialPresetProperties(mat, m_fallbackMaterial);
            }

            if (m_TextComponent == null)
            {
                m_TextComponent = GetComponentInParent <TextMeshProUGUI>();
            }

            // Make sure material properties are synchronized between the assigned material and masking material.
            if (m_MaskMaterial != null)
            {
                UnityEditor.Undo.RecordObject(m_MaskMaterial, "Material Property Changes");
                UnityEditor.Undo.RecordObject(m_sharedMaterial, "Material Property Changes");

                if (targetMaterialID == sharedMaterialID)
                {
                    //Debug.Log("Copy base material properties to masking material if not null.");
                    float stencilID   = m_MaskMaterial.GetFloat(ShaderUtilities.ID_StencilID);
                    float stencilComp = m_MaskMaterial.GetFloat(ShaderUtilities.ID_StencilComp);
                    m_MaskMaterial.CopyPropertiesFromMaterial(mat);
                    m_MaskMaterial.shaderKeywords = mat.shaderKeywords;

                    m_MaskMaterial.SetFloat(ShaderUtilities.ID_StencilID, stencilID);
                    m_MaskMaterial.SetFloat(ShaderUtilities.ID_StencilComp, stencilComp);
                }
                else if (targetMaterialID == maskingMaterialID)
                {
                    // Update the padding
                    GetPaddingForMaterial(mat);

                    m_sharedMaterial.CopyPropertiesFromMaterial(mat);
                    m_sharedMaterial.shaderKeywords = mat.shaderKeywords;
                    m_sharedMaterial.SetFloat(ShaderUtilities.ID_StencilID, 0);
                    m_sharedMaterial.SetFloat(ShaderUtilities.ID_StencilComp, 8);
                }
                else if (fallbackSourceMaterialID == targetMaterialID)
                {
                    float stencilID   = m_MaskMaterial.GetFloat(ShaderUtilities.ID_StencilID);
                    float stencilComp = m_MaskMaterial.GetFloat(ShaderUtilities.ID_StencilComp);
                    m_MaskMaterial.CopyPropertiesFromMaterial(m_fallbackMaterial);
                    m_MaskMaterial.shaderKeywords = m_fallbackMaterial.shaderKeywords;

                    m_MaskMaterial.SetFloat(ShaderUtilities.ID_StencilID, stencilID);
                    m_MaskMaterial.SetFloat(ShaderUtilities.ID_StencilComp, stencilComp);
                }
            }

            m_padding = GetPaddingForMaterial();

            SetVerticesDirty();
            m_ShouldRecalculateStencil = true;
            RecalculateClipping();
            RecalculateMasking();
        }