ConfigLoader.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using UnityEngine;
  5. namespace ET.Client
  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/GenFromExcel/{ct}/{Options.Instance.StartConfig}/{configType.Name}.bytes";
  46. }
  47. else
  48. {
  49. configFilePath = $"../Config/GenFromExcel/{ct}/{configType.Name}.bytes";
  50. }
  51. output[configType] = File.ReadAllBytes(configFilePath);
  52. }
  53. }
  54. else
  55. {
  56. using (Root.Instance.Scene.AddComponent<ResourcesComponent>())
  57. {
  58. const string configBundleName = "config.unity3d";
  59. ResourcesComponent.Instance.LoadBundle(configBundleName);
  60. foreach (Type configType in configTypes)
  61. {
  62. TextAsset v = ResourcesComponent.Instance.GetAsset(configBundleName, configType.Name) as TextAsset;
  63. output[configType] = v.bytes;
  64. }
  65. }
  66. }
  67. return output;
  68. }
  69. }
  70. [Invoke]
  71. public class GetOneConfigBytes: AInvokeHandler<ConfigComponent.GetOneConfigBytes, byte[]>
  72. {
  73. public override byte[] Handle(ConfigComponent.GetOneConfigBytes args)
  74. {
  75. //TextAsset v = ResourcesComponent.Instance.GetAsset("config.unity3d", configName) as TextAsset;
  76. //return v.bytes;
  77. throw new NotImplementedException("client cant use LoadOneConfig");
  78. }
  79. }
  80. }