ConfigLoader.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. namespace ET.Server
  5. {
  6. [Invoke]
  7. public class GetAllConfigBytes: AInvokeHandler<ConfigComponent.GetAllConfigBytes, Dictionary<Type, byte[]>>
  8. {
  9. public override Dictionary<Type, byte[]> Handle(ConfigComponent.GetAllConfigBytes args)
  10. {
  11. Dictionary<Type, byte[]> output = new Dictionary<Type, byte[]>();
  12. List<string> startConfigs = new List<string>()
  13. {
  14. "StartMachineConfigCategory",
  15. "StartProcessConfigCategory",
  16. "StartSceneConfigCategory",
  17. "StartZoneConfigCategory",
  18. };
  19. HashSet<Type> configTypes = EventSystem.Instance.GetTypes(typeof (ConfigAttribute));
  20. foreach (Type configType in configTypes)
  21. {
  22. string configFilePath;
  23. if (startConfigs.Contains(configType.Name))
  24. {
  25. configFilePath = $"../Config/GenFromExcel/s/{Options.Instance.StartConfig}/{configType.Name}.bytes";
  26. }
  27. else
  28. {
  29. configFilePath = $"../Config/GenFromExcel/s/{configType.Name}.bytes";
  30. }
  31. output[configType] = File.ReadAllBytes(configFilePath);
  32. }
  33. return output;
  34. }
  35. }
  36. [Invoke]
  37. public class GetOneConfigBytes: AInvokeHandler<ConfigComponent.GetOneConfigBytes, byte[]>
  38. {
  39. public override byte[] Handle(ConfigComponent.GetOneConfigBytes args)
  40. {
  41. byte[] configBytes = File.ReadAllBytes($"../Config/GenFromExcel/{args.ConfigName}.bytes");
  42. return configBytes;
  43. }
  44. }
  45. }