示例#1
0
        // 获得某组下的所有资源路径。慎用!因为没有跟远端version文件比对。
        public List <string> GetFilesInGroup(string groupName)
        {
            List <string> allFiles = new List <string>();

            if (localVersionFile == null)
            {
                TextAsset ta = Resources.Load <TextAsset>("versionfile/Version");//todo:有隐患,应该拿下载目录里的version文件
                this.localVersionFile = JsonConvert.DeserializeObject <VersionInfo>(ta.text);
            }

            VersionItemInfo item = null;

            if (localVersionFile.ResGroups.ContainsKey(groupName))
            {
                item = localVersionFile.ResGroups[groupName];
            }
            else
            {
                DebugUtil.LogError("grounName " + groupName + ", Not Exsits!");
                return(allFiles);
            }

            allFiles = localVersionFile.GetAssetBundlesByKey(groupName);
            return(allFiles);
        }
示例#2
0
        public void RefreshRemoteToLocal(List <string> files)
        {
            if (localVersionFile == null || remoteVersionFile == null)
            {
                DebugUtil.LogError("Version文件出错");
                return;
            }

            foreach (KeyValuePair <string, VersionItemInfo> kv in remoteVersionFile.ResGroups)
            {
                foreach (KeyValuePair <string, AssetBundleInfo> kv2 in kv.Value.AssetBundles)
                {
                    if (files.Contains(kv2.Key))
                    {
                        if (localVersionFile.ResGroups.ContainsKey(kv.Key))
                        {
                            AssetBundleInfo newABI = remoteVersionFile.ResGroups[kv.Key].AssetBundles[kv2.Key];
                            localVersionFile.ResGroups[kv.Key].Refresh(kv2.Key, newABI);
                        }
                        else
                        {
                            VersionItemInfo newVii = new VersionItemInfo
                            {
                                Version          = kv.Value.Version,
                                UpdateWholeGroup = kv.Value.UpdateWholeGroup
                            };
                            newVii.Refresh(kv2.Key, kv2.Value);
                            localVersionFile.Add(kv.Key, newVii);
                        }
                    }
                }
            }

            SaveVersionFile();
        }
示例#3
0
        public void RefreshRemoteToLocal(string groupName, string assetbundleName = null)
        {
            if (localVersionFile == null || remoteVersionFile == null)
            {
                DebugUtil.LogError("Version文件出错");
                return;
            }

            VersionItemInfo itemInfo = GetGroupVersion(groupName);

            if (itemInfo != null)
            {
                if (itemInfo.UpdateWholeGroup)
                {
                    localVersionFile.ResGroups[groupName].Refresh(remoteVersionFile.ResGroups[groupName].AssetBundles);
                    SaveVersionFile();
                }
                else
                {
                    if (assetbundleName == null || !remoteVersionFile.ResGroups[groupName].AssetBundles.ContainsKey(assetbundleName))
                    {
                        DebugUtil.LogError("远端没有资源:" + assetbundleName);
                        return;
                    }
                    AssetBundleInfo newABI = remoteVersionFile.ResGroups[groupName].AssetBundles[assetbundleName];
                    localVersionFile.ResGroups[groupName].Refresh(assetbundleName, newABI);
                    SaveVersionFile();
                }
            }
        }
 public void Add(string key, VersionItemInfo value)
 {
     if (this.ResGroups.ContainsKey(key))
     {
         DebugUtil.Log("资源组重名:" + key);
     }
     else
     {
         this.ResGroups.Add(key, value);
     }
 }
示例#5
0
        /// <summary>
        /// 通过组名,ab包名,获得需要下载的ab包
        /// </summary>
        /// <returns>The update files dict.[name,md5]</returns>
        /// <param name="groupName">Group name.</param>
        /// <param name="assetbundleName">Assetbundle name.</param>
        public Dictionary <string, string> GetUpdateFilesDict(string groupName, string assetbundleName = null)
        {
            Dictionary <string, string> updateFileNames = new Dictionary <string, string>();

            if (localVersionFile == null || remoteVersionFile == null)
            {
                DebugUtil.LogError("Version文件出错");
                return(updateFileNames);
            }

            VersionItemInfo item = null;

            if (localVersionFile.ResGroups.ContainsKey(groupName))
            {
                item = localVersionFile.ResGroups[groupName];
                if (item.UpdateWholeGroup)//强制更新整个组里的ab包
                {
                    List <string> remoteAB = remoteVersionFile.GetAssetBundlesByKey(groupName);
                    List <string> localAB  = localVersionFile.GetAssetBundlesByKey(groupName);

                    Dictionary <string, string> localFilesHash = new Dictionary <string, string>();
                    foreach (string assetname in localAB)
                    {
                        localFilesHash.Add(assetname, localVersionFile.GetAssetBundleHash(groupName, assetname));
                    }
                    foreach (string assetname in remoteAB)
                    {
                        string remoteHash = remoteVersionFile.GetAssetBundleHash(groupName, assetname);
                        string remoteMd5  = remoteVersionFile.GetAssetBundleMd5(groupName, assetname);
                        string localPath  = FilePathTools.GetBundleLoadPath(assetname);
                        if (localFilesHash.ContainsKey(assetname))
                        {
                            //添加“remoteState == AssetState.ExistInDownLoad”在于兼容ProtectMode
                            if (!File.Exists(localPath) || remoteHash.Trim() != localFilesHash[assetname].Trim())
                            {
                                updateFileNames.Add(assetname, remoteMd5);
                            }
                        }
                        else
                        {
                            updateFileNames.Add(assetname, remoteMd5);
                        }
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(assetbundleName))
                    {
                        string remoteName  = remoteVersionFile.GetAssetBundleByKeyAndName(groupName, assetbundleName);
                        string localName   = localVersionFile.GetAssetBundleByKeyAndName(groupName, assetbundleName);
                        string remoateHash = remoteVersionFile.GetAssetBundleHash(groupName, remoteName);
                        string remoateMd5  = remoteVersionFile.GetAssetBundleMd5(groupName, remoteName);
                        if (string.IsNullOrEmpty(localName))                 //本地没有
                        {
                            if (!string.IsNullOrEmpty(remoteName))           //远端有
                            {
                                updateFileNames.Add(remoteName, remoateMd5); //远端有,本地没有
                            }
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(remoteName))//本地有,远端有
                            {
                                // 比较两者的hash
                                string localHash = localVersionFile.GetAssetBundleHash(groupName, localName);
                                string localPath = FilePathTools.GetBundleLoadPath(localName);
                                if (!File.Exists(localPath) || localHash.Trim() != remoateHash.Trim())//hash不一样,要更新
                                {
                                    updateFileNames.Add(remoteName, remoateMd5);
                                }
                            }
                        }
                    }
                }
            }
            else
            {// 本地version文件不包含这个组,目前只发生在editor模式下,修复下。将来不一定。
                if (remoteVersionFile.ResGroups.ContainsKey(groupName))
                {
                    item = remoteVersionFile.ResGroups[groupName];
                    if (item.UpdateWholeGroup)
                    {
                        List <string> remoteAB = remoteVersionFile.GetAssetBundlesByKey(groupName);
                        foreach (string assetname in remoteAB)
                        {
                            string remoteMd5 = remoteVersionFile.GetAssetBundleMd5(groupName, assetname);
                            updateFileNames.Add(assetname, remoteMd5);
                        }
                    }
                    else
                    {
                        string remoteName = remoteVersionFile.GetAssetBundleByKeyAndName(groupName, assetbundleName);
                        string remoteMd5  = remoteVersionFile.GetAssetBundleMd5(groupName, remoteName);
                        if (!string.IsNullOrEmpty(remoteName))//远端有
                        {
                            updateFileNames.Add(remoteName, remoteMd5);
                        }
                    }
                }
                else
                {
                    DebugUtil.LogError("远端和本地的version文件都不包含:" + groupName);
                }
            }
            return(updateFileNames);
        }