static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { //Debug.Log( $"i:{importedAssets.Length}, d:{deletedAssets.Length}, ma:{movedAssets.Length}, mfap:{movedFromAssetPaths.Length}" ); if (E.i.m_asmdefNameSync || E.i.m_asmdefAutoReferenceOFF) { var _asmdefNameSync = E.i.m_asmdefNameSync; var _asmdefAutoReferenceOFF = E.i.m_asmdefAutoReferenceOFF; foreach (var p in importedAssets) { if (p[0] == 'P') { continue; } if (!p.EndsWith(".asmdef")) { continue; } bool dirty = false; var asmdef = p.LoadAsset <AssemblyDefinitionAsset>(); var json = (Dictionary <string, object>)UnityEditorJson.Deserialize(asmdef.text); if (_asmdefNameSync) { var fname = p.FileNameWithoutExtension(); if ((string)json["name"] != fname) { json["name"] = fname; dirty = true; } } if (_asmdefAutoReferenceOFF) { if (json.ContainsKey("autoReferenced")) { if ((bool)json["autoReferenced"]) { json["autoReferenced"] = false; dirty = true; } } else { json.Add("autoReferenced", false); dirty = true; } } if (dirty) { fs.WriteAllText(p, EditorJson.Serialize(json, true), new UTF8Encoding(false)); AssetDatabase.ImportAsset(p); } } } }
public static void SyncCSProject(AssemblyDefinitionAsset asset) { var m_data = (Dictionary <string, object>)EditorJson.Deserialize(asset.text); var aname = (string)m_data["name"]; var aa = UnityEditor.Compilation.CompilationPipeline.GetAssemblies().Where(x => x.name == aname).ToArray(); var sourceList = aa[0].sourceFiles; //Task.Run(_); //void _() { var cspath = $"{System.Environment.CurrentDirectory}/{aname}.csproj".separatorToOS(); var content = fs.ReadAllText(cspath); var ss = content.Replace("\r", "").Split('\n'); int step = 0; fs.WriteFileAll(cspath, (b) => { foreach (var s in ss) { if (step == 0) { if (s.Contains("Compile Include")) { step = 1; continue; } } else if (step == 1) { if (s.Contains("None Include") || s.Contains("Reference Include")) { step = 2; foreach (var c in aa[0].sourceFiles) { b.AppendLine($" <Compile Include=\"{c.separatorToOS()}\" />"); } } else { continue; } } b.AppendLine(s); } }, utf8bom: true, newLineLinux: false); //} }
public static void Save() { File.WriteAllText(kPATH, EditorJson.Serialize(s_manifest, true)); AssetDatabase.Refresh(); }
public static void Load() { s_manifest = EditorJson.Deserialize(File.ReadAllText(kPATH)) as Dictionary <string, object>; }