Пример #1
0
        private IEnumerator AsyncLoadCoroutine(string name, System.Type type)
        {
            string assetBundleName = GlobalSetting.ConvertToAssetBundleName(name);
            string url             = GlobalSetting.ConvertToFtpPath(assetBundleName);
            int    verNum          = GameApp.GetVersionNumber();

            WWW www = WWW.LoadFromCacheOrDownload(url, verNum);

            _dicLoadingReq.Add(name, www);
            while (www.isDone == false)
            {
                yield return(null);
            }
            AssetBundleRequest req = www.assetBundle.LoadAssetAsync(GetAssetName(name));

            while (req.isDone == false)
            {
                yield return(null);
            }

            _dicAsset.Add(name, req.asset);
            _dicLoadingReq.Remove(name);
            www.assetBundle.Unload(false);
            www = null;
        }
Пример #2
0
    // 加载表格
    public IEnumerator GetCSV()
    {
        // 用WWW读取配置表
        WWW www = new WWW(GlobalSetting.ConvertToAssetBundleName("BundleData.csv"));

        while (!www.isDone)
        {
            yield return(www);
        }
        CsvBundleData bundleCsv = new CsvBundleData(www.text);

        bundleCsv.ReadCsvFile();
        bundleDic = bundleCsv.CsvDataDic;

        //for (int i = 0; i < bundleDic.Count; i++)
        //{
        //    StartCoroutine(LoadAssetBundles(bundleDic[i].Type, typeof(GameObject)));
        //}
        //TextLog.text = "开始加载AssetBundle:" + "    " + Application.streamingAssetsPath + "                  " + GlobalSetting.getplatformfolder();

        StartCoroutine(LoadAssetBundles(bundleDic));
    }
Пример #3
0
    private IEnumerator LoadAssetBundles(Dictionary <int, CsvBundleBaseData> temDic)
    {
        foreach (int key in temDic.Keys)
        {
            string assetBundleName = temDic[key].BundleName;
            string url             = GlobalSetting.ConvertToAssetBundleName("streanmingassets/" + assetBundleName + ".bundle");

            Debug.Log("WWW AsyncLoad name =" + url + " versionNum = " + GlobalSetting.version);
            // 下载Bundle资源

            /*WWW www = WWW.LoadFromCacheOrDownload(url, GlobalSetting.version);
             *
             * dicLoadingReq.Add(bundleDic[key].BundleName, www);
             *
             *
             *
             *
             * while (!www.isDone)
             *  yield return www;
             *
             * if (string.IsNullOrEmpty(www.error) == false)
             * {
             *  Debug.Log(www.error);
             *  yield break;
             * }
             *
             * TextLog.text = "正在加载AssetBundle:" + " 未完成  ";
             * // 加载资源
             * AssetBundleRequest req = www.assetBundle.LoadAssetAsync(bundleDic[key].PrefabName, typeof(GameObject));
             * while (!req.isDone)
             *  yield return req;
             *
             * TextLog.text = "正在加载AssetBundle:" + " req  ";
             *
             *
             * AssetBundle temAb = www.assetBundle;
             *
             *
             *
             * //GameObject temObj = (req.asset as GameObject);
             * //DontDestroyOnLoad(temObj);
             * GameObject temObj = temAb.LoadAsset(bundleDic[key].BundleName) as GameObject;
             * sweetPrefabsDic.Add((GameManager.SweetType)key, temObj);
             * dicLoadingReq.Remove(bundleDic[key].BundleName);
             * www.assetBundle.Unload(false);
             * www.Dispose();
             * www = null;
             * Debug.Log("加载AssetBundle完成:" + bundleDic[key].BundleName);
             *
             * loadCount++;*/

            //AssetBundle bundle;
            //bundle = AssetBundle.LoadFromFile(Application.dataPath + "!assets/texture");

            //UnityEngine.Object obj = bundle.LoadAsset("Texture") as UnityEngine.Object;
            //GameObject go = Instantiate(obj, transform.position, Quaternion.identity) as GameObject;
            //bundle.Unload(false);

            //在Android上同步方法AssetBundle.LoadFromFile 就得用 Application.dataPath+”!assets”这个路径
            AssetBundle temAb     = AssetBundle.LoadFromFile(url);
            GameObject  temPrefab = temAb.LoadAsset(bundleDic[key].PrefabName) as GameObject;
            GameObject  temObj    = Instantiate(temPrefab, transform.position, transform.rotation);
            temObj.SetActive(false);
            DontDestroyOnLoad(temObj);
            sweetPrefabsDic.Add((GameManager.SweetType)key, temObj);
            loadCount++;
        }
        TextLog.text = "加载AssetBundle完成";
        yield return(null);

        if (loadCount == bundleDic.Count)
        {
            gameUI.SendMessage("ShowStartBtn");
        }
    }