我正在使用 vuforia 和 unity 创建一个增强现实应用程序。我已将我的assetbundle 上传到firebase 存储,我想检索保存在其中的3d 模型并将其作为子对象加载到我的图像目标游戏对象上,但我无法检索它。我还安装了firebase unity sdk。
using Firebase;
using Firebase.Storage;
using System.Threading.Tasks;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using System;
using UnityEngine.Networking;
using UnityEngine.UI;
public class loadmodel2 : MonoBehaviour
{
public GameObject test;
void Start()
{
FirebaseStorage storage = FirebaseStorage.DefaultInstance;
Firebase.Storage.StorageReference reference =storage.GetReferenceFromUrl("gs://fit-union-221609.appspot.com/assettest1/myasset");
reference.GetDownloadUrlAsync().ContinueWith((Task<Uri> task) => {
if (!task.IsFaulted && !task.IsCanceled)
{
Debug.Log("Download URL: " + task.Result);
// ... now download the file via WWW or UnityWebRequest.
StartCoroutine(Loadcoroutine());
}
});
}
IEnumerator Loadcoroutine()
{
string url = "gs://fit-union-221609.appspot.com/assettest1/myasset";
WWW www = new WWW(url);
while (!www.isDone)
yield return null;
AssetBundle myasset = www.assetBundle;
GameObject mya1 = myasset.LoadAsset("Barbarian Variant") as GameObject;
Instantiate(mya1).transform.parent = test.transform;
}
}
我创建了一个具有相同名称“myasset”的新资产包并将其上传到 firebase 存储我还将 3d 模型的名称更改为“BarbarianVariant”删除空间
在这里,我在主摄像头中启用了 loadmodel2 脚本,并为我分配主摄像头的测试游戏对象。您还可以在控制台中看到我得到的输出