Esempio n. 1
0
        void LoadAssetBundleSync(AssetBundleContainer bundle, string url, int version, uint crc)
        {
            var realpath = Path.GetDirectoryName(url) + "/" + url.Substring(AssetBundleLoader.GetStreamingAssetsURL("").Length).Replace('/', '_');

// #if UNITY_ANDROID && !UNITY_EDITOR
//             //GetNextEntry    assets/Controller/MainPlayer.unity3d
//             //url             jar:file:///data/app/com.base.mayatest-1.apk!/assets/Controller/MainPlayer.unity3d
//
//             var apkPath = Application.dataPath;
//             var filepath = realpath.Substring(realpath.IndexOf("assets/"));
//             var filestream = new FileStream(apkPath, FileMode.Open, FileAccess.Read);
//             var zipfile = new ZipFile(filestream);
//             var item = zipfile.GetEntry(filepath);
//             if (null != item)
//             {
//                 var stream = zipfile.GetInputStream(item);
//                 byte[] buffer = new byte[stream.Length];
//                 stream.Read(buffer, 0, buffer.Length);
//                 AssetBundle assetBundle = AssetBundle.CreateFromMemoryImmediate(buffer);
//                 BundleAssetList list = null;
//                 list = assetBundle.Load("list", typeof(BundleAssetList)) as BundleAssetList;
//                 bundle.Initialize(realpath, assetBundle, list ? list.Assets : null);
//             }
//             else
//             {
//                 Logger.Error("get file from apk error !:" + realpath);
//             }
// #else
            // path = Application.dataPath + "/Raw";  IOS
            // path = Application.dataPath + "/StreamingAssets"; PC
            var path = realpath.Substring(realpath.IndexOf("file://") + 7);

            if (File.Exists(path))
            {
                var    stream = File.OpenRead(path);
                byte[] buffer = new byte[stream.Length];
                stream.Read(buffer, 0, buffer.Length);
                AssetBundle     assetBundle = AssetBundle.CreateFromMemoryImmediate(buffer);
                BundleAssetList list        = null;
                list = assetBundle.Load("list", typeof(BundleAssetList)) as BundleAssetList;
                bundle.Initialize(realpath, assetBundle, list ? list.Assets : null);
            }
            else
            {
                Logger.Error("get file error !:" + path);
            }
//#endif
        }
Esempio n. 2
0
 /// <summary>
 /// Unload assetbundle
 /// </summary>
 /// <param name="assetbundle">Assetbundle</param>
 public void UnloadBundle(AssetBundleContainer assetbundle)
 {
     if (assetbundle != null)
     {
         if (!string.IsNullOrEmpty(assetbundle.Name))
         {
             this.UnloadBundle(assetbundle.Name);
         }
         else
         {
             // for debug
             if (assetbundle.AssetBundle)
             {
                 assetbundle.AssetBundle.Unload(false);
             }
         }
     }
 }
        IEnumerator LoadAssetBundle(AssetBundleContainer bundle, string url, int version, uint crc)
        {
            WWW www = null;

            if (0 <= version)
            {
                www = WWW.LoadFromCacheOrDownload(url, version, crc);
            }
            else
            {
                www = new WWW(url);
            }

            while (!www.isDone)
            {
                bundle.Progress = www.progress;
                yield return(9);
            }

            if (www.error != null)
            {
                Debug.LogError(string.Format("AssetBundleManager:\n\tload \"{0}\" error:{1}", url, www.error));
                bundle.Initialize(url, null, null);
                bundle.SetError(www.error);
            }
            else
            {
                BundleAssetInfo[] list = null;
                if (!www.assetBundle.isStreamedSceneAssetBundle)
                {
                    if (Application.HasProLicense())
                    {
#if UNITY_5
                        var request = www.assetBundle.LoadAssetAsync <BundleAssetList>("list");
#else
                        var request = www.assetBundle.LoadAsync("list", typeof(BundleAssetList));
#endif
                        yield return(request);

                        var bal = request.asset as BundleAssetList;
                        list = bal.Assets;
                    }
                    else
                    {
#if UNITY_5
                        var bal = www.assetBundle.LoadAsset <BundleAssetList>("list");
#else
                        var bal = www.assetBundle.Load("list", typeof(BundleAssetList)) as BundleAssetList;
#endif
                        list = bal.Assets;
                    }
                }
                else
                {
                    var paths = www.assetBundle.GetAllScenePaths();
                    list = new BundleAssetInfo[paths.Length];
                    for (int i = 0; i < paths.Length; ++i)
                    {
                        list[i] = new BundleAssetInfo(paths[i]);
                    }
                }
                if (list != null)
                {
                    bundle.Initialize(url, www.assetBundle, list);
                }
                else
                {
                    //Debug.LogWarning( "There is no BundleAssetList in " + www.url );
                    bundle.Initialize(url, www.assetBundle, null);
                }
            }
            if (www != null)
            {
                www.Dispose();
            }
        }
Esempio n. 4
0
        IEnumerator LoadAssetBundle(AssetBundleContainer bundle, string url, int version, uint crc)
        {
            WWW www = null;

            var path = Path.Combine(Path.GetDirectoryName(url), url.Substring(AssetBundleLoader.GetStreamingAssetsURL("").Length).Replace('/', '_'));

            path = path.Replace("\\", "/");

            if (0 <= version)
            {
                www = WWW.LoadFromCacheOrDownload(path, version, crc);
            }
            else
            {
                www = new WWW(path);
            }
            yield return(www);

            if (www.error != null)
            {
                Debug.Log(string.Format("AssetBundleManager:\n\tload \"{0}\" error:{1}", path, www.error));
                bundle.Initialize(path, null, null);
                bundle.SetError(www.error);
            }
            else
            {
                BundleAssetList list = null;
                if (Application.HasProLicense())
                {
#if UNITY_5
                    var request = www.assetBundle.LoadAssetAsync <BundleAssetList>("list");
#else
                    var request = www.assetBundle.LoadAsync("list", typeof(BundleAssetList));
#endif
                    yield return(request);

                    list = request.asset as BundleAssetList;
                }
                else
                {
#if UNITY_5
                    list = www.assetBundle.LoadAsset <BundleAssetList>("list");
#else
                    list = www.assetBundle.Load("list", typeof(BundleAssetList)) as BundleAssetList;
#endif
                }
                if (list)
                {
                    bundle.Initialize(path, www.assetBundle, list.Assets);
                }
                else
                {
                    //Debug.LogWarning( "There is no BundleAssetList in " + www.url );
                    bundle.Initialize(path, www.assetBundle, null);
                }
            }
            if (www != null)
            {
                www.Dispose();
            }
        }