예제 #1
0
        /// <summary>
        /// 检查内存中是否存在AssetBundle或者是否有更新
        /// </summary>
        /// <param name="bundleName"></param>
        /// <returns></returns>
        private static bool CheckLocalBundle(string bundleName)
        {
            if (!System.IO.File.Exists(cacheAssetPath + bundleName))
            {
                Log.Info("本地不存在AssetBundle: " + bundleName);
                return(false);
            }

            BundleList.URLVersionPair serverInfo = m_ServerBundleList.SearchURL(bundleName);
            BundleList.URLVersionPair localInfo  = m_LocalBundleList.SearchURL(bundleName);

            if (serverInfo == null || localInfo == null)
            {
                Log.Info("本地AssetBundle: " + bundleName + " 不存在!");
                return(false);
            }

            if (serverInfo.hashCode != localInfo.hashCode)
            {
                Log.Info("本地AssetBundle: " + bundleName + " 有更新!");
                return(false);
            }

            return(true);
        }
예제 #2
0
        /// <summary>
        /// 保存本地的BundleList
        /// </summary>
        private static void SaveLocalBundleList(string bundleName)
        {
            BundleList.URLVersionPair serverInfo = m_ServerBundleList.SearchURL(bundleName);
            BundleList.URLVersionPair localInfo  = m_LocalBundleList.SearchURL(bundleName);
            if (serverInfo != null)
            {
                if (localInfo != null)
                {
                    m_LocalBundleList.bundles.Remove(localInfo);
                }
                m_LocalBundleList.bundles.Add(serverInfo);
            }

            SaveLocalBundleList();
        }
예제 #3
0
        /// <summary>
        /// 下载AssetBundle
        /// </summary>
        /// <param name="id"></param>
        /// <param name="aBundle"></param>
        /// <returns></returns>
        private static IEnumerator DownloadBundleComplete(int id, BundleList.URLVersionPair aBundle)
        {
#if UNITY_EDITOR
            if (usedAssetBundle)
            {
                yield break;
            }
#endif
            if (CheckLocalBundle(aBundle.bundleName))
            {
                LoadLocalBundle(aBundle.bundleName);
                yield break;
            }

            Log.Info("开始下载AssetBundle: " + aBundle.bundleName);
            m_MultiBusyDownloading[id] = true;
            while (true)
            {
                m_MultiDownloader[id] = new WWW(bundleBaseURL + aBundle.bundleName);
                yield return(m_MultiDownloader[id]);

                if (m_MultiDownloader[id].error == null)
                {
                    try
                    {
                        System.IO.File.WriteAllBytes(cacheAssetPath + aBundle.bundleName, m_MultiDownloader[id].bytes);
                        LoadLocalBundle(aBundle.bundleName, m_MultiDownloader[id].bytes);
                        SaveLocalBundleList(aBundle.bundleName);
                    }
                    catch (System.Exception e)
                    {
                        Log.Info(e.Message);
                    }
                    break;
                }
                else
                {
                    Log.Error(" 下载 AssetBundle 出错 " + aBundle.bundleName);
                }
            }

            ++m_CurrentPreDownloadNum;
            m_MultiBusyDownloading[id] = false;
        }