예제 #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
        }
예제 #2
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();
            }
        }