Example #1
0
        /// <summary>
        /// Create a material for the sprite asset.
        /// </summary>
        /// <returns></returns>
        Material GetDefaultSpriteMaterial()
        {
            ShaderUtilities.GetShaderPropertyIDs();

            // Add a new material
            Shader   shader       = Shader.Find("TextMeshPro/Sprite");
            Material tempMaterial = new Material(shader);

            tempMaterial.SetTexture(ShaderUtilities.ID_MainTex, spriteSheet);
            tempMaterial.hideFlags = HideFlags.HideInHierarchy;

            return(tempMaterial);
        }
 static ShaderUtilities()
 {
     ShaderUtilities.Keyword_Bevel       = "BEVEL_ON";
     ShaderUtilities.Keyword_Glow        = "GLOW_ON";
     ShaderUtilities.Keyword_Underlay    = "UNDERLAY_ON";
     ShaderUtilities.Keyword_Ratios      = "RATIOS_OFF";
     ShaderUtilities.Keyword_MASK_SOFT   = "MASK_SOFT";
     ShaderUtilities.Keyword_MASK_HARD   = "MASK_HARD";
     ShaderUtilities.Keyword_MASK_TEX    = "MASK_TEX";
     ShaderUtilities.Keyword_Outline     = "OUTLINE_ON";
     ShaderUtilities.ShaderTag_ZTestMode = "unity_GUIZTestMode";
     ShaderUtilities.ShaderTag_CullMode  = "_CullMode";
     ShaderUtilities.m_clamp             = 1f;
     ShaderUtilities.GetShaderPropertyIDs();
 }
        public static float GetPadding(Material material, bool enableExtraPadding, bool isBold)
        {
            bool flag = !ShaderUtilities.isInitialized;

            if (flag)
            {
                ShaderUtilities.GetShaderPropertyIDs();
            }
            bool  flag2 = material == null;
            float result;

            if (flag2)
            {
                result = 0f;
            }
            else
            {
                int  num   = enableExtraPadding ? 4 : 0;
                bool flag3 = !material.HasProperty(ShaderUtilities.ID_GradientScale);
                if (flag3)
                {
                    result = (float)num;
                }
                else
                {
                    Vector4 vector = Vector4.zero;
                    Vector4 zero   = Vector4.zero;
                    float   num2   = 0f;
                    float   num3   = 0f;
                    float   num4   = 0f;
                    float   num5   = 0f;
                    float   num6   = 0f;
                    float   num7   = 0f;
                    float   num8   = 0f;
                    float   num9   = 0f;
                    ShaderUtilities.UpdateShaderRatios(material);
                    string[] shaderKeywords = material.shaderKeywords;
                    bool     flag4          = material.HasProperty(ShaderUtilities.ID_ScaleRatio_A);
                    if (flag4)
                    {
                        num5 = material.GetFloat(ShaderUtilities.ID_ScaleRatio_A);
                    }
                    bool flag5 = material.HasProperty(ShaderUtilities.ID_FaceDilate);
                    if (flag5)
                    {
                        num2 = material.GetFloat(ShaderUtilities.ID_FaceDilate) * num5;
                    }
                    bool flag6 = material.HasProperty(ShaderUtilities.ID_OutlineSoftness);
                    if (flag6)
                    {
                        num3 = material.GetFloat(ShaderUtilities.ID_OutlineSoftness) * num5;
                    }
                    bool flag7 = material.HasProperty(ShaderUtilities.ID_OutlineWidth);
                    if (flag7)
                    {
                        num4 = material.GetFloat(ShaderUtilities.ID_OutlineWidth) * num5;
                    }
                    float num10 = num4 + num3 + num2;
                    bool  flag8 = material.HasProperty(ShaderUtilities.ID_GlowOffset) && shaderKeywords.Contains(ShaderUtilities.Keyword_Glow);
                    if (flag8)
                    {
                        bool flag9 = material.HasProperty(ShaderUtilities.ID_ScaleRatio_B);
                        if (flag9)
                        {
                            num6 = material.GetFloat(ShaderUtilities.ID_ScaleRatio_B);
                        }
                        num8 = material.GetFloat(ShaderUtilities.ID_GlowOffset) * num6;
                        num9 = material.GetFloat(ShaderUtilities.ID_GlowOuter) * num6;
                    }
                    num10 = Mathf.Max(num10, num2 + num8 + num9);
                    bool flag10 = material.HasProperty(ShaderUtilities.ID_UnderlaySoftness) && shaderKeywords.Contains(ShaderUtilities.Keyword_Underlay);
                    if (flag10)
                    {
                        bool flag11 = material.HasProperty(ShaderUtilities.ID_ScaleRatio_C);
                        if (flag11)
                        {
                            num7 = material.GetFloat(ShaderUtilities.ID_ScaleRatio_C);
                        }
                        float num11 = material.GetFloat(ShaderUtilities.ID_UnderlayOffsetX) * num7;
                        float num12 = material.GetFloat(ShaderUtilities.ID_UnderlayOffsetY) * num7;
                        float num13 = material.GetFloat(ShaderUtilities.ID_UnderlayDilate) * num7;
                        float num14 = material.GetFloat(ShaderUtilities.ID_UnderlaySoftness) * num7;
                        vector.x = Mathf.Max(vector.x, num2 + num13 + num14 - num11);
                        vector.y = Mathf.Max(vector.y, num2 + num13 + num14 - num12);
                        vector.z = Mathf.Max(vector.z, num2 + num13 + num14 + num11);
                        vector.w = Mathf.Max(vector.w, num2 + num13 + num14 + num12);
                    }
                    vector.x  = Mathf.Max(vector.x, num10);
                    vector.y  = Mathf.Max(vector.y, num10);
                    vector.z  = Mathf.Max(vector.z, num10);
                    vector.w  = Mathf.Max(vector.w, num10);
                    vector.x += (float)num;
                    vector.y += (float)num;
                    vector.z += (float)num;
                    vector.w += (float)num;
                    vector.x  = Mathf.Min(vector.x, 1f);
                    vector.y  = Mathf.Min(vector.y, 1f);
                    vector.z  = Mathf.Min(vector.z, 1f);
                    vector.w  = Mathf.Min(vector.w, 1f);
                    zero.x    = ((zero.x < vector.x) ? vector.x : zero.x);
                    zero.y    = ((zero.y < vector.y) ? vector.y : zero.y);
                    zero.z    = ((zero.z < vector.z) ? vector.z : zero.z);
                    zero.w    = ((zero.w < vector.w) ? vector.w : zero.w);
                    float @float = material.GetFloat(ShaderUtilities.ID_GradientScale);
                    vector *= @float;
                    num10   = Mathf.Max(vector.x, vector.y);
                    num10   = Mathf.Max(vector.z, num10);
                    num10   = Mathf.Max(vector.w, num10);
                    result  = num10 + 0.5f;
                }
            }
            return(result);
        }