Exemple #1
0
 private void FindObject(string path)
 {
     if (!string.IsNullOrEmpty(path))
     {
         Regex           guidRegex = new Regex("m_Script: {fileID: (.*), guid: (?<GuidValue>.*?), type:");
         MatchCollection matchList = guidRegex.Matches(File.ReadAllText(path));
         if (matchList != null)
         {
             MissComponentInfo info = new MissComponentInfo(path);
             for (int i = 0; i < matchList.Count; i++)
             {
                 string guid = matchList[i].Groups["GuidValue"].Value;
                 string p    = AssetDatabase.GUIDToAssetPath(guid);
                 if (string.IsNullOrEmpty(p) || !File.Exists(p))
                 {
                     MissComponent mc = new MissComponent(guid, p);
                     info.AddComponent(mc);
                 }
             }
             if (info.components.Count > 0)
             {
                 m_infos.Add(info);
             }
         }
     }
 }
Exemple #2
0
        private void CleanObject(MissComponentInfo info)
        {
            string content = File.ReadAllText(info.path);

            string[] strArray = content.Split(new string[] { "---" }, StringSplitOptions.RemoveEmptyEntries);
            Regex    regBlock = new Regex("MonoBehaviour");

            for (int i = 0; i < strArray.Length; i++)
            {
                string blockStr = strArray[i];
                if (regBlock.IsMatch(blockStr))
                {
                    Match guidMatch = Regex.Match(blockStr, "m_Script: {fileID: (.*), guid: (?<GuidValue>.*?), type:");
                    if (guidMatch.Success)
                    {
                        string guid = guidMatch.Groups["GuidValue"].Value;
                        for (int k = 0; k < info.components.Count; k++)
                        {
                            var mc = info.components[k];
                            if (mc.guid == guid)
                            {
                                // remove MonoBehaviour
                                content = content.Replace("---" + blockStr, "");

                                // 移除 MonoBehaviour 引用
                                Match fileIdMatch = Regex.Match(blockStr, " !u!(.*) &(?<FileIdValue>.*?)\n");
                                if (fileIdMatch.Success)
                                {
                                    string fileId = fileIdMatch.Groups["FileIdValue"].Value;
                                    Regex  quote  = new Regex("  - (.*): {fileID: " + fileId + "}");
                                    content = quote.Replace(content, "");
                                }

                                Debug.Log(string.Format("miss component -> remove {0} guid:{1}", info.path, guid));
                                break;
                            }
                        }
                    }
                }
            }

            File.WriteAllText(info.path, content);
        }