unity_优化Unity高级进阶教程Unity技术分享

Unity一键处理AssetBundle渲染bug

2016-10-18  本文已影响325人  2b75747cf703

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

Paste_Image.png

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

    [MenuItem("BabybusFrame/Utility/修复Shader")]
    private static void 修复Shader()
    {
        var renderers = Resources.FindObjectsOfTypeAll<Renderer>();
        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<Graphic>();
        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);
        }
    }
Paste_Image.png
上一篇 下一篇

猜你喜欢

热点阅读