public static void Func2() { var prefabPath = "F:/WorkFolder/master/client/GameClient_UI/Assets/Resources/prefab/UIItems/Lab/ui_item_tech.prefab"; var scriptFileID = "11418506"; DeleteMissScriptTool.DeleteMissScript(prefabPath, scriptFileID); }
/// <summary> /// 删除所有预制体上有guid的miss脚本引用 /// </summary> void DeleteMissScriptWithGUID() { Dictionary <string, HashSet <string> > guid2prefab = null; Dictionary <string, Dictionary <string, string> > prefab2guid2fileID = null; var referenceGuids = GetMissScriptGUID(out guid2prefab, out prefab2guid2fileID); int i = 0; foreach (var scriptGUID in referenceGuids) { EditorUtility.DisplayProgressBar("Processing...", "清理有guid的miss脚本中....", i++ / (float)referenceGuids.Count); var prefabLst = guid2prefab[scriptGUID]; foreach (var prefabPath in prefabLst) { var fileID2guid = prefab2guid2fileID[prefabPath]; foreach (var item in fileID2guid) { if (item.Value == scriptGUID) { var scriptFileID = item.Key; DeleteMissScriptTool.DeleteMissScript(prefabPath, scriptFileID); Debug.LogFormat("prefab:{0},script:{1},guid:{2}", prefabPath, scriptFileID, scriptGUID); } } } } EditorUtility.ClearProgressBar(); }
/// <summary> /// 打印没有guid的miss脚本信息 /// </summary> void PrintMissScriptNoGUID() { string[] prefabGuids = AssetDatabase.FindAssets("t:Prefab", new string[] { "Assets/Resources/prefab" });//获取所有预制体guid int i = 0; foreach (var prefabGUID in prefabGuids) { EditorUtility.DisplayProgressBar("Processing...", "打印没有guid的miss脚本中....", i++ / (float)prefabGuids.Length); var prefabPath = DeleteMissScriptTool.GetPathByGUID(prefabGUID);//预制体全路径 var scriptFileIDLst = DeleteMissScriptTool.GetScriptNoGUIDFileIDLst(prefabPath); foreach (var fileID in scriptFileIDLst) { Debug.LogFormat("prefab:{0},script:{1}", prefabPath, fileID); } } EditorUtility.ClearProgressBar(); }
/// <summary> /// 搜索所有含有miss脚本的预制体 /// </summary> private void SearchMissComponentObjs() { string[] guids = AssetDatabase.FindAssets("t:Prefab", new string[] { "Assets/Resources/prefab" }); int i = 0; foreach (var guid in guids) { var prefabPath = AssetDatabase.GUIDToAssetPath(guid); EditorUtility.DisplayProgressBar("Processing...", "遍历丢失脚本Prefab中....", i++ / (float)guids.Length); var obj = (GameObject)AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)); if (DeleteMissScriptTool.CheckMissComponentObj(obj) == true) { m_missObjs.Add(obj); Debug.Log(prefabPath, obj); } } EditorUtility.ClearProgressBar(); }
/// <summary> /// 获取有guid的miss脚本信息 /// </summary> /// <param name="Dictionary<string"></param> /// <param name="guid2prefab"></param> /// <param name="Dictionary<string"></param> /// <param name="prefab2guid2fileID"></param> /// <returns></returns> HashSet <string> GetMissScriptGUID(out Dictionary <string, HashSet <string> > guid2prefab, out Dictionary <string, Dictionary <string, string> > prefab2guid2fileID) { string[] guids = AssetDatabase.FindAssets("t:Script");//所有脚本guid HashSet <string> existGuids = new HashSet <string>(guids); HashSet <string> referenceGuids = new HashSet <string>(); //所有预制体引用的脚本guid prefab2guid2fileID = new Dictionary <string, Dictionary <string, string> >(); //脚本guid到预制体列表的映射 guid2prefab = new Dictionary <string, HashSet <string> >(); //脚本guid到预制体列表的映射 string[] prefabGuids = AssetDatabase.FindAssets("t:Prefab", new string[] { "Assets/Resources/prefab" }); //获取所有预制体guid int i = 0; foreach (var prefabGUID in prefabGuids) { EditorUtility.DisplayProgressBar("Processing...", "收集miss脚本的guid中....", i++ / (float)prefabGuids.Length); var prefabPath = DeleteMissScriptTool.GetPathByGUID(prefabGUID); //预制体全路径 var fileID2guid = DeleteMissScriptTool.GetScriptFileIDAndGuid(prefabPath); //脚本guid到fileID的映射 prefab2guid2fileID[prefabPath] = fileID2guid; //预制体上的脚本guid到fileID的映射 //脚本guid到预制体列表的映射 foreach (var item in fileID2guid) { if (guid2prefab.ContainsKey(item.Value) == false) { guid2prefab[item.Value] = new HashSet <string>(); } guid2prefab[item.Value].Add(prefabPath); } referenceGuids.UnionWith(fileID2guid.Values); //合并预制体引用的脚本guid并去重 } referenceGuids.ExceptWith(guids); //提取出不存在的脚本guid EditorUtility.ClearProgressBar(); return(referenceGuids); }