我正在使用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脚本,并为我分配了maincamera的测试游戏对象启用了脚本。您还可以在控制台中看到我得到的输出