SettingsUtil.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using UnityEditor;
  6. using UnityEditorInternal;
  7. using UnityEngine;
  8. using HybridCLR.Editor.Settings;
  9. namespace HybridCLR.Editor
  10. {
  11. public static class SettingsUtil
  12. {
  13. public static bool Enable
  14. {
  15. get => HybridCLRSettings.Instance.enable;
  16. set
  17. {
  18. HybridCLRSettings.Instance.enable = value;
  19. HybridCLRSettings.Save();
  20. }
  21. }
  22. public static string PackageName { get; } = "com.code-philosophy.hybridclr";
  23. public static string HybridCLRDataPathInPackage => $"Packages/{PackageName}/Data~";
  24. public static string TemplatePathInPackage => $"{HybridCLRDataPathInPackage}/Templates";
  25. public static string ProjectDir { get; } = Directory.GetParent(Application.dataPath).ToString();
  26. public static string ScriptingAssembliesJsonFile { get; } = "ScriptingAssemblies.json";
  27. public static string HotUpdateDllsRootOutputDir => HybridCLRSettings.Instance.hotUpdateDllCompileOutputRootDir;
  28. public static string AssembliesPostIl2CppStripDir => HybridCLRSettings.Instance.strippedAOTDllOutputRootDir;
  29. public static string HybridCLRDataDir => $"{ProjectDir}/HybridCLRData";
  30. public static string LocalUnityDataDir => $"{HybridCLRDataDir}/LocalIl2CppData-{Application.platform}";
  31. public static string LocalIl2CppDir => $"{LocalUnityDataDir}/il2cpp";
  32. public static string GeneratedCppDir => $"{LocalIl2CppDir}/libil2cpp/hybridclr/generated";
  33. public static string Il2CppBuildCacheDir { get; } = $"{ProjectDir}/Library/Il2cppBuildCache";
  34. public static string GetHotUpdateDllsOutputDirByTarget(BuildTarget target)
  35. {
  36. return $"{HotUpdateDllsRootOutputDir}/{target}";
  37. }
  38. public static string GetAssembliesPostIl2CppStripDir(BuildTarget target)
  39. {
  40. return $"{AssembliesPostIl2CppStripDir}/{target}";
  41. }
  42. class AssemblyDefinitionData
  43. {
  44. public string name;
  45. }
  46. /// <summary>
  47. /// 热更新dll列表。不包含 preserveHotUpdateAssemblies。
  48. /// </summary>
  49. public static List<string> HotUpdateAssemblyNamesExcludePreserved
  50. {
  51. get
  52. {
  53. var gs = HybridCLRSettings.Instance;
  54. var hotfixAssNames = (gs.hotUpdateAssemblyDefinitions ?? Array.Empty<AssemblyDefinitionAsset>()).Select(ad => JsonUtility.FromJson<AssemblyDefinitionData>(ad.text));
  55. var hotfixAssembles = new List<string>();
  56. foreach (var assName in hotfixAssNames)
  57. {
  58. hotfixAssembles.Add(assName.name);
  59. }
  60. hotfixAssembles.AddRange(gs.hotUpdateAssemblies ?? Array.Empty<string>());
  61. return hotfixAssembles.ToList();
  62. }
  63. }
  64. public static List<string> HotUpdateAssemblyFilesExcludePreserved => HotUpdateAssemblyNamesExcludePreserved.Select(dll => dll + ".dll").ToList();
  65. public static List<string> HotUpdateAssemblyNamesIncludePreserved
  66. {
  67. get
  68. {
  69. List<string> allAsses = HotUpdateAssemblyNamesExcludePreserved;
  70. string[] preserveAssemblyNames = HybridCLRSettings.Instance.preserveHotUpdateAssemblies;
  71. if (preserveAssemblyNames != null && preserveAssemblyNames.Length > 0)
  72. {
  73. foreach (var assemblyName in preserveAssemblyNames)
  74. {
  75. if (allAsses.Contains(assemblyName))
  76. {
  77. throw new Exception($"[HotUpdateAssemblyNamesIncludePreserved] assembly:'{assemblyName}' is duplicated");
  78. }
  79. allAsses.Add(assemblyName);
  80. }
  81. }
  82. return allAsses;
  83. }
  84. }
  85. public static List<string> HotUpdateAssemblyFilesIncludePreserved => HotUpdateAssemblyNamesIncludePreserved.Select(ass => ass + ".dll").ToList();
  86. public static List<string> AOTAssemblyNames => HybridCLRSettings.Instance.patchAOTAssemblies.ToList();
  87. public static HybridCLRSettings HybridCLRSettings => HybridCLRSettings.Instance;
  88. }
  89. }