private static void ReplaceGUIAndFileId(Object builInRes, string targetAssetPath) { try{ long defaultFileId = builInRes.GetFileID(); string defaultGUIId = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(builInRes)); GUIIDAndFileId ids = builtInExtraDic[builInRes.name]; StreamReader sr = new StreamReader(EditorTools.GetWindowsPath(targetAssetPath)); string content = sr.ReadToEnd(); sr.Close(); content = content.Replace(defaultGUIId, ids.guid); content = content.Replace(defaultFileId.ToString(), ids.fileid.ToString()); FileStream fs = new FileStream(EditorTools.GetWindowsPath(targetAssetPath), FileMode.OpenOrCreate); StreamWriter sw = new StreamWriter(fs); sw.Write(content); sw.WriteLine("#修改标记"); sw.Close(); fs.Close(); }catch { throw new UnityException("builnt in extrac dic 数据错误"); } }
private static void ReverReplaceBuiltInRes() { foreach (var pair in replacedResAssetDic) { Object defaultObj = pair.Key; List <string> replaceAsset = pair.Value; string defaultObjPath = AssetDatabase.GetAssetPath(defaultObj); GUIIDAndFileId ids = builtInExtraDic [defaultObj.name]; foreach (var path in replaceAsset) { string windowsPath = EditorTools.GetWindowsPath(path); StreamReader sr = new StreamReader(windowsPath); string content = sr.ReadToEnd(); sr.Close(); content = content.Replace("#修改标记", ""); content = content.Replace(ids.guid, AssetDatabase.AssetPathToGUID(defaultObjPath)); content = content.Replace(ids.fileid.ToString(), defaultObj.GetFileID().ToString()); StreamWriter sw = new StreamWriter(windowsPath); sw.Write(content); sw.Close(); } } }
private static void AnalysisExtractRes() { EditorUtility.DisplayProgressBar("解析内置资源", "解析内置资源", 1f); builtInExtraDic.Clear(); if (!Directory.Exists(BundleBuildConfig.BuiltExtraAssetPath)) { return; } string[] filePaths = Directory.GetFiles(BundleBuildConfig.BuiltExtraAssetPath, "*.*", SearchOption.AllDirectories); foreach (var filePath in filePaths) { if (filePath.EndsWith(".meta")) { continue; } string builtInUnityPath = EditorTools.GetUnityPath(filePath); Object builtInObj = AssetDatabase.LoadMainAssetAtPath(builtInUnityPath); builtInExtraDic.Add(builtInObj.name, new GUIIDAndFileId { guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(builtInObj)), fileid = builtInObj.GetFileID() }); } }