Esempio n. 1
0
        public static string CheckMaterial(Material mat, BuildTarget buildTarget)
        {
            if (mat == null || mat.shader == null)
            {
                return(null);
            }
            string shaderName = mat.shader.name;
            int    lOD        = ShaderUtil.GetLOD(mat.shader);
            bool   flag       = Array.Exists <string>(PerformanceChecks.kShadersWithMobileVariants, (string s) => s == shaderName);
            bool   flag2      = PerformanceChecks.IsMobileBuildTarget(buildTarget);

            if (buildTarget == BuildTarget.Android && ShaderUtil.HasClip(mat.shader))
            {
                return(PerformanceChecks.FormattedTextContent("PerformanceChecks.ShaderWithClipAndroid", new object[0]));
            }
            if (!(mat.GetTag("PerformanceChecks", true).ToLower() == "false"))
            {
                if (flag)
                {
                    if (flag2 && mat.HasProperty("_Color") && mat.GetColor("_Color") == new Color(1f, 1f, 1f, 1f))
                    {
                        return(PerformanceChecks.FormattedTextContent("PerformanceChecks.ShaderUsesWhiteColor", new object[]
                        {
                            "Mobile/" + shaderName
                        }));
                    }
                    if (flag2 && shaderName.StartsWith("Particles/"))
                    {
                        return(PerformanceChecks.FormattedTextContent("PerformanceChecks.ShaderHasMobileVariant", new object[]
                        {
                            "Mobile/" + shaderName
                        }));
                    }
                    if (shaderName == "RenderFX/Skybox" && mat.HasProperty("_Tint") && mat.GetColor("_Tint") == new Color(0.5f, 0.5f, 0.5f, 0.5f))
                    {
                        return(PerformanceChecks.FormattedTextContent("PerformanceChecks.ShaderMobileSkybox", new object[]
                        {
                            "Mobile/Skybox"
                        }));
                    }
                }
                if (lOD >= 300 && flag2 && !shaderName.StartsWith("Mobile/"))
                {
                    return(PerformanceChecks.FormattedTextContent("PerformanceChecks.ShaderExpensive", new object[0]));
                }
                if (shaderName.Contains("VertexLit") && mat.HasProperty("_Emission"))
                {
                    Color color = mat.GetColor("_Emission");
                    if (color.r >= 0.5f && color.g >= 0.5f && color.b >= 0.5f)
                    {
                        return(PerformanceChecks.FormattedTextContent("PerformanceChecks.ShaderUseUnlit", new object[0]));
                    }
                }
                if (mat.HasProperty("_BumpMap") && mat.GetTexture("_BumpMap") == null)
                {
                    return(PerformanceChecks.FormattedTextContent("PerformanceChecks.ShaderNoNormalMap", new object[0]));
                }
            }
            return(null);
        }
Esempio n. 2
0
        public static string CheckMaterial(Material mat, BuildTarget buildTarget)
        {
            // ISSUE: object of a compiler-generated type is created
            // ISSUE: variable of a compiler-generated type
            PerformanceChecks.\u003CCheckMaterial\u003Ec__AnonStoreyBE materialCAnonStoreyBe = new PerformanceChecks.\u003CCheckMaterial\u003Ec__AnonStoreyBE();
            if ((UnityEngine.Object)mat == (UnityEngine.Object)null || (UnityEngine.Object)mat.shader == (UnityEngine.Object)null)
            {
                return((string)null);
            }
            // ISSUE: reference to a compiler-generated field
            materialCAnonStoreyBe.shaderName = mat.shader.name;
            int lod = ShaderUtil.GetLOD(mat.shader);
            // ISSUE: reference to a compiler-generated method
            bool flag1 = Array.Exists <string>(PerformanceChecks.kShadersWithMobileVariants, new Predicate <string>(materialCAnonStoreyBe.\u003C\u003Em__22D));
            bool flag2 = PerformanceChecks.IsMobileBuildTarget(buildTarget);

            if (!(mat.GetTag("PerformanceChecks", true).ToLower() == "false"))
            {
                if (flag1)
                {
                    if (flag2 && mat.HasProperty("_Color") && mat.GetColor("_Color") == new Color(1f, 1f, 1f, 1f))
                    {
                        // ISSUE: reference to a compiler-generated field
                        return(PerformanceChecks.FormattedTextContent("Shader is using white color which does nothing; Consider using {0} shader for performance.", (object)("Mobile/" + materialCAnonStoreyBe.shaderName)));
                    }
                    // ISSUE: reference to a compiler-generated field
                    if (flag2 && materialCAnonStoreyBe.shaderName.StartsWith("Particles/"))
                    {
                        // ISSUE: reference to a compiler-generated field
                        return(PerformanceChecks.FormattedTextContent("Consider using {0} shader on this platform for performance.", (object)("Mobile/" + materialCAnonStoreyBe.shaderName)));
                    }
                    // ISSUE: reference to a compiler-generated field
                    if (materialCAnonStoreyBe.shaderName == "RenderFX/Skybox" && mat.HasProperty("_Tint") && mat.GetColor("_Tint") == new Color(0.5f, 0.5f, 0.5f, 0.5f))
                    {
                        return(PerformanceChecks.FormattedTextContent("Skybox shader is using gray color which does nothing; Consider using {0} shader for performance.", (object)"Mobile/Skybox"));
                    }
                }
                // ISSUE: reference to a compiler-generated field
                if (lod >= 300 && flag2 && !materialCAnonStoreyBe.shaderName.StartsWith("Mobile/"))
                {
                    return(PerformanceChecks.FormattedTextContent("Shader might be expensive on this platform. Consider switching to a simpler shader; look under Mobile shaders."));
                }
                // ISSUE: reference to a compiler-generated field
                if (materialCAnonStoreyBe.shaderName.Contains("VertexLit") && mat.HasProperty("_Emission"))
                {
                    Color color = mat.GetColor("_Emission");
                    if ((double)color.r >= 0.5 && (double)color.g >= 0.5 && (double)color.b >= 0.5)
                    {
                        return(PerformanceChecks.FormattedTextContent("Looks like you're using VertexLit shader to simulate an unlit object (white emissive). Use one of Unlit shaders instead for performance."));
                    }
                }
                if (mat.HasProperty("_BumpMap") && (UnityEngine.Object)mat.GetTexture("_BumpMap") == (UnityEngine.Object)null)
                {
                    return(PerformanceChecks.FormattedTextContent("Normal mapped shader without a normal map. Consider using a non-normal mapped shader for performance."));
                }
            }
            return((string)null);
        }
        public static string CheckMaterial(Material mat, BuildTarget buildTarget)
        {
            if (mat == null || mat.shader == null)
            {
                return(null);
            }
            string shaderName = mat.shader.name;
            int    lOD        = ShaderUtil.GetLOD(mat.shader);
            bool   flag       = Array.Exists <string>(PerformanceChecks.kShadersWithMobileVariants, (string s) => s == shaderName);
            bool   flag2      = PerformanceChecks.IsMobileBuildTarget(buildTarget);

            if (!(mat.GetTag("PerformanceChecks", true).ToLower() == "false"))
            {
                if (flag)
                {
                    if (flag2 && mat.HasProperty("_Color") && mat.GetColor("_Color") == new Color(1f, 1f, 1f, 1f))
                    {
                        return(PerformanceChecks.FormattedTextContent("Shader is using white color which does nothing; Consider using {0} shader for performance.", new object[]
                        {
                            "Mobile/" + shaderName
                        }));
                    }
                    if (flag2 && shaderName.StartsWith("Particles/"))
                    {
                        return(PerformanceChecks.FormattedTextContent("Consider using {0} shader on this platform for performance.", new object[]
                        {
                            "Mobile/" + shaderName
                        }));
                    }
                    if (shaderName == "RenderFX/Skybox" && mat.HasProperty("_Tint") && mat.GetColor("_Tint") == new Color(0.5f, 0.5f, 0.5f, 0.5f))
                    {
                        return(PerformanceChecks.FormattedTextContent("Skybox shader is using gray color which does nothing; Consider using {0} shader for performance.", new object[]
                        {
                            "Mobile/Skybox"
                        }));
                    }
                }
                if (lOD >= 300 && flag2 && !shaderName.StartsWith("Mobile/"))
                {
                    return(PerformanceChecks.FormattedTextContent("Shader might be expensive on this platform. Consider switching to a simpler shader; look under Mobile shaders.", new object[0]));
                }
                if (shaderName.Contains("VertexLit") && mat.HasProperty("_Emission"))
                {
                    Color color = mat.GetColor("_Emission");
                    if (color.r >= 0.5f && color.g >= 0.5f && color.b >= 0.5f)
                    {
                        return(PerformanceChecks.FormattedTextContent("Looks like you're using VertexLit shader to simulate an unlit object (white emissive). Use one of Unlit shaders instead for performance.", new object[0]));
                    }
                }
                if (mat.HasProperty("_BumpMap") && mat.GetTexture("_BumpMap") == null)
                {
                    return(PerformanceChecks.FormattedTextContent("Normal mapped shader without a normal map. Consider using a non-normal mapped shader for performance.", new object[0]));
                }
            }
            return(null);
        }