从Firebase存储到统一的负载负荷资产

问题描述 投票:0回答:1

我正在使用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
{
// Start is called before the first frame update
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;




}


}

this is what i want

firebase unity3d firebase-storage unitywebrequest
1个回答
0
投票

我不是Firebase专家,但是为什么您首先使用GetReference,然后却从不使用它,而是启动一个新的UnityWebRequest从该URL下载它?您是否不想使用从task.Result中检索到的下载URL,例如

StartCoroutine(Loadcoroutine(task.Result));

...

IEnumerator Loadcoroutine(string URL)
{
    ...
}

然后注意WWW!= UnityWebRequest

您想做的可能是使用UnityWebRequest.GetAssetBundle

UnityWebRequest.GetAssetBundle
© www.soinside.com 2019 - 2024. All rights reserved.