LubanClientLoaderInvoker.cs 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using UnityEngine;
  5. namespace ET
  6. {
  7. [Invoke]
  8. public class LubanClientLoaderInvokerGetAll : AInvokeHandler<ConfigLoader.LubanGetAllConfigBytes, ETTask<Dictionary<Type, byte[]>>>
  9. {
  10. public override async ETTask<Dictionary<Type, byte[]>> Handle(ConfigLoader.LubanGetAllConfigBytes args)
  11. {
  12. var output = new Dictionary<Type, byte[]>();
  13. var allTypes = CodeTypes.Instance.GetTypes(typeof(ConfigAttribute));
  14. var isEditor = false;
  15. #if ET10
  16. #if UNITY_EDITOR
  17. isEditor = true;
  18. #else
  19. isEditor = false;
  20. #endif
  21. #else
  22. isEditor = Define.IsEditor;
  23. #endif
  24. if (isEditor)
  25. {
  26. var globalConfig = Resources.Load<GlobalConfig>("GlobalConfig");
  27. var codeMode = globalConfig.CodeMode.ToString();
  28. foreach (Type configType in allTypes)
  29. {
  30. var configAttribute = configType.GetCustomAttributes(typeof(ConfigAttribute), false)[0] as ConfigAttribute;
  31. var configBytes = await EventSystem.Instance.Invoke<ConfigLoader.LubanGetConfigBytes, ETTask<byte[]>>(configAttribute.ConfigType, new ConfigLoader.LubanGetConfigBytes
  32. {
  33. Type = configType,
  34. CodeMode = codeMode
  35. });
  36. if (configBytes != null)
  37. {
  38. output[configType] = configBytes;
  39. }
  40. }
  41. }
  42. else
  43. {
  44. foreach (Type type in allTypes)
  45. {
  46. var v = await ResourcesComponent.Instance.LoadAssetAsync<TextAsset>(type.Name);
  47. output[type] = v.bytes;
  48. }
  49. }
  50. return output;
  51. }
  52. }
  53. [Invoke(ConfigType.Luban)]
  54. public class LubanGetConfigBytes_Luban : AInvokeHandler<ConfigLoader.LubanGetConfigBytes, ETTask<byte[]>>
  55. {
  56. public override async ETTask<byte[]> Handle(ConfigLoader.LubanGetConfigBytes args)
  57. {
  58. var configType = args.Type;
  59. var codeMode = args.CodeMode;
  60. string configFilePath;
  61. if (LubanHelper.StartConfigs.Contains(configType.Name))
  62. {
  63. configFilePath = $"{LubanHelper.ConfigResPath}/StartConfig/{Options.Instance.StartConfig}/Binary/{CodeMode.Server}/{configType.Name}.bytes";
  64. }
  65. else
  66. {
  67. configFilePath = $"{LubanHelper.ConfigResPath}/Config/Binary/{codeMode}/{configType.Name}.bytes";
  68. }
  69. return await File.ReadAllBytesAsync(configFilePath);
  70. }
  71. }
  72. [Invoke(ConfigType.Luban)]
  73. public class LubanClientLoaderInvokerGetOne : AInvokeHandler<ConfigLoader.LubanGetOneConfigBytes, ETTask<byte[]>>
  74. {
  75. public override async ETTask<byte[]> Handle(ConfigLoader.LubanGetOneConfigBytes args)
  76. {
  77. var globalConfig = Resources.Load<GlobalConfig>("GlobalConfig");
  78. var codeMode = globalConfig.CodeMode.ToString();
  79. var configFilePath = $"{LubanHelper.ConfigResPath}/Config/Binary/{codeMode}/{args.ConfigName}.bytes";
  80. return await File.ReadAllBytesAsync(configFilePath);
  81. }
  82. }
  83. }