Unity一键处理AssetBundle渲染bug

通过Assetbundle加装的场景或者物体会出现如下显示问题。

Unity一键处理AssetBundle渲染bug_第1张图片
Paste_Image.png

只需简单的代码就可以修复。

    [MenuItem("BabybusFrame/Utility/修复Shader")]
    private static void 修复Shader()
    {
        var renderers = Resources.FindObjectsOfTypeAll();
        if (renderers == null || renderers.Length == 0)
            return;

        foreach (var renderer in renderers)
        {
            if (AssetDatabase.GetAssetPath(renderer) != "")
                continue;

            foreach (var sharedMaterial in renderer.sharedMaterials)
            {
                if (sharedMaterial != null)
                    sharedMaterial.shader = Shader.Find(sharedMaterial.shader.name);
            }
        }

        var graphics = Resources.FindObjectsOfTypeAll();
        if (graphics == null || graphics.Length == 0)
            return;

        foreach (var graphic in graphics)
        {
            if (AssetDatabase.GetAssetPath(graphic) != "")
                continue;

            graphic.material.shader = Shader.Find(graphic.material.shader.name);
        }
    }
Unity一键处理AssetBundle渲染bug_第2张图片
Paste_Image.png

你可能感兴趣的:(Unity一键处理AssetBundle渲染bug)