static void PackageRelyPackage(EditPackageConfig package) { //BuildPipeline.PushAssetDependencies(); if (package.objects.Count == 0) { Debug.LogError(package.name + " 没有资源!"); } Object[] res = new Object[package.objects.Count]; for (int i = 0; i < package.objects.Count; i++) { res[i] = package.objects[i].obj; } string path = GetExportPath(package.path, package.name); FileTool.CreatFilePath(path); if (package.isCollectDependencies) { BuildPipeline.BuildAssetBundle(null, res, path, relyBuildOption, GetTargetPlatform); } else { BuildAssetBundleOptions bbo = BuildAssetBundleOptions.DeterministicAssetBundle; BuildPipeline.BuildAssetBundle(null, res, path, bbo, GetTargetPlatform); } }
bool GetIsShowByRelyMask(EditPackageConfig package) { if (RelyMaskFilter == -1) { return(true); } if (RelyMaskFilter == 0) { if (package.relyPackagesMask == 0) { return(true); } else { return(false); } } if ((package.relyPackagesMask & RelyMaskFilter) != 0) { return(true); } else { return(false); } }
/// <summary> /// 检查依赖包中有没有重复资源 /// </summary> /// <param name="pack"></param> void CheckRelyRepeatRes(EditPackageConfig pack) { for (int i = 0; i < pack.objects.Count; i++) { string resNameTmp = CustomToString(pack.objects[i].obj); EditorObject tmp = pack.objects[i]; if (checkDict.ContainsKey(resNameTmp)) { if (isExist_EditorList(checkDict[resNameTmp], tmp)) { pack.warnMsg.Add("Objects存在重复资源 ! " + resNameTmp); warnCount++; } else { checkDict[resNameTmp].Add(tmp); } } else { checkDict.Add(resNameTmp, new List <EditorObject>()); checkDict[resNameTmp].Add(tmp); } } }
/// <summary> /// 检查依赖包是否是无资源 /// </summary> void CheckRelyPackagesEmptyRes(EditPackageConfig pack) { if (pack.objects.Count == 0) { pack.errorMsg.Add(pack.name + " 依赖包无资源 !"); errorCount++; } }
/// <summary> /// 判断某个资源是否 /// </summary> /// <param name="pack"></param> /// <param name="res"></param> /// <returns></returns> bool GetResIsUseByMainObject(EditPackageConfig pack, EditorObject res) { if (EqualsEditorObject(pack.mainObject, res)) { return(true); } return(false); }
void ObjectListView(EditPackageConfig pack) { EditorGUILayout.LabelField("Size: " + pack.objects.Count); for (int j = 0; j < pack.objects.Count; j++) { EditorGUILayout.LabelField("Path:", pack.objects[j].path); EditorGUILayout.BeginHorizontal(); EditorGUILayout.ObjectField(pack.objects[j].obj, typeof(Object), false); if (GUILayout.Button("删除", GUILayout.Width(ButtonWidth))) { pack.objects.RemoveAt(j); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); } EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Button:"); if (GUILayout.Button("增加选中资源")) { Object[] selects = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets); for (int k = 0; k < selects.Length; k++) { EditorObject tmp = new EditorObject(); tmp.obj = selects[k]; tmp.path = GetObjectPath(selects[k]); if (!isExist_EditorList(pack.objects, tmp)) { pack.objects.Add(tmp); } else { Debug.Log(CustomToString(selects[k]) + " has Exists"); } } } if (GUILayout.Button("打印所有依赖资源")) { for (int i = 0; i < pack.objects.Count; i++) { Object[] objs = GetCorrelationResource(pack.objects[i].obj); for (int j = 0; j < objs.Length; j++) { Debug.Log(pack.objects[i].obj + " -> " + objs[j]); } } } EditorGUILayout.EndHorizontal(); }
//消息视图 void MessageView(EditPackageConfig package) { for (int i = 0; i < package.errorMsg.Count; i++) { EditorGUILayout.LabelField("ERROR: " + package.errorMsg[i], EditorGUIStyleData.ErrorMessageLabel); } for (int i = 0; i < package.warnMsg.Count; i++) { EditorGUILayout.LabelField("WARN: " + package.warnMsg[i], EditorGUIStyleData.WarnMessageLabel); } }
bool GetIsFitsBundleQuery(EditPackageConfig package) { if (bundleQuery == "") { return(true); } //大小写不敏感 string nameLower = package.name.ToLower(); return(nameLower.Contains(bundleQuery.ToLower())); }
//重新加载Object static void ReLoadGameObject(EditPackageConfig pack) { if (pack.mainObject != null) { ReLoadEditObject(pack.mainObject); } for (int i = 0; i < pack.objects.Count; i++) { ReLoadEditObject(pack.objects[i]); } }
/// <summary> /// 检查单个包有没有丢失资源 /// </summary> /// <param name="pack"></param> void CheckMissRes(EditPackageConfig pack) { for (int i = 0; i < pack.objects.Count; i++) { if (pack.objects[i].obj == null) { Debug.LogError(pack.name + " " + i + "号资源丢失!"); pack.errorMsg.Add(i + "号资源丢失!"); errorCount++; } } //将来加入资源缺失检测 if (pack.mainObject == null) { Debug.LogError(pack.name + "没有主资源!"); pack.errorMsg.Add("没有主资源!"); errorCount++; return; } Object[] res = GetCorrelationResource(pack.mainObject.obj); for (int i = 0; i < res.Length; i++) { if (res[i] == null) { pack.warnMsg.Add(pack.mainObject.path + " 有丢失的脚本!"); warnCount++; continue; } //查找其他资源是否有掉材质球问题 List <string> resLostList = FindLostRes(res[i]); for (int j = 0; j < resLostList.Count; j++) { pack.warnMsg.Add(resLostList[j]); warnCount++; } //EditorObject tmp = new EditorObject(); //tmp.obj = res[i]; //tmp.path = GetObjectPath(res[i]); //if (!GetResIsUse(pack, tmp) && !ComponentFilter(res[i])) //{ // pack.errorMsg.Add( CustomToString(res[i]) + " 资源丢失依赖!"); // errorCount++; //} } }
/// <summary> /// 显示Resource子Resources的子目录和子文件 /// </summary> /// <param name="pathPoint"></param> /// <param name="n_level"></param> void ShowSubFolderBundle(PathPoint pathPoint, int n_level) { if (pathPoint.s_nowPathPoint != null) { //文件夹节点 EditorGUI.indentLevel = n_level; pathPoint.isFold = EditorGUILayout.Foldout(pathPoint.isFold, "<folder> " + pathPoint.s_nowPathPoint); if (pathPoint.isFold) { if (pathPoint.nextPathPoint != null) { foreach (var nextPathPoint in pathPoint.nextPathPoint) { ShowSubFolderBundle(nextPathPoint.Value, (n_level + 1)); } } if (pathPoint.bundles != null) { for (int i = 0; i < pathPoint.bundles.Count; i++) { EditPackageConfig bundle = pathPoint.bundles[i]; //bundle节点 EditorGUI.indentLevel = n_level + 1; EditorGUILayout.BeginHorizontal(); bundle.isFold = EditorGUILayout.Foldout(bundle.isFold, bundle.name); //删除视图 if (GUILayout.Button("删除", GUILayout.Width(ButtonWidth))) { bundles.Remove(bundle); pathPoint.bundles.Remove(bundle); continue; } EditorGUILayout.EndHorizontal(); if (bundle.isFold) { ShowSingleBundleGUI(bundle, n_level + 1); } EditorGUI.indentLevel = n_level + 2; //消息视图 MessageView(bundle); } } } } }
/// <summary> /// 检查单个资源是否全都被其依赖包引用 /// </summary> bool GetResIsUseByRelyBundle(EditPackageConfig pack, EditorObject res) { //根据mask获取所有依赖包 List <EditPackageConfig> relysBundles = GetRelyPackListByMask(pack.relyPackagesMask); for (int i = 0; i < relysBundles.Count; i++) { if (isExist_Bundle(res, relysBundles[i])) { return(true); } } return(false); }
void ShowSingleBundleGUI(EditPackageConfig bundle, int l_foldIndex) { EditorGUILayout.BeginVertical(); EditorGUI.indentLevel = l_foldIndex + 1; if (bundle.mainObject != null && bundle.mainObject.obj != null) { bundle.name = bundle.mainObject.obj.name; } else { bundle.name = "Null"; } //主资源 EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("主资源:"); EditorGUILayout.ObjectField(bundle.mainObject.obj, typeof(Object), false); if (GUILayout.Button("重新打包", GUILayout.Width(ButtonWidth))) { PackageService.PackageBundle(bundle); } EditorGUILayout.EndHorizontal(); //依赖包 EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("依赖包:"); bundle.relyPackagesMask = EditorGUILayout.MaskField(bundle.relyPackagesMask, RelyPackageNames); EditorGUILayout.EndHorizontal(); //Debug.Log(" bundles[i].relyPackagesMask: " + bundles[i].relyPackagesMask); //加载路径 EditorGUILayout.LabelField("路径: ", bundle.path); bundle.isFold_objects = EditorGUILayout.Foldout(bundle.isFold_objects, "Objects"); //子资源视图 EditorGUI.indentLevel = l_foldIndex + 2; if (bundle.isFold_objects) { ObjectListView(bundle); } EditorGUILayout.EndVertical(); }
//整理资源路径 private void ArrangeBundlesByLayer() { allBundlesLayerInfo = new PathPoint(); allBundlesLayerInfo.s_nowPathPoint = "Resourse"; allBundlesLayerInfo.lastPathPoint = null; allBundlesLayerInfo.nextPathPoint = new Dictionary <string, PathPoint>(); allBundlesLayerInfo.bundles = null; for (int i = 0; i < bundles.Count; i++) { EditPackageConfig nowBundle = bundles[i]; string s_bundlePath = nowBundle.path; string[] t_pathPoints = s_bundlePath.Split('/'); int n_nowPoints = 0; PathPoint endPathPoint = allBundlesLayerInfo; while (n_nowPoints < t_pathPoints.Length - 1) { //如果下一个节点中没有需要的节点 if (endPathPoint.nextPathPoint.ContainsKey(t_pathPoints[n_nowPoints]) == false) { PathPoint nextPoint = new PathPoint(); nextPoint.s_nowPathPoint = t_pathPoints[n_nowPoints]; nextPoint.lastPathPoint = endPathPoint; nextPoint.nextPathPoint = new Dictionary <string, PathPoint>(); endPathPoint.nextPathPoint.Add(t_pathPoints[n_nowPoints], nextPoint); endPathPoint = nextPoint; } else { endPathPoint = endPathPoint.nextPathPoint[t_pathPoints[n_nowPoints]]; } n_nowPoints++; } ; if (endPathPoint.bundles == null) { endPathPoint.bundles = new List <EditPackageConfig>(); } endPathPoint.bundles.Add(nowBundle); } }
void PackageRelyPackage(EditPackageConfig package) { if (package.objects.Count == 0) { Debug.LogError(package.name + " 没有资源!"); } Object[] res = new Object[package.objects.Count]; for (int i = 0; i < package.objects.Count; i++) { res[i] = package.objects[i].obj; } string path = GetExportPath(package.path, package.name); FileTool.CreatFilePath(path); BuildPipeline.BuildAssetBundle(null, res, path, relyBuildOption, getTargetPlatform); }
public static void PackageBundle(EditPackageConfig package) { //导入资源包 BuildPipeline.PushAssetDependencies(); //打包 Object[] res = new Object[package.objects.Count]; for (int i = 0; i < package.objects.Count; i++) { res[i] = package.objects[i].obj; } string path = GetExportPath(package.path, package.name); FileTool.CreatFilePath(path); BuildPipeline.BuildAssetBundle(package.mainObject.obj, res, path, bundleBuildOption, GetTargetPlatform); BuildPipeline.PopAssetDependencies(); }
void RePackageBundle(EditPackageConfig package) { relyBuildOption = BuildAssetBundleOptions.DeterministicAssetBundle //每次二进制一致 | BuildAssetBundleOptions.CollectDependencies //收集依赖 | BuildAssetBundleOptions.CompleteAssets; //完整资源 //| BuildAssetBundleOptions.UncompressedAssetBundle //不压缩 BuildPipeline.PushAssetDependencies(); List <EditPackageConfig> tmp = GetRelyPackListByMask(package.relyPackagesMask); //先打依赖包 for (int i = 0; i < tmp.Count; i++) { PackageRelyPackage(relyPackages[i]); } //再打普通包 PackageBundle(package); BuildPipeline.PopAssetDependencies(); }
/// <summary> /// 检查单个资源是否全都被其依赖包引用 /// </summary> bool GetResIsUseByRelyBundle(EditPackageConfig pack, EditorObject res) { //根据mask获取所有依赖包 List<EditPackageConfig> relysBundles = GetRelyPackListByMask(pack.relyPackagesMask); for (int i = 0; i < relysBundles.Count; i++) { if (isExist_Bundle(res, relysBundles[i])) { return true; } } return false; }
/// <summary> /// 判断某个资源是否 /// </summary> /// <param name="pack"></param> /// <param name="res"></param> /// <returns></returns> bool GetResIsUseByMainObject(EditPackageConfig pack, EditorObject res) { if (EqualsEditorObject(pack.mainObject, res)) { return true; } return false; }
/// <summary> /// 依赖包视图 /// </summary> void RelyPackagesView() { for (int i = 0; i < relyPackages.Count; i++) { relyPackages[i].relyPackagesMask = 1 << i; if (!GetIsShowByRelyMask(relyPackages[i])) { continue; } //标签头 EditorGUI.indentLevel = 2; EditorGUILayout.BeginHorizontal(); relyPackages[i].isFold = EditorGUILayout.Foldout(relyPackages[i].isFold, relyPackages[i].name); //删除按钮 if (GUILayout.Button("删除")) { relyPackages.RemoveAt(i); continue; } EditorGUILayout.EndHorizontal(); EditorGUI.indentLevel = 3; if (relyPackages[i].isFold) { //名称 EditorGUI.indentLevel = 4; relyPackages[i].name = EditorGUILayout.TextField("name:", relyPackages[i].name); //加载路径 relyPackages[i].path = c_relyAssetsBundlePath + "/" + relyPackages[i].name; EditorGUILayout.LabelField("Path: ", relyPackages[i].path); relyPackages[i].isCollectDependencies = EditorGUILayout.Toggle("收集依赖", relyPackages[i].isCollectDependencies); //子资源视图 relyPackages[i].isFold_objects = EditorGUILayout.Foldout(relyPackages[i].isFold_objects, "Objects"); EditorGUI.indentLevel = 5; if (relyPackages[i].isFold_objects) { ObjectListView(relyPackages[i]); } } EditorGUI.indentLevel = 2; //消息视图 MessageView(relyPackages[i]); } EditorGUILayout.Space(); EditorGUI.indentLevel = 1; //EditorGUILayout.BeginHorizontal(); //EditorGUILayout.LabelField("Button:"); if (GUILayout.Button("增加一个依赖包")) { EditPackageConfig EditPackageConfigTmp = new EditPackageConfig(); EditPackageConfigTmp.name = "NewRelyAssetsBundle" + relyPackages.Count; relyPackages.Add(EditPackageConfigTmp); } //EditorGUILayout.EndHorizontal(); }
void ShowSingleBundleGUI(EditPackageConfig bundle, int l_foldIndex) { EditorGUILayout.BeginVertical(); EditorGUI.indentLevel = l_foldIndex + 1; if (bundle.mainObject != null && bundle.mainObject.obj != null) { bundle.name = bundle.mainObject.obj.name; } else { bundle.name = "Null"; } //主资源 EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("主资源:"); EditorGUILayout.ObjectField(bundle.mainObject.obj, typeof(Object), false); EditorGUILayout.EndHorizontal(); //依赖包 EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("依赖包:"); bundle.relyPackagesMask = EditorGUILayout.MaskField(bundle.relyPackagesMask, RelyPackageNames); EditorGUILayout.EndHorizontal(); //Debug.Log(" bundles[i].relyPackagesMask: " + bundles[i].relyPackagesMask); //加载路径 EditorGUILayout.LabelField("路径: ", bundle.path); bundle.isFold_objects = EditorGUILayout.Foldout(bundle.isFold_objects, "Objects"); //子资源视图 EditorGUI.indentLevel = l_foldIndex + 2; if (bundle.isFold_objects) { ObjectListView(bundle); } EditorGUILayout.EndVertical(); //} }
void AddAssetBundle(Object obj, string path) { EditorObject objTmp = new EditorObject(); objTmp.obj = obj; objTmp.path = GetObjectPath(obj); if (isExist_AllBundle(objTmp)) { //Debug.Log(obj.name + " 已经存在!"); } else { EditPackageConfig EditPackageConfigTmp = new EditPackageConfig(); EditPackageConfigTmp.name = obj.name; EditorObject mainObjTmp = new EditorObject(); mainObjTmp.obj = obj; mainObjTmp.path = GetObjectPath(obj); EditPackageConfigTmp.mainObject = mainObjTmp; EditPackageConfigTmp.path = GetRelativePath(FileTool.RemoveExpandName(GetObjectPath(obj))); Object[] res = GetCorrelationResource(obj); //判断依赖包中含不含有该资源,如果有,则不将此资源放入bundle中 //依赖包判断 for (int j = 0; j < res.Length; j++) { if (res[j] == null) { Debug.LogWarning(obj + " 有资源丢失!"); continue; } ////过滤掉一些不必要加载进去的组件 //if (ComponentFilter(res[j])) //{ // continue; //} EditorObject tmp = new EditorObject(); tmp.obj = res[j]; tmp.path = GetObjectPath(res[j]); //bool isExistRelyPackage = false; for (int i = 0; i < relyPackages.Count; i++) { if (isExist_Bundle(tmp, relyPackages[i])) { //在依赖包选项中添加此依赖包 EditPackageConfigTmp.relyPackagesMask = EditPackageConfigTmp.relyPackagesMask | 1 << i; //isExistRelyPackage = true; break; } } ////该资源不在依赖包中,并且也与主资源不同时,放入包中 //if (isExistRelyPackage == false // &&!EqualsEditorObject(EditPackageConfigTmp.mainObject,tmp) // ) //{ // EditPackageConfigTmp.objects.Add(tmp); //} } bundles.Add(EditPackageConfigTmp); } }
/// <summary> /// 检查某个资源包内有没有重复资源 /// </summary> /// <param name="pack"></param> void CheckBundle(EditPackageConfig pack) { if (bundleName.ContainsKey(pack.name)) { Debug.LogError(pack.name + "包名重复! "); pack.errorMsg.Add("包名重复! "); errorCount++; } else { bundleName.Add(pack.name, 0); } if (pack.mainObject != null) { string resNameTmp = CustomToString(pack.mainObject.obj); if (checkDict.ContainsKey(resNameTmp)) { //判断该资源是否在它的依赖包里,如果不在,加入判重 if (!GetResIsUseByRelyBundle(pack, pack.mainObject) && !ComponentFilter(pack.mainObject.obj)) { if (isExist_EditorList(checkDict[resNameTmp], pack.mainObject)) { pack.warnMsg.Add("MainObject 重复! " + resNameTmp); warnCount++; } else { checkDict[resNameTmp].Add(pack.mainObject); } } } else { checkDict.Add(resNameTmp, new List<EditorObject>()); checkDict[resNameTmp].Add(pack.mainObject); } } Object[] res = GetCorrelationResource(pack.mainObject.obj); for (int i = 0; i < res.Length; i++) { string resNameTmp = CustomToString(res[i]); EditorObject tmp = new EditorObject(); tmp.obj = res[i]; tmp.path = GetObjectPath(res[i]); if (checkDict.ContainsKey(resNameTmp)) { //判断该资源是否在它的依赖包里,如果不在,加入判重 if (!EqualsEditorObject(pack.mainObject, tmp) && !GetResIsUseByRelyBundle(pack, tmp) && !ComponentFilter(res[i])) { if (isExist_EditorList(checkDict[resNameTmp], tmp)) { pack.warnMsg.Add("Objects存在重复资源 ! " + resNameTmp); warnCount++; } else { checkDict[resNameTmp].Add(tmp); } } } else { checkDict.Add(resNameTmp, new List<EditorObject>()); checkDict[resNameTmp].Add(tmp); } } }
/// <summary> /// 检查依赖包中有没有重复资源 /// </summary> /// <param name="pack"></param> void CheckRelyRepeatRes(EditPackageConfig pack) { for (int i = 0; i < pack.objects.Count; i++) { string resNameTmp = CustomToString(pack.objects[i].obj); EditorObject tmp = pack.objects[i]; if (checkDict.ContainsKey(resNameTmp)) { if (isExist_EditorList(checkDict[resNameTmp], tmp)) { pack.warnMsg.Add("Objects存在重复资源 ! " + resNameTmp); warnCount++; } else { checkDict[resNameTmp].Add(tmp); } } else { checkDict.Add(resNameTmp, new List<EditorObject>()); checkDict[resNameTmp].Add(tmp); } } }
/// <summary> /// 检查某个资源包内有没有重复资源 /// </summary> /// <param name="pack"></param> void CheckBundle(EditPackageConfig pack) { if (bundleName.ContainsKey(pack.name)) { Debug.LogError(pack.name + "包名重复! "); pack.errorMsg.Add("包名重复! "); errorCount++; } else { bundleName.Add(pack.name, 0); } if (pack.mainObject != null) { string resNameTmp = CustomToString(pack.mainObject.obj); if (checkDict.ContainsKey(resNameTmp)) { //判断该资源是否在它的依赖包里,如果不在,加入判重 if (!GetResIsUseByRelyBundle(pack, pack.mainObject) && !ComponentFilter(pack.mainObject.obj)) { if (isExist_EditorList(checkDict[resNameTmp], pack.mainObject)) { pack.warnMsg.Add("MainObject 重复! " + resNameTmp); warnCount++; } else { checkDict[resNameTmp].Add(pack.mainObject); } } } else { checkDict.Add(resNameTmp, new List <EditorObject>()); checkDict[resNameTmp].Add(pack.mainObject); } } Object[] res = GetCorrelationResource(pack.mainObject.obj); for (int i = 0; i < res.Length; i++) { string resNameTmp = CustomToString(res[i]); EditorObject tmp = new EditorObject(); tmp.obj = res[i]; tmp.path = GetObjectPath(res[i]); if (ComponentFilter(tmp.obj)) { continue; } if (checkDict.ContainsKey(resNameTmp)) { //判断该资源是否在它的依赖包里,如果不在,加入判重 if (!EqualsEditorObject(pack.mainObject, tmp) && !GetResIsUseByRelyBundle(pack, tmp) && !ComponentFilter(res[i])) { if (isExist_EditorList(checkDict[resNameTmp], tmp)) { pack.warnMsg.Add(pack.path + " 存在重复资源 ! " + resNameTmp); warnCount++; } else { checkDict[resNameTmp].Add(tmp); } } } else { checkDict.Add(resNameTmp, new List <EditorObject>()); checkDict[resNameTmp].Add(tmp); } } }
void AddAssetBundle(Object obj, string path) { if (obj == null) { return; //都是空了也就是没有意义的 } EditorObject objTmp = new EditorObject(); objTmp.obj = obj; objTmp.path = GetObjectPath(obj); if (isExist_AllBundle(objTmp)) { Debug.LogWarning(obj.name + " 已经存在!"); } else if (!IsPackage(objTmp)) { //Debug.LogWarning(obj.name + " 资源不打包!"); } else { EditPackageConfig EditPackageConfigTmp = new EditPackageConfig(); if (obj == null) { Debug.LogError("AddAssetBundle ERROR : path: " + path); return; } EditPackageConfigTmp.name = obj.name; EditorObject mainObjTmp = new EditorObject(); mainObjTmp.obj = obj; mainObjTmp.path = GetObjectPath(obj); EditPackageConfigTmp.mainObject = mainObjTmp; EditPackageConfigTmp.path = GetRelativePath(FileTool.RemoveExpandName(GetObjectPath(obj))); Object[] res = GetCorrelationResource(obj); //判断依赖包中含不含有该资源,如果有,则不将此资源放入bundle中 //依赖包判断 for (int j = 0; j < res.Length; j++) { if (res[j] == null) { //Debug.LogWarning(obj + " 有资源丢失!"); continue; } ////过滤掉一些不必要加载进去的组件 //if (ComponentFilter(res[j])) //{ // continue; //} EditorObject tmp = new EditorObject(); tmp.obj = res[j]; tmp.path = GetObjectPath(res[j]); //bool isExistRelyPackage = false; for (int i = 0; i < relyPackages.Count; i++) { if (isExist_Bundle(tmp, relyPackages[i])) { //Debug.Log("添加依赖包 : " + i); //在依赖包选项中添加此依赖包 EditPackageConfigTmp.relyPackagesMask = EditPackageConfigTmp.relyPackagesMask | 1 << i; //isExistRelyPackage = true; break; } } } bundles.Add(EditPackageConfigTmp); m_BundleDictCache.Add(EditPackageConfigTmp.name, EditPackageConfigTmp); } }
//重新加载Object void ReLoadGameObject(EditPackageConfig pack) { if (pack.mainObject != null) { ReLoadEditObject(pack.mainObject); } for (int i = 0; i < pack.objects.Count; i++) { ReLoadEditObject(pack.objects[i]); } }
bool GetIsFitsBundleQuery(EditPackageConfig package) { if (bundleQuery == "") { return true; } //大小写不敏感 string nameLower = package.name.ToLower(); return nameLower.Contains(bundleQuery.ToLower()); }
bool isExist_Bundle(EditorObject obj, EditPackageConfig package) { return isExist_EditorList(package.objects, obj); }
/// <summary> /// 检查依赖包是否是无资源 /// </summary> void CheckRelyPackagesEmptyRes(EditPackageConfig pack) { if (pack.objects.Count == 0) { Debug.LogError(pack.name + " 依赖包无资源 !"); pack.errorMsg.Add(pack.name + " 依赖包无资源 !"); errorCount++; } }
void ObjectListView(EditPackageConfig pack) { EditorGUILayout.LabelField("Size: " + pack.objects.Count); for (int j = 0; j < pack.objects.Count; j++) { EditorGUILayout.LabelField("Path:", pack.objects[j].path); EditorGUILayout.BeginHorizontal(); EditorGUILayout.ObjectField(pack.objects[j].obj, typeof(Object), false); if (GUILayout.Button("删除", GUILayout.Width(ButtonWidth))) { pack.objects.RemoveAt(j); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); } EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Button:"); if (GUILayout.Button("增加选中资源")) { Object[] selects = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets); for (int k = 0; k < selects.Length; k++) { EditorObject tmp = new EditorObject(); tmp.obj = selects[k]; tmp.path = GetObjectPath(selects[k]); if (!isExist_EditorList(pack.objects, tmp)) { pack.objects.Add(tmp); } else { Debug.Log(CustomToString(selects[k]) + " has Exists"); } } } //if (GUILayout.Button("资源去重")) //{ //} EditorGUILayout.EndHorizontal(); }
/// <summary> /// 检查单个包有没有丢失资源 /// </summary> /// <param name="pack"></param> void CheckMissRes(EditPackageConfig pack) { for (int i = 0; i < pack.objects.Count; i++) { if (pack.objects[i].obj == null) { Debug.LogError(pack.name + " " + i + "号资源丢失!"); pack.errorMsg.Add(i + "号资源丢失!"); errorCount++; } } //将来加入资源缺失检测 if (pack.mainObject == null) { Debug.LogError(pack.name + "没有主资源!"); pack.errorMsg.Add("没有主资源!"); errorCount++; return; } Object[] res = GetCorrelationResource(pack.mainObject.obj); for (int i = 0; i < res.Length; i++) { if (res[i] == null) { pack.warnMsg.Add("有丢失的脚本!"); warnCount++; continue; } //查找其他资源是否有掉材质球问题 List<string> resLostList = FindLostRes(res[i]); for (int j = 0; j < resLostList.Count; j++) { pack.warnMsg.Add(resLostList[j]); warnCount++; } //EditorObject tmp = new EditorObject(); //tmp.obj = res[i]; //tmp.path = GetObjectPath(res[i]); //if (!GetResIsUse(pack, tmp) && !ComponentFilter(res[i])) //{ // pack.errorMsg.Add( CustomToString(res[i]) + " 资源丢失依赖!"); // errorCount++; //} } }
/// <summary> /// 依赖包视图 /// </summary> void RelyPackagesView() { for (int i = 0; i < relyPackages.Count; i++) { relyPackages[i].relyPackagesMask = 1 << i; if (!GetIsShowByRelyMask(relyPackages[i])) { continue; } //标签头 EditorGUI.indentLevel = 2; EditorGUILayout.BeginHorizontal(); relyPackages[i].isFold = EditorGUILayout.Foldout(relyPackages[i].isFold, relyPackages[i].name); //删除按钮 if (GUILayout.Button("删除")) { relyPackages.RemoveAt(i); continue; } EditorGUILayout.EndHorizontal(); EditorGUI.indentLevel = 3; if (relyPackages[i].isFold) { //名称 EditorGUI.indentLevel = 4; relyPackages[i].name = EditorGUILayout.TextField("name:", relyPackages[i].name); //加载路径 relyPackages[i].path = relyAssetsBundlePath + "/" + relyPackages[i].name; EditorGUILayout.LabelField("Path: ", relyPackages[i].path); //子资源视图 relyPackages[i].isFold_objects = EditorGUILayout.Foldout(relyPackages[i].isFold_objects, "Objects"); EditorGUI.indentLevel = 5; if (relyPackages[i].isFold_objects) { ObjectListView(relyPackages[i]); } } EditorGUI.indentLevel = 2; //消息视图 MessageView(relyPackages[i]); } EditorGUILayout.Space(); EditorGUI.indentLevel = 1; //EditorGUILayout.BeginHorizontal(); //EditorGUILayout.LabelField("Button:"); if (GUILayout.Button("增加一个依赖包")) { EditPackageConfig EditPackageConfigTmp = new EditPackageConfig(); EditPackageConfigTmp.name = "NewRelyAssetsBundle" + relyPackages.Count; relyPackages.Add(EditPackageConfigTmp); } //EditorGUILayout.EndHorizontal(); }
bool isExist_Bundle(EditorObject obj, EditPackageConfig package) { return(isExist_EditorList(package.objects, obj)); }
void PackageBundle(EditPackageConfig package) { //Debug.Log("PackageBundle " + package.name); //导入资源包 BuildPipeline.PushAssetDependencies(); //打包 Object[] res = new Object[package.objects.Count]; for (int i = 0; i < package.objects.Count; i++) { res[i] = package.objects[i].obj; } string path = GetExportPath(package.path, package.name); FileTool.CreatFilePath(path); BuildPipeline.BuildAssetBundle(package.mainObject.obj, res, path, relyBuildOption, getTargetPlatform); BuildPipeline.PopAssetDependencies(); }
void AddAssetBundle(Object obj, string path) { if (obj == null) return;//都是空了也就是没有意义的 EditorObject objTmp = new EditorObject(); objTmp.obj = obj; objTmp.path = GetObjectPath(obj); if (isExist_AllBundle(objTmp) || !IsPackage(objTmp)) { //Debug.Log(obj.name + " 已经存在!"); } else { EditPackageConfig EditPackageConfigTmp = new EditPackageConfig(); if (obj == null) { Debug.LogError("AddAssetBundle ERROR : path: " + path); return; } EditPackageConfigTmp.name = obj.name; EditorObject mainObjTmp = new EditorObject(); mainObjTmp.obj = obj; mainObjTmp.path = GetObjectPath(obj); EditPackageConfigTmp.mainObject = mainObjTmp; EditPackageConfigTmp.path = GetRelativePath(FileTool.RemoveExpandName(GetObjectPath(obj))); Object[] res = GetCorrelationResource(obj); //判断依赖包中含不含有该资源,如果有,则不将此资源放入bundle中 //依赖包判断 for (int j = 0; j < res.Length; j++) { if (res[j] == null) { //Debug.LogWarning(obj + " 有资源丢失!"); continue; } ////过滤掉一些不必要加载进去的组件 //if (ComponentFilter(res[j])) //{ // continue; //} EditorObject tmp = new EditorObject(); tmp.obj = res[j]; tmp.path = GetObjectPath(res[j]); //bool isExistRelyPackage = false; for (int i = 0; i < relyPackages.Count; i++) { if (isExist_Bundle(tmp, relyPackages[i])) { //在依赖包选项中添加此依赖包 EditPackageConfigTmp.relyPackagesMask = EditPackageConfigTmp.relyPackagesMask | 1 << i; //isExistRelyPackage = true; break; } } } bundles.Add(EditPackageConfigTmp); m_BundleDictCatch.Add(EditPackageConfigTmp.name, EditPackageConfigTmp); } }
void PackageRelyPackage(EditPackageConfig package) { //BuildPipeline.PushAssetDependencies(); if (package.objects.Count == 0) { Debug.LogError(package.name + " 没有资源!"); } Object[] res = new Object[package.objects.Count]; for (int i = 0; i < package.objects.Count; i++) { res[i] = package.objects[i].obj; } string path = GetExportPath(package.path, package.name); FileTool.CreatFilePath(path); BuildPipeline.BuildAssetBundle(null, res, path, relyBuildOption, getTargetPlatform); //BuildPipeline.PopAssetDependencies(); }
bool GetIsShowByRelyMask(EditPackageConfig package) { if (RelyMaskFilter == -1) { return true; } if (RelyMaskFilter == 0) { if (package.relyPackagesMask == 0) { return true; } else { return false; } } if ((package.relyPackagesMask & RelyMaskFilter) != 0) { return true; } else { return false; } }
//消息视图 void MessageView(EditPackageConfig package) { for (int i = 0; i < package.errorMsg.Count; i++) { EditorGUILayout.LabelField("ERROR: " + package.errorMsg[i], EditorGUIStyleData.s_ErrorMessageLabel); } for (int i = 0; i < package.warnMsg.Count; i++) { EditorGUILayout.LabelField("WARN: " + package.warnMsg[i], EditorGUIStyleData.s_WarnMessageLabel); } }