|
@@ -12,12 +12,12 @@ namespace ET
|
|
|
public struct GetAllConfigBytes
|
|
|
{
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public struct GetOneConfigBytes
|
|
|
{
|
|
|
public string ConfigName;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private readonly Dictionary<Type, ISingleton> allConfig = new Dictionary<Type, ISingleton>();
|
|
|
|
|
|
public override void Dispose()
|
|
@@ -35,17 +35,17 @@ namespace ET
|
|
|
{
|
|
|
oneConfig.Destroy();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
byte[] oneConfigBytes = EventSystem.Instance.Invoke<GetOneConfigBytes, byte[]>(0, new GetOneConfigBytes() {ConfigName = configType.FullName});
|
|
|
|
|
|
object category = SerializeHelper.Deserialize(configType, oneConfigBytes, 0, oneConfigBytes.Length);
|
|
|
ISingleton singleton = category as ISingleton;
|
|
|
singleton.Register();
|
|
|
-
|
|
|
+
|
|
|
this.allConfig[configType] = singleton;
|
|
|
return category;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public void Load()
|
|
|
{
|
|
|
this.allConfig.Clear();
|
|
@@ -57,14 +57,14 @@ namespace ET
|
|
|
this.LoadOneInThread(type, oneConfigBytes);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public async ETTask LoadAsync()
|
|
|
{
|
|
|
this.allConfig.Clear();
|
|
|
Dictionary<Type, byte[]> configBytes = EventSystem.Instance.Invoke<GetAllConfigBytes, Dictionary<Type, byte[]>>(0, new GetAllConfigBytes());
|
|
|
|
|
|
using ListComponent<Task> listTasks = ListComponent<Task>.Create();
|
|
|
-
|
|
|
+
|
|
|
foreach (Type type in configBytes.Keys)
|
|
|
{
|
|
|
byte[] oneConfigBytes = configBytes[type];
|
|
@@ -73,21 +73,17 @@ namespace ET
|
|
|
}
|
|
|
|
|
|
await Task.WhenAll(listTasks.ToArray());
|
|
|
-
|
|
|
- foreach (ISingleton category in this.allConfig.Values)
|
|
|
- {
|
|
|
- category.Register();
|
|
|
- }
|
|
|
- Log.Debug("register all config ok");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private void LoadOneInThread(Type configType, byte[] oneConfigBytes)
|
|
|
{
|
|
|
object category = SerializeHelper.Deserialize(configType, oneConfigBytes, 0, oneConfigBytes.Length);
|
|
|
Log.Debug($"Deserialize: {configType} ok");
|
|
|
lock (this)
|
|
|
{
|
|
|
- this.allConfig[configType] = category as ISingleton;
|
|
|
+ ISingleton singleton = category as ISingleton;
|
|
|
+ singleton.Register();
|
|
|
+ this.allConfig[configType] = singleton;
|
|
|
}
|
|
|
}
|
|
|
}
|