我一直试图解决这个问题好几天了,我不确定如何 . 首先,我正在创建具有预制件的AssetBundles和带有纹理的GameObjects . 在构建AssetBundle之后,它被上传到服务器,在另一个Android应用程序中,我检索它并卸载其资产 . 在Unity编辑器“游戏视图”中一切正常,但在Android手机上,动态游戏对象的纹理显示为黑色 . 静态纹理,就像我用于背景的纹理一样,通常出现在编辑器和Android设备上 . 看似黑色的纹理是我从AssetBundles中检索到的纹理 .

当我搜索它时,我发现了这些建议:

首先,我拖放纹理的图像,然后使用此函数自动压缩:

// Automatically Compress all imported textures to the project to ETC_RGBA
void OnPreprocessTexture(Texture2D t)
{
    EditorUtility.CompressTexture(t, TextureFormat.ETC_RGBA8_3DS, TextureCompressionQuality.Normal);
}

然后我在编辑器中手动将纹理添加到3D GameObject并创建一个预制件并将GameObject添加到其中 . 我将预制本身,材料和图像添加到AssetBundle并执行此操作以导出AssetBundle :(现在AssetBundle总共包含3个资产 . 我将其上传到服务器)

//Creates a new menu (Build Asset Bundles) and item (Normal) in the Editor
[MenuItem("Assets/Build Asset Bundles/Normal")]
static void BuildABsNone()
{
    BuildPipeline.BuildAssetBundles("Assets/AssetBundle", BuildAssetBundleOptions.None, BuildTarget.Android);
}

在应用程序中,我从服务器动态加载AssetBundle,我想使用Vuforia在ImageTarget上显示它 . 这是CloudHandler类中IEnumerator DownloadAndCache()函数的一部分,它加载材质资源并实例化GameObject "mBundleInstance" . 然后我在图像目标上显示"mBundleInstance":

bundle = www.assetBundle;

            var materials = bundle.LoadAllAssets(typeof(Material));
            containsMaterial = (materials.Length > 0);

            if (AssetName == "")
            {
                mBundleInstance = Instantiate(getMainAsset(bundle)) as GameObject;
            }
            else
            { 
                mBundleInstance = Instantiate(bundle.LoadAsset(AssetName, typeof(GameObject))) as GameObject;
            }
            Debug.Log(mBundleInstance.GetComponent<Renderer>().material.mainTexture.name);
            //returns the correct name of the compressed png image
            if (containsMaterial)
            {
                foreach (Material m in materials)
                {
                    var shaderName = "Standard";
                    var newShader = Shader.Find(shaderName);

                    if (newShader != null)
                    {
                        m.shader = newShader;

                        mBundleInstance.GetComponent<Renderer>().material = m;
                        Debug.Log("actual texture name: " + mBundleInstance.GetComponent<Renderer>().material.mainTexture.name);
                        //returns the correct name of the png image
                    }
                    else
                    {
                        Debug.LogWarning("unable to refresh shader: " + shaderName + " in material " + m.name);
                    }
                 }
              }

以下是编辑器GameView中的样子:Texture of GameObject appears: (The King of Diamonds image)

这就是它在Android设备上的样子:Texture of Gameobject does not appear.

由于没有明显的错误,我不确定为什么会发生这种错误 . 任何帮助或建议为什么会发生这种情况或我可以做些什么来解决它?