/// <summary> /// 添加MainManifest对象. /// </summary> public void AddMainManifestAssetsTarget() { var manifestBundleId = AssetBundleDirNameOfNormal; if (string.IsNullOrEmpty(manifestBundleId)) { return; } var path = GetLocalBundleFilePath( manifestBundleId, BundleFileType.MainManifest, false); if (File.Exists(path) == false) { return; } var item = new BundleMap { id = manifestBundleId, type = BundleType.Normal }; var index = path.IndexOf(manifestBundleId, StringComparison.Ordinal); item.path = path.Substring(0, index); // 添加对象 AddTarget(item, BundleFileType.MainManifest); }
/// <summary> /// 判断目标存不存在. /// </summary> /// <returns><c>true</c>, 存在, <c>false</c> 不存在.</returns> /// <param name="iTargetId">目标ID.</param> /// <param name="iTarget">目标.</param> private bool IsTargetExist(string iTargetId, out BundleMap iTarget) { iTarget = null; foreach (var loop in Maps) { if (loop.id.Equals(iTargetId) != true) { continue; } iTarget = loop; return(true); } return(false); }
/// <summary> /// 目标是否改变了. /// </summary> /// <returns><c>true</c>, 已改变, <c>false</c> 未改变.</returns> /// <param name="iNewTarget">新目标.</param> /// <param name="iOldTarget">旧目标</param> private bool IsTargetChanged(BundleMap iNewTarget, ref BundleMap iOldTarget) { iOldTarget = null; var isExist = IsTargetExist(iNewTarget.id, out iOldTarget); if (isExist) { // Type if (iOldTarget.type != iNewTarget.type) { return(true); } // AssetPath if (false == iOldTarget.path.Equals(iNewTarget.path)) { return(true); } // Targets if (iOldTarget.targets.Count != iNewTarget.targets.Count) { return(true); } foreach (var newPath in iNewTarget.targets) { var isExistTmp = false; foreach (var path in iOldTarget.targets) { if (!newPath.Equals(path)) { continue; } isExistTmp = true; break; } if (false == isExistTmp) { return(true); } } } else { return(true); } return(false); }
/// <summary> /// 取得或者创建一个BundleMap对象. /// </summary> /// <returns>BundleMap对象.</returns> /// <param name="iBundleId">BundleId.</param> public static BundleMap GetOrCreateBundlesMap(string iBundleId) { BundleMap objRet; if (GetInstance().IsTargetExist(iBundleId, out objRet)) { if (objRet == null) { objRet = new BundleMap(); } } else { objRet = new BundleMap(); } return(objRet); }
/// <summary> /// 添加对象. /// </summary> /// <param name="iTarget">对象.</param> /// <param name="iFileType">上传文件类型.</param> /// <param name="iHashCode">HashCode(Unity3d打包生成).</param> public void AddTarget( BundleMap iTarget, BundleFileType iFileType, string iHashCode = null) { if (iTarget == null) { return; } BundlesResultItem item; var filePath = GetLocalBundleFilePath( iTarget.id, iFileType, (BundleType.Scene == iTarget.type)); string checkCode = null; string dataSize = null; if (false == string.IsNullOrEmpty(filePath) && File.Exists(filePath)) { checkCode = CheckMode.Unity3dHash128 == CheckMode ? iHashCode : UtilsTools.GetMd5ByFilePath(filePath); var fileInfo = new FileInfo(filePath); dataSize = fileInfo.Length.ToString(); } else { this.Warning("AddTarget()::Target File is not exist!!!(ProjectName:{0})", filePath); } var exist = IsTargetExist(iTarget.id, iFileType, out item); if (false == exist) { item = CreateBundleItem(iTarget.id, iTarget.type, iFileType); item.checkCode = checkCode; item.dataSize = dataSize; } else { if (false == string.IsNullOrEmpty(checkCode) && false == checkCode.Equals(item.checkCode)) { item.checkCode = checkCode; item.dataSize = dataSize; item.uploaded = false; } } UtilsAsset.SetAssetDirty(this); }
/// <summary> /// 合并目标. /// </summary> /// <param name="iNewTarget">I new ProjectName.</param> private void MergeTarget(BundleMap iNewTarget) { BundleMap oldTarget = null; var isChanged = IsTargetChanged(iNewTarget, ref oldTarget); if (true != isChanged) { return; } if (null == oldTarget) { Maps.Add(iNewTarget); } else { oldTarget.type = iNewTarget.type; oldTarget.path = iNewTarget.path; foreach (var newPath in iNewTarget.targets) { var isExist = false; foreach (var path in oldTarget.targets) { if (true != newPath.Equals(path)) { continue; } isExist = true; break; } if (false == isExist) { oldTarget.targets.Add(newPath); } } } }