12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using UnityEngine;
- namespace ET.Client
- {
- [Invoke]
- public class GetAllConfigBytes: AInvokeHandler<ConfigComponent.GetAllConfigBytes, Dictionary<Type, byte[]>>
- {
- public override Dictionary<Type, byte[]> Handle(ConfigComponent.GetAllConfigBytes args)
- {
- Dictionary<Type, byte[]> output = new Dictionary<Type, byte[]>();
- HashSet<Type> configTypes = EventSystem.Instance.GetTypes(typeof (ConfigAttribute));
-
- if (Define.IsEditor)
- {
- string ct = "cs";
- GlobalConfig globalConfig = Resources.Load<GlobalConfig>("GlobalConfig");
- CodeMode codeMode = globalConfig.CodeMode;
- switch (codeMode)
- {
- case CodeMode.Client:
- ct = "c";
- break;
- case CodeMode.Server:
- ct = "s";
- break;
- case CodeMode.ClientServer:
- ct = "cs";
- break;
- default:
- throw new ArgumentOutOfRangeException();
- }
- List<string> startConfigs = new List<string>()
- {
- "StartMachineConfigCategory",
- "StartProcessConfigCategory",
- "StartSceneConfigCategory",
- "StartZoneConfigCategory",
- };
- foreach (Type configType in configTypes)
- {
- string configFilePath;
- if (startConfigs.Contains(configType.Name))
- {
- configFilePath = $"../Config/GenFromExcel/{ct}/{Options.Instance.StartConfig}/{configType.Name}.bytes";
- }
- else
- {
- configFilePath = $"../Config/GenFromExcel/{ct}/{configType.Name}.bytes";
- }
- output[configType] = File.ReadAllBytes(configFilePath);
- }
- }
- else
- {
- using (Root.Instance.Scene.AddComponent<ResourcesComponent>())
- {
- const string configBundleName = "config.unity3d";
- ResourcesComponent.Instance.LoadBundle(configBundleName);
-
- foreach (Type configType in configTypes)
- {
- TextAsset v = ResourcesComponent.Instance.GetAsset(configBundleName, configType.Name) as TextAsset;
- output[configType] = v.bytes;
- }
- }
- }
- return output;
- }
- }
-
- [Invoke]
- public class GetOneConfigBytes: AInvokeHandler<ConfigComponent.GetOneConfigBytes, byte[]>
- {
- public override byte[] Handle(ConfigComponent.GetOneConfigBytes args)
- {
- //TextAsset v = ResourcesComponent.Instance.GetAsset("config.unity3d", configName) as TextAsset;
- //return v.bytes;
- throw new NotImplementedException("client cant use LoadOneConfig");
- }
- }
- }
|