Unity의 AssetBundles 패키지 읽기

using UnityEngine;
using System.Collections;


public class RunScript : MonoBehaviour
{


    // StreamingAssets , 。
    public static readonly string PathURL =
#if UNITY_ANDROID
"jar:file://" + Application.dataPath + "!/assets/";
#elif UNITY_IPHONE
Application.dataPath + "/Raw/";
#elif UNITY_STANDALONE_WIN || UNITY_EDITOR
"file://" + Application.dataPath + "/StreamingAssets/";
#else
 string.Empty;
#endif


    public void OnClickSingleButton()
    {
         Caching.CleanCache();
        //StartCoroutine(Load(PathURL + "login.assetbundle"));
        StartCoroutine(LoadMainGameObject(PathURL + "Prefab1.assetbundle"));
        StartCoroutine(LoadMainGameObject(PathURL + "Prefab2.assetbundle"));
    }


    public void OnClickAllButton()
    {
        StartCoroutine(LoadALLGameObject(PathURL + "ALL.assetbundle"));
    }


    // 


    private IEnumerator LoadMainGameObject(string path)
    {
        WWW bundle = new WWW(path);
        yield return bundle;


        // 
        yield return Instantiate(bundle.assetBundle.mainAsset);
        bundle.assetBundle.Unload(false); 
    }








    //  
    IEnumerator Load(string path)
    {
        WWW bundle = WWW.LoadFromCacheOrDownload(path, 1);


        yield return bundle;
    }


    // 
    private IEnumerator LoadALLGameObject(string path)
    {
        WWW bundle = new WWW(path);


        yield return bundle;


        // ,   
        GameObject obj0 = (GameObject)bundle.assetBundle.LoadAsset("Prefab1");
        GameObject obj1 = (GameObject)bundle.assetBundle.LoadAsset("Prefab2");
        //  
        yield return Instantiate(obj0);
        yield return Instantiate(obj1);
        bundle.assetBundle.Unload(false);
    }


    private IEnumerator LoadMainCacheGameObject(string path)
    {
        WWW bundle = WWW.LoadFromCacheOrDownload(path, 5);


        yield return bundle;


        // 
        yield return Instantiate(bundle.assetBundle.mainAsset);


        bundle.assetBundle.Unload(false);
    }






}

좋은 웹페이지 즐겨찾기