ConfigLoader.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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<ConfigComponent.GetAllConfigBytes, Dictionary<Type, byte[]>>
  9. {
  10. public override Dictionary<Type, byte[]> Handle(ConfigComponent.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<ConfigComponent.GetOneConfigBytes, byte[]>
  68. {
  69. public override byte[] Handle(ConfigComponent.GetOneConfigBytes args)
  70. {
  71. throw new NotImplementedException("client cant use LoadOneConfig");
  72. }
  73. }
  74. }