Ejemplo n.º 1
0
        /// <summary>
        /// 对比两个BundleInfo
        /// </summary>
        /// <param name="localBundleInfo"></param>
        /// <param name="serverBundleInfo"></param>
        /// <returns></returns>
        public static string[] Compare(tagBundleInfo localBundleInfo, tagBundleInfo serverBundleInfo)
        {
            // 本地BundleInfo可以为空,但是服务器的一定存在
            if (serverBundleInfo == null)
            {
                Debug.LogError("serverBundleInfo cannot be null!");
                return(null);
            }

            List <string> toUpdateList = new List <string>();

            // 遍历服务器包信息,hashcode有变化或者本地没有的包都需要更新
            Dictionary <string, tagOneBundleInfo> .Enumerator serverItor = serverBundleInfo.m_allBundleInfo.GetEnumerator();
            while (serverItor.MoveNext())
            {
                string serverBundleName = serverItor.Current.Value.strABName;
                //string servercrc = serverItor.Current.Value.crc;
                string  serverHashcode = serverItor.Current.Value.strHashcode;
                Hash128 serverHash     = Hash128.Parse(serverHashcode);
                if (serverHash.isValid == false)
                {
                    Debug.LogError("Parse Hash128 failed, string: " + serverHashcode);
                }

                if (localBundleInfo == null ||
                    !localBundleInfo.m_allBundleInfo.ContainsKey(serverBundleName) ||
                    localBundleInfo.m_allBundleInfo[serverBundleName].strHashcode != serverHashcode)
                {
                    toUpdateList.Add(serverBundleName);
                }
            }

            return(toUpdateList.ToArray());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 加载bundleInfo
        /// </summary>
        /// <param name="buffer"></param>
        /// <returns></returns>
        public tagBundleInfo LoadBundleInfo(byte[] buffer)
        {
            tagBundleInfo bundleInfo = new tagBundleInfo();

            bundleInfo.Init(buffer);

            return(bundleInfo);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 重新加载bundleinfo
        /// </summary>
        /// <param name="strPath"></param>
        /// <returns></returns>
        public tagBundleInfo ReloadBundleInfo(string strPath)
        {
            tagBundleInfo bundleInfo = _LoadBundleInfo(strPath, "bundleinfo");

            m_dicBundleInfos[strPath] = bundleInfo;

            return(bundleInfo);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 获取bundleinfo
        /// </summary>
        /// <param name="strPath"></param>
        /// <returns></returns>
        public tagBundleInfo GetBundleInfo(string strPath)
        {
            if (m_dicBundleInfos == null)
            {
                return(null);
            }

            if (m_dicBundleInfos.ContainsKey(strPath))
            {
                return(m_dicBundleInfos[strPath]);
            }
            else
            {
                tagBundleInfo bundleInfo = _LoadBundleInfo(strPath, "bundleinfo");
                m_dicBundleInfos[strPath] = bundleInfo;

                return(bundleInfo);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 加载bundleInfo
        /// </summary>
        /// <param name="strPath"></param>
        /// <returns></returns>
        private tagBundleInfo _LoadBundleInfo(string strPath, string strAssetName)
        {
            // 加载并初始化bundleInfo包
            AssetBundle assetBundle = AssetBundle.LoadFromFile(strPath + strAssetName);

            if (assetBundle != null)
            {
                TextAsset text = assetBundle.LoadAsset <TextAsset>(strAssetName);
                if (text != null)
                {
                    tagBundleInfo bundleInfo = new tagBundleInfo();
                    bundleInfo.Init(text.bytes);
                    assetBundle.Unload(true);
                    return(bundleInfo);
                }
            }

            Debug.LogError("加载bundleInfo失败,path:" + strPath);
            return(null);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 对比版本文件
        /// </summary>
        /// <returns></returns>
        private string[] _CompareBundleInfo()
        {
            string[] toUpdateAssetBundleNames = null;

            if (AssetBundleInfoManager.IsExits() == false)
            {
                return(null);
            }

            // 读取下载路径上的版本文件
            tagBundleInfo localBundleInfo = AssetBundleInfoManager.GetSingel().GetBundleInfo(AssetBundleManager.Instance.itfDownloadPath);

            if (localBundleInfo != null)
            {
                return(tagBundleInfo.Compare(localBundleInfo, m_serverBundleInfo));
            }

            // 读取包内路径上的版本文件
            localBundleInfo = AssetBundleInfoManager.GetSingel().GetBundleInfo(AssetBundleManager.Instance.itfStreamingPath);
            if (localBundleInfo != null)
            {
                return(tagBundleInfo.Compare(localBundleInfo, m_serverBundleInfo));
            }

            //if (toUpdateAssetBundleNames != null
            //    && toUpdateAssetBundleNames.Length != 0)
            //{
            //    // begin download!
            //    for (int i = 0; i < toUpdateAssetBundleNames.Length; i++)
            //    {
            //        Debug.Log("Compare: " + toUpdateAssetBundleNames[i]);
            //    }
            //}

            Debug.Log("local BundleInfo is null!");

            return(toUpdateAssetBundleNames);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 实际使用www下载包的地方
        /// </summary>
        /// <param name="strABName"></param>
        /// <returns></returns>
        private IEnumerator _DownloadAssetBundleInternal(string strABName, bool isBundleInfoFile = false)
        {
            WWW    download = null;
            string url      = m_strBaseDownloadingURL + strABName;

            Debug.Log(url);
            download = new WWW(url);
            yield return(download);

            if (download.error != null)
            {
                Debug.LogError(download.error);
                yield break;
            }

            if (download.isDone &&
                download.assetBundle != null)
            {
                if (isBundleInfoFile == true &&
                    AssetBundleInfoManager.IsExits())
                {
                    //解决乱码问题将下载的bundleinfo 字节流按照assetbundle的方式加载 而不是直接使用字节流
                    AssetBundle.UnloadAllAssetBundles(false); //这里是因为在某个地方已经加载了本地的bundleinfo ,如果不释放掉就不能加载刚刚下下来的这个buffer(暂时还没找到)
                    AssetBundle bundleinfo = AssetBundle.LoadFromMemory(download.bytes);
                    // AssetBundle bundleinfo = bundleinfoRe.assetBundle;
                    if (bundleinfo != null)
                    {
                        TextAsset text = bundleinfo.LoadAsset <TextAsset>("bundleinfo");
                        if (text != null)
                        {
                            m_serverBundleInfo = AssetBundleInfoManager.GetSingel().LoadBundleInfo(text.bytes);
                        }
                    }
                    bundleinfo.Unload(true);
                    // _SaveFile(strABName, download.bytes);
                }

                //如果是bundleinfo的话不应该是直接用字节流去读取数据因为这个字节流是元始的喂解密的bundle字节流
                // _SaveServerInfoAndLoad(strABName, download.bytes);

                else
                {
                    _SaveFile(strABName, download.bytes);
                }

                //包加载成功立即卸载,只需要缓存到本地即可
                if (download.assetBundle != null)
                {
                    download.assetBundle.Unload(false);
                }
                Debug.Log("download " + strABName + " bundle succeed!");
            }
            else
            {
                //包加载失败
                Debug.LogError("assetBundle:" + strABName + " is invalid!");
            }

            //也可以不调用Dispose,unity会在适当的时候释放www资源,如果dispose正在下载的资源,有极大问题,可能崩溃
            //download.Dispose();
        }