public bool Rebuild(Guid taskID, U3DAssetDBRebuildTask.Result res) { if (!taskID.Equals(rebuildTaskID)) { return(false); } assetTable = res.assetTable; assetReferencedTable = res.assetReferencedTable; unUsedAssets = res.unUsedAssets; rebuildTaskID = Guid.Empty; //更新数据库时间 dbUpdateTime = DateTime.Now.ToLocalTime().ToString(); //标记已经破损的资源 foreach (var corruptedId in corruptedAssets) { U3DAssetInfo info = null; if (assetTable.TryGetValue(corruptedId, out info)) { ResourceManageToolUtility.MarkAssetCorrupted(ref info); } } corruptedAssets.Clear(); Save(); return(true); }
private void _UpdateAssetTableStep() { string path = iter.Current as string; if (_IsIgnoreAsset(path)) { return; } U3DAssetInfo assetInfo = new U3DAssetInfo(); ResourceManageToolUtility.InitAssetInfo(path, ref assetInfo); Guid guid = assetInfo.guid; string[] deps = ResourceManageToolUtility.GetDependencies(path); foreach (var depPath in deps) { Guid depGuid = ResourceManageToolUtility.PathToGuid(depPath); if (depGuid.Equals(guid)) { continue; } assetInfo.deps.Add(depGuid); } resultObj.assetTable.Add(guid, assetInfo); }
private void _GetAssetDependencies(Guid id, out List <U3DAssetInfo> assets) { U3DAssetInfo assetInfo = null; assets = new List <U3DAssetInfo>(); if (!U3DAssetDB.GetInstance().Find(id, out assetInfo)) { return; } string[] depPaths = ResourceManageToolUtility.GetDependencies(assetInfo.path); foreach (var p in depPaths) { if (p.Equals(assetInfo.Path)) { continue; } U3DAssetInfo depAsset = null; Guid depId = ResourceManageToolUtility.PathToGuid(p); //在数据库中没有找到此资源则初始化 if (!U3DAssetDB.GetInstance().Find(depId, out depAsset)) { depAsset = new U3DAssetInfo(); depAsset.guid = depId; ResourceManageToolUtility.InitAssetInfo(p, ref depAsset); U3DAssetDB.GetInstance().AssetTable.Add(depAsset.guid, depAsset); } assets.Add(depAsset); } assets.Sort(new AssetInfoComparer(AssetFilterList)); }
private void _TouchCacheFolder() { if (!Directory.Exists(_GetCacheFolderPath())) { Directory.CreateDirectory(_GetCacheFolderPath()); } ResourceManageToolUtility.RefreshAssetDatabase(); }
private void _CorruptedAssetsCatchCallback(string condition, string stackTrace, LogType type) { if (condition.Contains("Failed to read file") && condition.Contains("because it is corrupted.") ) {//资源已经破损 string subStr = condition.Substring(condition.IndexOf("Assets")); string corruptedAssetPath = subStr.Substring(0, subStr.LastIndexOf('\'')); corruptedAssets.Add(ResourceManageToolUtility.PathToGuid(corruptedAssetPath)); } }
public void Init() { Clear(); string[] assetPaths = ResourceManageToolUtility.GetAllAssetPaths(); foreach (var p in assetPaths) { if (IsPathContain(p)) { U3DAssetInfo newInfo = new U3DAssetInfo(); ResourceManageToolUtility.InitAssetInfo(p, ref newInfo); assetTable.Add(newInfo.guid, newInfo); } } }
private bool _ApplySerializeObject(U3DAssetDBSerializeObject obj) { string projPath = EditorHelper.GetProjectPath(); dbUpdateTime = obj.StrUpdateTime; assetTable.Clear(); foreach (var asset in obj.AssetTable) { Guid id = new Guid(asset.Key); U3DAssetInfo info = asset.Value; string absPath = projPath + info.path; //数据库中所述路径所对应文件已经不存在 if ( !Directory.Exists(absPath) && !File.Exists(absPath) ) { Debug.LogError("Asset数据库已过期!路径\"" + info.path + "\"不存在!"); return(false); } ResourceManageToolUtility.InitAssetInfoIcon(ref info); assetTable.Add(id, info); } assetReferencedTable.Clear(); foreach (var pair in obj.AssetReferencedTable) { Guid id = new Guid(pair.Key); List <Guid> referencedList = new List <Guid>(); foreach (var referencedID in pair.Value) { Guid refId = new Guid(referencedID); referencedList.Add(refId); } assetReferencedTable.Add(id, referencedList); } unUsedAssets.Clear(); foreach (var unUsedAsset in obj.UnUsedAssets) { Guid id = new Guid(unUsedAsset); unUsedAssets.Add(id); } return(true); }
static void UpdateTreeView() { TreeViewCtrl treeView = s_root.FindControl("_MainTreeView") as TreeViewCtrl; if (treeView == null) { return; } treeView.Clear(); string[] allAssetPaths = ResourceManageToolUtility.GetAllAssetPaths(); foreach (var path in allAssetPaths) { if (ResourceManageToolUtility.PathIsFolder(path)) { AddAssetToResourceTreeView(path); } } }
public void GetAssetDependencies(Guid resID, out List <U3DAssetInfo> assets) { assets = new List <U3DAssetInfo>(); U3DAssetInfo assetInfo = null; if (U3DAssetDB.GetInstance().Find(resID, out assetInfo)) {//若找到了查依赖的资源 //若资源已经损坏则不再构建正向依赖 if (assetInfo.Corrupted) { return; } if (assetInfo.deps.Count > 0) {//已初始化正向依赖信息 foreach (var depId in assetInfo.deps) { U3DAssetInfo depAsset = null; if (U3DAssetDB.GetInstance().Find(depId, out depAsset)) {//正向依赖资源已经收集到资源数据库中 assets.Add(depAsset); } else {//未收集到资源数据库中,建临时信息 depAsset = new U3DAssetInfo(); depAsset.guid = depId; ResourceManageToolUtility.InitAssetInfo(ResourceManageToolUtility.GuidToPath(depId), ref depAsset); assets.Add(depAsset); } } assets.Sort(new AssetInfoComparer(AssetFilterList)); } else {//未初始化正向依赖信息 _GetAssetDependencies(resID, out assets); } } }
public IEditorCoroutineTask NewRebuildTask() { U3DAssetDBRebuildTask task = null; if (rebuildTaskID.Equals(Guid.Empty)) { string[] allPaths = ResourceManageToolUtility.GetAllAssetPaths(); //确定要扫描的资源 List <string> searchPaths = new List <string>(); foreach (var p in allPaths) { if (IsPathContain(p)) { searchPaths.Add(p); } } task = new U3DAssetDBRebuildTask(searchPaths.ToArray()); rebuildTaskID = task.TaskID; } return(task); }
public bool IsPathContain(string path) { if (ResourceManageConfig.GetInstance().Paths.Count == 0) { //只有Assets下的资源可被包含 if (path.IndexOf("Assets") == 0) { return(true); } return(false); } foreach (var p in ResourceManageConfig.GetInstance().Paths) { if (0 == path.IndexOf(p)) { return(true); } } //此时当前路径不完全包含待扫描路径 //如果当前路径为文件夹,则看其是否 //在待扫描路径中出现 if (ResourceManageToolUtility.PathIsFolder(path)) { foreach (var p in ResourceManageConfig.GetInstance().Paths) { if (0 == p.IndexOf(path)) { return(true); } } } return(false); }
public bool FindReferencedList(string path, out List <Guid> referencedList) { Guid guid = ResourceManageToolUtility.PathToGuid(path); return(FindReferencedList(guid, out referencedList)); }
//根据路径查找 public bool Find(string path, out U3DAssetInfo info) { Guid guid = ResourceManageToolUtility.PathToGuid(path); return(Find(guid, out info)); }
public bool Contain(string path) { Guid guid = ResourceManageToolUtility.PathToGuid(path); return(assetTable.ContainsKey(guid)); }
static void AddAssetToResourceTreeView(string path) { TreeViewCtrl treeView = s_root.FindControl("_MainTreeView") as TreeViewCtrl; if (treeView == null) { return; } string totalPath = path; string currPath = path; List <TreeViewNode> currLevelNodeList = treeView.Roots; TreeViewNode parentNode = null; int len = 0; while (currPath != "") { int i = currPath.IndexOf('/'); if (i < 0) { i = currPath.Length; } len += i + 1; string pathNodeName = currPath.Substring(0, i); string currNodeFullPath = totalPath.Substring(0, len - 1); if (i + 1 < currPath.Length) { currPath = currPath.Substring(i + 1); } else { currPath = ""; } bool findNode = false; foreach (var treeNode in currLevelNodeList) { if (treeNode.name == pathNodeName) { findNode = true; parentNode = treeNode; currLevelNodeList = treeNode.children; break; } } if (!findNode) { TreeViewNode newNode = new TreeViewNode(); newNode.name = pathNodeName; newNode.image = ResourceManageToolUtility.GetCachedIcon(path); if (string.Equals(pathNodeName.ToLower(), "assets")) { newNode.state.IsExpand = true; } else { newNode.state.IsExpand = false; } TreeViewNodeUserParam userParam = new TreeViewNodeUserParam(); bool toggleState = false; //Modify by liteng for 发布工具改善 foreach (string p in PackageExportToolModel.GetInstance().GetPackageInfo().ExportAssets) { if (p.Equals(currNodeFullPath)) { toggleState = true; } } userParam.param = toggleState; newNode.state.userParams.Add(userParam); if (parentNode == null) {//说明需要作为根节点插入树视图中 currLevelNodeList.Add(newNode); } else { parentNode.Add(newNode); //Add by liteng for 发布工具改善 start if (true == toggleState) { parentNode.state.IsExpand = true; } //Add by liteng for 发布工具改善 end } parentNode = newNode; currLevelNodeList = newNode.children; } } }
//对 "Assets/" 目录下的所有资源进行检查 public void TotalCheck() { if (H3DAssetCheckerConfig.GetInstance().isAssetCheckerOff) { return; } var pathCheckerList = H3DAssetCheckerFramework.GetInstance().GetAssetPathCheckerList(); var assetCheckerList = H3DAssetCheckerFramework.GetInstance().GetAssetCheckerList(H3DAssetChecker.ResouceType.ALL); var assetPaths = AssetDatabase.GetAllAssetPaths(); foreach (var path in assetPaths) { if (ResourceManageToolUtility.PathIsFolder(path)) { continue; } UnityEngine.Object asset = AssetDatabase.LoadAssetAtPath(path, typeof(object)); H3DAssetChecker.ResouceType resType = H3DAssetChecker.QueryAssetResType(asset); var assetImporter = AssetImporter.GetAtPath(path); bool needImport = false; bool firstImport = !HasAssetImportMark(assetImporter); if (firstImport) {//若为第一次导入则加入标记 MarkAssetImporterAsAlreadyImported(assetImporter); needImport = true; } foreach (var checker in pathCheckerList) { if (H3DAssetCheckerUtil.IsPathInclude(path, checker)) { checker.Check(asset, assetImporter, path, firstImport, ref needImport); } } foreach (var checker in assetCheckerList) { if ( checker.ResType == resType && H3DAssetCheckerUtil.IsPathInclude(path, checker) ) {//使用符合资源类型的checker进行检查 checker.Check(asset, assetImporter, path, firstImport, ref needImport); checker.PostCheck(asset, assetImporter, path, firstImport, ref needImport); } } if (needImport) { AssetDatabase.ImportAsset(path); } } AssetDatabase.Refresh(); }