CodeLoader.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Reflection;
  5. using UnityEngine;
  6. #pragma warning disable CS0162
  7. namespace ET
  8. {
  9. public class CodeLoader: Singleton<CodeLoader>
  10. {
  11. private Assembly assembly;
  12. public void Start()
  13. {
  14. if (!Define.EnableCodes)
  15. {
  16. GlobalConfig globalConfig = Resources.Load<GlobalConfig>("GlobalConfig");
  17. if (globalConfig.CodeMode != CodeMode.ClientServer)
  18. {
  19. throw new Exception("!ENABLE_CODES mode must use ClientServer code mode!");
  20. }
  21. Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
  22. Dictionary<string, Type> types = AssemblyHelper.GetAssemblyTypes(assemblies);
  23. EventSystem.Instance.Add(types);
  24. foreach (Assembly ass in assemblies)
  25. {
  26. string name = ass.GetName().Name;
  27. if (name == "Unity.Model")
  28. {
  29. this.assembly = ass;
  30. }
  31. }
  32. }
  33. else
  34. {
  35. byte[] assBytes;
  36. byte[] pdbBytes;
  37. if (!Define.IsEditor)
  38. {
  39. //Dictionary<string, UnityEngine.Object> dictionary = AssetsBundleHelper.LoadBundle("code.unity3d");
  40. //assBytes = ((TextAsset)dictionary["Codes.dll"]).bytes;
  41. //pdbBytes = ((TextAsset)dictionary["Codes.pdb"]).bytes;
  42. assBytes = File.ReadAllBytes(Path.Combine("../Unity", Define.BuildOutputDir, "Codes.dll"));
  43. pdbBytes = File.ReadAllBytes(Path.Combine("../Unity", Define.BuildOutputDir, "Codes.pdb"));
  44. if (Define.EnableIL2CPP)
  45. {
  46. HybridCLRHelper.Load();
  47. }
  48. }
  49. else
  50. {
  51. assBytes = File.ReadAllBytes(Path.Combine(Define.BuildOutputDir, "Codes.dll"));
  52. pdbBytes = File.ReadAllBytes(Path.Combine(Define.BuildOutputDir, "Codes.pdb"));
  53. }
  54. this.assembly = Assembly.Load(assBytes, pdbBytes);
  55. Dictionary<string, Type> types = AssemblyHelper.GetAssemblyTypes(typeof (Game).Assembly, typeof(Init).Assembly, this.assembly);
  56. EventSystem.Instance.Add(types);
  57. }
  58. IStaticMethod start = new StaticMethod(this.assembly, "ET.Entry", "Start");
  59. start.Run();
  60. }
  61. }
  62. }