|
|
@@ -1,6 +1,6 @@
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
-
|
|
|
+using System.Threading.Tasks;
|
|
|
|
|
|
namespace ET
|
|
|
{
|
|
|
@@ -21,7 +21,6 @@ namespace ET
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
public class ConfigDestroySystem : DestroySystem<ConfigComponent>
|
|
|
{
|
|
|
public override void Destroy(ConfigComponent self)
|
|
|
@@ -40,21 +39,51 @@ namespace ET
|
|
|
public static void Load(this ConfigComponent self)
|
|
|
{
|
|
|
self.AllConfig.Clear();
|
|
|
- HashSet<Type> types = Game.EventSystem.GetTypes(typeof(ConfigAttribute));
|
|
|
+ HashSet<Type> types = Game.EventSystem.GetTypes(typeof (ConfigAttribute));
|
|
|
+
|
|
|
+ Dictionary<string, byte[]> configBytes = new Dictionary<string, byte[]>();
|
|
|
+ FunctionCallback.GetAllConfigBytes(configBytes);
|
|
|
+
|
|
|
+ List<Task> listTasks = new List<Task>();
|
|
|
+
|
|
|
+ foreach (Type type in types)
|
|
|
+ {
|
|
|
+ Task task = Task.Run(() => self.LoadOneInThread(type, configBytes));
|
|
|
+ listTasks.Add(task);
|
|
|
+ }
|
|
|
+
|
|
|
+ Task.WaitAll(listTasks.ToArray());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static async ETTask LoadAsync(this ConfigComponent self)
|
|
|
+ {
|
|
|
+ self.AllConfig.Clear();
|
|
|
+ HashSet<Type> types = Game.EventSystem.GetTypes(typeof (ConfigAttribute));
|
|
|
+
|
|
|
+ Dictionary<string, byte[]> configBytes = new Dictionary<string, byte[]>();
|
|
|
+ FunctionCallback.GetAllConfigBytes(configBytes);
|
|
|
+
|
|
|
+ List<Task> listTasks = new List<Task>();
|
|
|
|
|
|
foreach (Type type in types)
|
|
|
{
|
|
|
- object obj = Activator.CreateInstance(type);
|
|
|
+ Task task = Task.Run(() => self.LoadOneInThread(type, configBytes));
|
|
|
+ listTasks.Add(task);
|
|
|
+ }
|
|
|
|
|
|
- ACategory iCategory = obj as ACategory;
|
|
|
- if (iCategory == null)
|
|
|
- {
|
|
|
- throw new Exception($"class: {type.Name} not inherit from ACategory");
|
|
|
- }
|
|
|
- iCategory.BeginInit();
|
|
|
- iCategory.EndInit();
|
|
|
+ await Task.WhenAll(listTasks.ToArray());
|
|
|
+ }
|
|
|
|
|
|
- self.AllConfig[iCategory.ConfigType] = iCategory;
|
|
|
+ private static void LoadOneInThread(this ConfigComponent self, Type configType, Dictionary<string, byte[]> configBytes)
|
|
|
+ {
|
|
|
+ byte[] oneConfigBytes = configBytes[configType.Name];
|
|
|
+
|
|
|
+ object category = ProtobufHelper.FromBytes(configType, oneConfigBytes, 0, oneConfigBytes.Length);
|
|
|
+
|
|
|
+ lock (self)
|
|
|
+ {
|
|
|
+ self.AllConfig[configType] = category;
|
|
|
}
|
|
|
}
|
|
|
}
|