void RemapAssetIds(StringBuilder log) { AssetIdRemapObject remapObject = new AssetIdRemapObject(); JsonUtility.FromJsonOverwrite(m_RemapFile.text, remapObject); int remappedReferences = 0; int modifiedFiles = 0; string[] assets = k_AssetExtensionsToRemap.SelectMany(x => Directory.GetFiles("Assets", x, SearchOption.AllDirectories)).ToArray(); var failures = new StringBuilder(); var successes = new StringBuilder(); int failCount = 0; for (int i = 0, c = assets.Length; i < c; i++) { EditorUtility.DisplayProgressBar("Asset Id Remap", assets[i], i / (float)c); int modified; if (!DoAssetIdentifierRemap(assets[i], remapObject.map, out modified)) { failures.AppendLine(" - " + assets[i]); failCount++; } else { if (modified > 0) { successes.AppendLine(string.Format(" - ({0}) references in {1}", modified.ToString(), assets[i])); modifiedFiles++; } } remappedReferences += modified; } EditorUtility.ClearProgressBar(); log.AppendLine(string.Format("Remapped {0} references in {1} files.", remappedReferences.ToString(), modifiedFiles.ToString())); log.AppendLine(string.Format("\nFailed remapping {0} files:", failCount.ToString())); log.AppendLine(failCount > 0 ? failures.ToString() : " - (none)"); log.AppendLine("\nSuccessfully remapped files:"); log.Append(successes); PackageImporter.Reimport(PackageImporter.EditorCorePackageManager); AssetDatabase.Refresh(); }
/// <summary> /// Load a remap json file from a relative path (Assets/MyRemapFile.json). /// </summary> /// <returns>A GuidRemapObject from the path, or if not found, a new GuidRemapObject</returns> AssetIdRemapObject GetGuidRemapObject() { var remapObject = m_TreeView.remapObject; if (remapObject != null) { return(remapObject); } if (m_RemapTextAsset == null) { m_RemapTextAsset = AssetDatabase.LoadAssetAtPath <TextAsset>(remapFilePath); } remapObject = new AssetIdRemapObject(); if (m_RemapTextAsset != null) { JsonUtility.FromJsonOverwrite(m_RemapTextAsset.text, remapObject); } return(remapObject); }