ConfigLoader.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using UnityEngine;
  5. namespace ET
  6. {
  7. [Invoke]
  8. public class GetAllConfigBytes: AInvokeHandler<ConfigLoader.GetAllConfigBytes, Dictionary<Type, byte[]>>
  9. {
  10. public override Dictionary<Type, byte[]> Handle(ConfigLoader.GetAllConfigBytes args)
  11. {
  12. Dictionary<Type, byte[]> output = new Dictionary<Type, byte[]>();
  13. HashSet<Type> configTypes = EventSystem.Instance.GetTypes(typeof (ConfigAttribute));
  14. if (Define.IsEditor)
  15. {
  16. string ct = "cs";
  17. GlobalConfig globalConfig = Resources.Load<GlobalConfig>("GlobalConfig");
  18. CodeMode codeMode = globalConfig.CodeMode;
  19. switch (codeMode)
  20. {
  21. case CodeMode.Client:
  22. ct = "c";
  23. break;
  24. case CodeMode.Server:
  25. ct = "s";
  26. break;
  27. case CodeMode.ClientServer:
  28. ct = "cs";
  29. break;
  30. default:
  31. throw new ArgumentOutOfRangeException();
  32. }
  33. List<string> startConfigs = new List<string>()
  34. {
  35. "StartMachineConfigCategory",
  36. "StartProcessConfigCategory",
  37. "StartSceneConfigCategory",
  38. "StartZoneConfigCategory",
  39. };
  40. foreach (Type configType in configTypes)
  41. {
  42. string configFilePath;
  43. if (startConfigs.Contains(configType.Name))
  44. {
  45. configFilePath = $"../Config/Excel/{ct}/{Options.Instance.StartConfig}/{configType.Name}.bytes";
  46. }
  47. else
  48. {
  49. configFilePath = $"../Config/Excel/{ct}/{configType.Name}.bytes";
  50. }
  51. output[configType] = File.ReadAllBytes(configFilePath);
  52. }
  53. }
  54. else
  55. {
  56. Dictionary<string, UnityEngine.Object> dictionary = AssetsBundleHelper.LoadBundle("config.unity3d");
  57. foreach (Type type in configTypes)
  58. {
  59. TextAsset v = dictionary[type.Name] as TextAsset;
  60. output[type] = v.bytes;
  61. }
  62. }
  63. return output;
  64. }
  65. }
  66. [Invoke]
  67. public class GetOneConfigBytes: AInvokeHandler<ConfigLoader.GetOneConfigBytes, byte[]>
  68. {
  69. public override byte[] Handle(ConfigLoader.GetOneConfigBytes args)
  70. {
  71. string ct = "cs";
  72. GlobalConfig globalConfig = Resources.Load<GlobalConfig>("GlobalConfig");
  73. CodeMode codeMode = globalConfig.CodeMode;
  74. switch (codeMode)
  75. {
  76. case CodeMode.Client:
  77. ct = "c";
  78. break;
  79. case CodeMode.Server:
  80. ct = "s";
  81. break;
  82. case CodeMode.ClientServer:
  83. ct = "cs";
  84. break;
  85. default:
  86. throw new ArgumentOutOfRangeException();
  87. }
  88. List<string> startConfigs = new List<string>()
  89. {
  90. "StartMachineConfigCategory",
  91. "StartProcessConfigCategory",
  92. "StartSceneConfigCategory",
  93. "StartZoneConfigCategory",
  94. };
  95. string configName = args.ConfigName;
  96. string configFilePath;
  97. if (startConfigs.Contains(configName))
  98. {
  99. configFilePath = $"../Config/Excel/{ct}/{Options.Instance.StartConfig}/{configName}.bytes";
  100. }
  101. else
  102. {
  103. configFilePath = $"../Config/Excel/{ct}/{configName}.bytes";
  104. }
  105. return File.ReadAllBytes(configFilePath);
  106. }
  107. }
  108. }