Beispiel #1
0
        public bool Load(string bundleName)
        {
            this.Begin();

            string bundlePath = AssetPath.LocalBundlePath(bundleName);

            byte[]            data = XFile.ReadBytesFile(bundlePath);
            Autarky.Signature sig_v3;
            if (Autarky.Load(ref data, out sig_v3))
            {
                try
                {
                    this.bundle = AssetBundle.LoadFromMemory(data);
                    this.done   = true;
                    return(true);
                }
                catch (System.Exception e)
                {
                    this.error = e.Message;
                    this.done  = true;
                    return(false);
                }
            }
            else
            {
                this.error = Autarky.error;
                this.done  = true;
                return(false);
            }
        }
Beispiel #2
0
        private IEnumerator DownloadAllAsync(string assetHostURL, List <string> bundleNames)
        {
            foreach (var bundleName in bundleNames)
            {
                string       url      = System.IO.Path.Combine(assetHostURL, bundleName + ".bundle");
                DownloadTask download = new DownloadTask(url);
                this.mDownloadList[bundleName] = download;
            }
            foreach (var bundleName in bundleNames)
            {
                DownloadTask download = null;
                this.mDownloadList.TryGetValue(bundleName, out download);
                if (download == null)
                {
                    continue;
                }
                yield return(download.Download());

                int count = 0;
                while (count <= 3 && !string.IsNullOrEmpty(download.www.error))
                {
                    count++;
                    yield return(download.Download());
                }

                if (!string.IsNullOrEmpty(download.www.error))
                {
                    Debug.LogError(download.www.error + "\n" + download.url);
                    yield break;
                }

                byte[]            data = download.www.bytes;
                Autarky.Signature sig_v3;
                if (Autarky.DecodeSignature(data, out sig_v3))
                {
                    BundleInfo info = null;
                    if (this.mAssetManifest.TryGetValue(bundleName, out info))
                    {
                        info.localVersion = sig_v3.version;
                    }
                    string localBundlePath = AssetPath.LocalBundlePath(bundleName);
                    if (System.IO.File.Exists(localBundlePath))
                    {
                        System.IO.File.Delete(localBundlePath);
                    }
                    XFile.WriteBytesFile(localBundlePath, data, 0, data.Length);
                    download.Done();
                    System.GC.Collect();
                }
                else
                {
                    Debug.LogErrorFormat(
                        "Bundle download successfully but file format is invalid. \n url : {0} \n bundleName : {1} \n error : {2}",
                        assetHostURL, bundleName, Autarky.error);
                }
            }
        }
Beispiel #3
0
 private bool GetBundleInfo(byte[] data, ref BundleInfo info)
 {
     Autarky.Signature sig_v3;
     if (Autarky.DecodeSignature(data, out sig_v3))
     {
         info.localVersion = sig_v3.version;
         return(true);
     }
     return(false);
 }
Beispiel #4
0
        private bool GetLocalBundleInfo(string bundleName, ref BundleInfo info)
        {
            string bundlePath = AssetPath.LocalBundlePath(bundleName);

            Autarky.Signature sig_v3;
            if (Autarky.DecodeSignature(bundlePath, out sig_v3))
            {
                info.localVersion = sig_v3.version;
                return(true);
            }

            return(false);
        }
Beispiel #5
0
        public IEnumerator LoadAsync(string bundleName)
        {
            this.Begin();

            string bundlePath = AssetPath.LocalBundlePath(bundleName);
            string bundleURI  = AssetPath.LocalBundleURI(bundleName);

            if (!System.IO.File.Exists(bundlePath))
            {
                bundleURI = AssetPath.StreamBundleURI(bundleName);
            }

            WWW www = new WWW(bundleURI);

            yield return(www);

            if (!string.IsNullOrEmpty(www.error))
            {
                this.error = www.error;
                this.done  = true;
                yield break;
            }

            byte[]            data = www.bytes;
            Autarky.Signature sig;
            if (Autarky.Load(ref data, out sig))
            {
                if (sig.enableEncrypt)
                {
                    var req = AssetBundle.LoadFromMemoryAsync(data);
                    yield return(req);

                    this.bundle = req.assetBundle;
                    this.done   = true;
                }
                else
                {
                    this.bundle = www.assetBundle;
                    this.done   = true;
                    yield break;
                }
            }
            else
            {
                this.error = Autarky.error;
                this.done  = true;
                yield break;
            }
        }