当前位置:网站首页>Unity load AB package

Unity load AB package

2022-07-06 20:13:00 LiPing122335

Load asynchronously

using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.Networking;

public class LaodAB : MonoBehaviour {

    // Use this for initialization
    void Start () {
        StartCoroutine("LoadWed");
        //LoadFile();
    }

    void LoadFile()
    {// Local
        AssetBundle ab = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "my2"));
        GameObject go = ab.LoadAsset<GameObject>("Cube");
        GameObject g = Instantiate(go);
        //g.transform.SetParent(GameObject.Find("Canvas").transform, false);

    }
    IEnumerator LoadWed()
    {
        string uri = "file:///" + Application.dataPath + "/StreamingAssets/my2";
        UnityWebRequest request = UnityWebRequest.GetAssetBundle(uri);
        yield return request.Send();
        AssetBundle ab = DownloadHandlerAssetBundle.GetContent(request);
        //AssetBundle ab = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "my2"));
        GameObject go = ab.LoadAsset<GameObject>("Cube");
        GameObject g = Instantiate(go);
    }
    void Update () {
        
    }
}

原网站

版权声明
本文为[LiPing122335]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202131232205983.html