ScriptingAssembliesJsonPatcher.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using UnityEngine;
  8. namespace HybridCLR.Editor.BuildProcessors
  9. {
  10. public class ScriptingAssembliesJsonPatcher
  11. {
  12. [Serializable]
  13. private class ScriptingAssemblies
  14. {
  15. public List<string> names;
  16. public List<int> types;
  17. }
  18. private string _file;
  19. ScriptingAssemblies _scriptingAssemblies;
  20. public void Load(string file)
  21. {
  22. _file = file;
  23. string content = File.ReadAllText(file);
  24. _scriptingAssemblies = JsonUtility.FromJson<ScriptingAssemblies>(content);
  25. }
  26. public void AddScriptingAssemblies(List<string> assemblies)
  27. {
  28. foreach (string name in assemblies)
  29. {
  30. if (!_scriptingAssemblies.names.Contains(name))
  31. {
  32. _scriptingAssemblies.names.Add(name);
  33. _scriptingAssemblies.types.Add(16); // user dll type
  34. Debug.Log($"[PatchScriptAssembliesJson] add hotfix assembly:{name} to {_file}");
  35. }
  36. }
  37. }
  38. public void Save(string jsonFile)
  39. {
  40. string content = JsonUtility.ToJson(_scriptingAssemblies);
  41. File.WriteAllText(jsonFile, content);
  42. }
  43. }
  44. }