示例#1
0
    private IEnumerator CreateOBJByName(string objName, string bundleName)
    {
        yield return(StartCoroutine(AssetBundleManager.DownloadAssetBundle(Path.Combine(AppConst.DataPath, "Streamingassets"), 0)));

        manifestBundle = AssetBundleManager.GetAssetBundle(Path.Combine(AppConst.DataPath, "Streamingassets"), 0);

        //AssetBundle abm = AssetBundle.LoadFromFile(AppConst.DataPath + "/StreamingAssets");
        manifest = (AssetBundleManifest)manifestBundle.LoadAsset("AssetBundleManifest");
        string[] depends = manifest.GetAllDependencies(bundleName);

        AssetBundle[] dependsAssetBundle = new AssetBundle[depends.Length];

        for (int i = 0; i < depends.Length; i++)
        {
            //dependsAssetBundle[i]=AssetBundle.LoadFromFile(AppConst.DataPath + "/"+ depends[i]);
            yield return(StartCoroutine(AssetBundleManager.DownloadAssetBundle(AppConst.DataPath + depends[i], 0)));

            dependsAssetBundle[i] = AssetBundleManager.GetAssetBundle(AppConst.DataPath + depends[i], 0);
        }

        yield return(StartCoroutine(AssetBundleManager.DownloadAssetBundle(AppConst.DataPath + bundleName, 0)));

        AssetBundle ab = AssetBundleManager.GetAssetBundle(AppConst.DataPath + bundleName, 0);

        //AssetBundle ab = AssetBundle.LoadFromFile(AppConst.DataPath + "/test.unity3d");
        if (ab)
        {
            GameObject obj = ab.LoadAsset <GameObject>("CharacterRobotBoy");
            Instantiate(obj);
        }
    }
示例#2
0
    private void CreateByBundleName(string objName, string bundleName, Action <UObject> func)
    {
        if (manifest == null)
        {
            manifestBundle = AssetBundle.LoadFromFile(Path.Combine(AppConst.DataPath, "StreamingAssets"));
            manifest       = (AssetBundleManifest)manifestBundle.LoadAsset("AssetBundleManifest");
        }

        string[] depends = manifest.GetAllDependencies(bundleName);

        for (int index = 0; index < depends.Length; index++)
        {
            //加载所有的依赖文件;
            StartCoroutine(AssetBundleManager.DownloadAssetBundle(AppConst.DataPath + depends[index], 0, null));
        }

        StartCoroutine(AssetBundleManager.DownloadAssetBundle(AppConst.DataPath + bundleName, 0,
                                                              x => {
            GameObject go = ((AssetBundle)x).LoadAsset <GameObject>(objName);
            if (func != null)
            {
                func(go);
            }
        }));
    }
        public static void LoadAssetBundle(string itemId, Hash128 version, Action <bool> callback)
        {
            Debug.Log("Load Asset: " + itemId);
            AssetBundleRef skinRef = new AssetBundleRef(TransferItemIdToBundleName(itemId), version);

            AssetBundleManager.DownloadAssetBundle(skinRef, callback);
            LastestLoadedSkinBundleName = skinRef.name;
        }
    IEnumerator DownloadAllAssetBundle()
    {
        yield return(StartCoroutine(AssetBundleManager.DownloadAssetBundle(prefabBundleURL, 0)));

        yield return(StartCoroutine(AssetBundleManager.DownloadAssetBundle(materialBundleURL, 0)));

        yield return(StartCoroutine(AssetBundleManager.DownloadAssetBundle(sceneBundleURL, 0)));
    }
    public void Retry()
    {
        // リトライボタンアクティブ
        retryBtn.SetActive(false);

        // その他有効化
        notice.text         = "NOW LOADING";
        count.enabled       = true;
        per.enabled         = true;
        progressImg.enabled = true;

        // ダウンロード開始
        AssetBundleManager.DownloadAssetBundle(bundleNames, OnDownloading);
    }
    // Use this for initialization
    void Start()
    {
        // AssetBundleキャッシュを削除
        if (isCleanCache)
        {
            Caching.ClearCache();
        }

        // ダウンロード開始 ====
        // 初期値設定
        AssetBundleManager.Initialize(baseURL);
        // ダウンロード開始
        AssetBundleManager.DownloadAssetBundle(bundleNames, OnDownloading);

        // リトライボタンを無効化
        retryBtn.SetActive(false);
        notice.text = "NOW LOADING";
    }
    private void OnGUI()
    {
        // 指定したアセットのダウンロード処理
        #region DOWNLOAD_ASSETBUNDLES
        if (GUILayout.Button("Download AssetBundles", GUILayout.MinWidth(256)))
        {
            // ダウンロード開始
            AssetBundleManager.DownloadAssetBundle(downloadAssetBundles, autoLoadAssetBundle, Downloading);
        }
        #endregion DOWNLOAD_ASSETBUNDLES


        // ダウンロードしたアセットのロード処理
        #region ASSETBUNDLE_LIST
        GUILayout.Label("Loaded AssetBundle List");
        List <string> bundleList = new List <string>();
        foreach (var bundle in AssetBundle.GetAllLoadedAssetBundles())
        {
            bundleList.Add(bundle.name);
        }
        if (bundleList.Count <= selGridInt)
        {
            selGridInt = bundleList.Count - 1;
        }
        selGridInt = GUILayout.SelectionGrid(selGridInt, bundleList.ToArray(), 2);
        #endregion ASSETBUNDLE_LIST


        // GameObjectのInstantiate
        #region PREFAB_INSTANTIATE
        GUILayout.Space(8);
        if (GUILayout.Button("Instantiate"))
        {
            // ロード処理
            string abName    = bundleList[selGridInt];
            string assetName = abName;
            if (assetName.Contains("/"))     // 子階層になっている場合
            {
                string[] n = assetName.Split('/');
                assetName = n[n.Length - 1];
            }
            else
            {
                assetName = abName;
            }
            GameObject go = AssetBundleManager.GetAsset <GameObject>(abName, assetName);

            // Instantiate
            InstantiateAsset(go);
        }
        #endregion PREFAB_INSTANTIATE


        // AssetBundleのUnload
        #region UNLOAD_ASSETBUNDLES
        if (GUILayout.Button("Unload"))
        {
            string name = bundleList[selGridInt];
            AssetBundleManager.Unload(name);
        }
        #endregion UNLOAD_ASSETBUNDLES

        // ログ
        #region OUTPUT_LOG
        GUILayout.Space(32);
        GUILayout.Box(output, GUILayout.Height(128));
        #endregion OUTPUT_LOG
    }