public static IEnumerable <ScriptId> ListDllScripts(string dllName) { // returns guids // var guids = AssetDatabase.FindAssets ("t:MonoScript"); var scripts = Resources.FindObjectsOfTypeAll <MonoScript> (); foreach (var script in scripts) { if (null == script) { continue; } var Class = script.GetClass(); if (null == Class) { continue; } if (Class.Assembly.GetName().Name == dllName) { var guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(script)); var fileId = FileIDUtil.Compute(Class); yield return(new ScriptId(fileId.ToString(), guid, Class)); } } }
public CCTypeMeta_t(Type t) { type = t; int d = FileIDUtil.Compute(t); fileID = d.ToString(); }
static void Replace() { List <UnityReference> r = new List <UnityReference>(); foreach (var type in Assembly.GetAssembly(typeof(Text)).GetTypes()) { if (type.IsSubclassOf(typeof(UIBehaviour)) && type.IsAbstract == false) { UnityEngine.Debug.Log(type.FullName); var go = new GameObject(); var comp = go.AddComponent(type) as UIBehaviour; var script = MonoScript.FromMonoBehaviour(comp); var path = AssetDatabase.GetAssetPath(script); r.Add(new UnityReference( uiguid, FileIDUtil.Compute(type).ToString(), AssetDatabase.AssetPathToGUID(path), "11500000" )); r.Add(new UnityReference( uiguid2, FileIDUtil.Compute(type).ToString(), AssetDatabase.AssetPathToGUID(path), "11500000" )); GameObject.DestroyImmediate(go); } } ReplaceReferences(Application.dataPath, r, uiguid, uiguid2); }
protected virtual string GetFileIDBinary(string srcGUID) { string result = ""; if (_guidToClass.ContainsKey(srcGUID)) { QuickReferenceFixerAsset.ClassData cData = _guidToClass[srcGUID]; result = FileIDUtil.Compute(cData._tNamespace, cData._tName).ToString(); } return(result); }
private void ParseDLLFile(float progress, string metaFile, ref List <ClassModel> data, int gcLimit, ref int gcCount) { MigrationWindow.DisplayProgressBar("Exporting IDs", "Exporting IDs " + Path.GetFileName(metaFile), progress); string text = File.ReadAllText(metaFile); Match match = constants.RegexGuid.Match(text); if (!match.Success) { Debug.LogError("Could not parse the guid from the dll meta file. File : " + metaFile); } string file = metaFile.Replace(".meta", ""); try { if (Path.GetFileName(file).Contains("Newtonsoft.Json") || Path.GetFileName(file).Contains("YamlDotNet")) { return; } Assembly assembly = Assembly.LoadFile(file); foreach (Type type in assembly.GetTypes()) { if (!type.IsSubclassOf(typeof(MonoBehaviour))) { continue; } MigrationWindow.DisplayProgressBar("Exporting IDs", "Exporting IDs " + type, progress); data.Add(new ClassModel(type, match.Value, FileIDUtil.Compute(type).ToString())); gcCount++; if (gcCount > gcLimit) { GC.Collect(); } } } catch (Exception e) { Debug.LogWarning("Could not load assembly : " + file + "\nException : " + e); } }
//查找行 static int TestAndFindMissInLine(int lineNo, string sLine, out string sNewLine) { sNewLine = ""; Match m = rgx_11500000.Match(sLine); if (m != null && m.Success) { Meta_t v; if (m_dstMetas.TryGetValue(m.Groups[1].ToString(), out v)) { } else { Meta_t v2; if (m_refMetas.TryGetValue(m.Groups[1].ToString(), out v2)) { //如果在ref中找到,那么取得名字 //16007找到Ref = G:/Aotu/worksapce100/Client3/Assets\Src\BattleCore\UI\UGUIImage2.cs , m_Script: {fileID: 11500000, guid: 00c5cc3b6a3258848869cb04912bbefc, type: 3} //那么新的名字就是: int pos = v2.fn.LastIndexOf("\\"); string fn = v2.fn.Substring(pos + 1); int pos2 = fn.LastIndexOf("."); fn = fn.Substring(0, pos2); Type t = m_UIBaseDLL.Find(fn); if (t != null) { Debug.Log(string.Format("[{0}]找到Ref={1},{2},{3}", lineNo, t, v2.fn, sLine)); int fileid = FileIDUtil.Compute(t); string fid = fileid.ToString(); sNewLine = " m_Script: {fileID: " + fid + ", guid: " + m_UIBaseDLL.m_meta.uuid + ", type: 3}"; return(1); } else { Debug.LogWarning(string.Format("[{0}] 未找到Ref={1},{2},{3}", lineNo, t, v2.fn, sLine)); } } else { Debug.LogError(string.Format("[{0}] 未找到Ref={1}", lineNo, sLine)); } } } return(0); }
// Start is called before the first frame update void Start() { Debug.Log(FileIDUtil.Compute(typeof(LibraryTestScript))); }
public void BuildAssemblyInfo(string pattern = ".*") { var DefaultAssetModfiy = new AssetHandler(MakeStringReplaceAssetModify("m_Script")); foreach (var extension in AsssetExtension) { if (!_extension_handler.ContainsKey(extension)) { _extension_handler.TryAdd(extension, DefaultAssetModfiy); } } if (_extension_handler.ContainsKey(".anim")) { _extension_handler[".anim"] = new AssetHandler(MakeStringReplaceAssetModify("script")); } var assembliesname = _assemblies.Select((assembly) => assembly.GetName().Name + ".dll.meta"); var assembliesmeta = new ConcurrentDictionary <string, string>(); //find assemblyname.meta build _assetfiles var assetdirfileinfos = _assetdir.GetFiles("*.*", SearchOption.AllDirectories); Parallel.ForEach(assetdirfileinfos, file => { if (file.Extension == ".meta" && file.Name.Contains(".dll")) { var assemblyname = assembliesname.FirstOrDefault(name => file.Name == name); if (assemblyname != null) { assembliesmeta.TryAdd(assemblyname, file.FullName); } } var regex = new Regex(pattern); if (!regex.IsMatch(file.FullName)) { return; } if (AsssetExtension.Contains(file.Extension)) { _assetfiles.Add(file.FullName); return; } }); //build _assembliesguid; foreach (var assembly in _assemblies) { var assemblyname = assembly.GetName().Name + ".dll.meta"; var assemblymeta = string.Empty; if (!assembliesmeta.TryGetValue(assemblyname, out assemblymeta)) { Console.WriteLine(string.Format("build assmebliesguid: Try Get {0} 'meta failed", assemblyname)); continue; } try { var yaml = new YamlDotNet.Serialization.Deserializer().Deserialize(File.OpenText(assemblymeta)); //var json = new YamlDotNet.Serialization.SerializerBuilder().JsonCompatible().Build().Serialize(yaml); var pairs = (Dictionary <object, object>)yaml; _assembliesguid[assembly] = pairs["guid"].ToString(); } catch (Exception e) { Console.WriteLine(string.Format("build assembliesguid parse {0} failed Exception: {1}", assemblymeta, e)); } } //build _metafiles var metadirfileinfos = _metadir.GetFiles("*.*", SearchOption.AllDirectories); Parallel.ForEach(metadirfileinfos, file => { if (file.Extension != ".meta") { return; } if (!file.Name.Contains(".cs")) { return; } _csmetafiles.AddOrUpdate(file.Name, file.FullName, (key, value) => { Console.WriteLine(string.Format("{0} has exist please change filename&classname.warning replace {1} by {2}", file.Name, ShortPathName(_metadir, value), ShortPathName(_metadir, file.FullName))); return(file.FullName); }); } ); //parse metafiles build _guid2path Parallel.ForEach(_csmetafiles, pair => { try { var yaml = new YamlDotNet.Serialization.Deserializer().Deserialize(File.OpenText(pair.Value)); var pairs = (Dictionary <object, object>)yaml; if (!_guid2path.TryAdd(pairs["guid"].ToString(), pair.Value)) { Console.WriteLine(string.Format("build guidpath add {0},{1} failed", pairs["guid"], pair.Value)); } } catch (Exception e) { Console.WriteLine(string.Format("build guidpath parse {0} failed Exception: {1}", pair.Value, e)); } }); //parse assembly build _type2path & _path2type var types = _assemblies .Select(assembly => assembly.GetTypes()) .SelectMany(t => t) //必须继承ScriptableObject才能序列化 //必须继承MonoBehaviour才能被挂接 .Where(type => type.IsSubclassOf(typeof(UnityEngine.ScriptableObject)) || type.IsSubclassOf(typeof(UnityEngine.MonoBehaviour))).ToList(); Parallel.ForEach(types, type => { var fullpath = string.Empty; if (!_csmetafiles.TryGetValue(type.Name + ".cs.meta", out fullpath)) { Console.WriteLine(string.Format("warning :find {0}.cs failed", type.Name)); return; } if (!_type2path.TryAdd(type, fullpath)) { Console.WriteLine(string.Format("warning :type {0} has existed", type.Name)); return; } if (!_path2type.TryAdd(fullpath, type)) { Console.WriteLine(string.Format("error:type {0} path {1} existed!", type.Name, ShortPathName(_metadir, fullpath))); } if (!_type2fileid.TryAdd(type, FileIDUtil.Compute(type).ToString())) { Console.WriteLine(string.Format("error:type {0} add fileid failed", type.Name)); } }); }
private void DoScan() { if (_typeToReplace == _typeToReplaceWith) { return; } if (_typeToReplace == null) { return; } if (_typeToReplaceWith == null) { return; } //get guids MonoScript script1; MonoScript script2; if (!GetMonoScripts(_typeToReplace, _typeToReplaceWith, out script1, out script2)) { return; } var spath1 = AssetDatabase.GetAssetPath(script1); var spath2 = AssetDatabase.GetAssetPath(script2); var sMetaPath1 = spath1 + ".meta"; var sMetaPath2 = spath2 + ".meta"; string sguid1; string sguid2; if (!this.GetGUIDs(sMetaPath1, sMetaPath2, out sguid1, out sguid2)) { return; } string fileid1 = (spath1.EndsWith(".dll", System.StringComparison.OrdinalIgnoreCase)) ? FileIDUtil.Compute(_typeToReplace).ToString() : "11500000"; string fileid2 = (spath2.EndsWith(".dll", System.StringComparison.OrdinalIgnoreCase)) ? FileIDUtil.Compute(_typeToReplaceWith).ToString() : "11500000"; const string MATCH_PATTERN = "{{fileID: {0}, guid: {1}, type: 3}}"; foreach (var sfile in Directory.GetFiles(Application.dataPath, "*.unity", SearchOption.AllDirectories)) { var pattern = string.Format(MATCH_PATTERN, fileid1, sguid1); string contents; using (var tr = new StreamReader(sfile)) { contents = tr.ReadToEnd(); } if (contents.Contains(pattern)) { contents = contents.Replace(pattern, string.Format(MATCH_PATTERN, fileid2, sguid2)); using (var tw = new StreamWriter(sfile, false)) { tw.Write(contents); Debug.Log(sfile); } } } foreach (var sfile in Directory.GetFiles(Application.dataPath, "*.prefab", SearchOption.AllDirectories)) { var pattern = string.Format(MATCH_PATTERN, fileid1, sguid1); string contents; using (var tr = new StreamReader(sfile)) { contents = tr.ReadToEnd(); } if (contents.Contains(pattern)) { contents = contents.Replace(pattern, string.Format(MATCH_PATTERN, fileid2, sguid2)); using (var tw = new StreamWriter(sfile, false)) { tw.Write(contents); Debug.Log(sfile); } } } }