tanghai 3 лет назад
Родитель
Сommit
18658cff0e

+ 5 - 4
Codes/ModelView/Client/Demo/Config/ConfigLoader.cs

@@ -13,13 +13,14 @@ namespace ET.Client
             {
                 const string configBundleName = "config.unity3d";
                 ResourcesComponent.Instance.LoadBundle(configBundleName);
+                
                 Dictionary<string, UnityEngine.Object> keys = ResourcesComponent.Instance.GetBundleAll(configBundleName);
 
-                foreach (var kv in keys)
+                HashSet<Type> configTypes = Game.EventSystem.GetTypes(typeof (ConfigAttribute));
+                foreach (Type configType in configTypes)
                 {
-                    TextAsset v = kv.Value as TextAsset;
-                    string key = kv.Key;
-                    output[key] = v.bytes;
+                    TextAsset v = keys[configType.Name] as TextAsset;
+                    output[configType.Name] = v.bytes;
                 }
             }
         }

+ 7 - 18
Codes/ModelView/Client/Module/Resource/ResourcesComponent.cs

@@ -63,22 +63,6 @@ namespace ET.Client
     [FriendOf(typeof(ResourcesComponent))]
     public static class AssetBundleHelper
     {
-        public static async ETTask<AssetBundle> UnityLoadBundleAsync(string path)
-        {
-            var tcs = ETTask<AssetBundle>.Create(true);
-            AssetBundleCreateRequest request = AssetBundle.LoadFromFileAsync(path);
-            request.completed += operation => { tcs.SetResult(request.assetBundle); };
-            return await tcs;
-        }
-
-        public static async ETTask<UnityEngine.Object[]> UnityLoadAssetAsync(AssetBundle assetBundle)
-        {
-            var tcs = ETTask<UnityEngine.Object[]>.Create(true);
-            AssetBundleRequest request = assetBundle.LoadAllAssetsAsync();
-            request.completed += operation => { tcs.SetResult(request.allAssets); };
-            return await tcs;
-        }
-
         public static string IntToString(this int value)
         {
             string result;
@@ -140,6 +124,7 @@ namespace ET.Client
                 {
                     self.LoadOneBundle("StreamingAssets");
                     self.AssetBundleManifestObject = (AssetBundleManifest)self.GetAsset("StreamingAssets", "AssetBundleManifest");
+                    self.UnloadBundle("StreamingAssets");
                 }
             }
         }
@@ -542,7 +527,9 @@ namespace ET.Client
             //     Log.Error("Async load bundle not exist! BundleName : " + p);
             //     return null;
             // }
-            assetBundle = await AssetBundleHelper.UnityLoadBundleAsync(p);
+            AssetBundleCreateRequest assetBundleCreateRequest = AssetBundle.LoadFromFileAsync(p);
+            await assetBundleCreateRequest;
+            assetBundle = assetBundleCreateRequest.assetBundle;
             if (assetBundle == null)
             {
                 // 获取资源的时候会抛异常,这个地方不直接抛异常,因为有些地方需要Load之后判断是否Load成功
@@ -571,7 +558,9 @@ namespace ET.Client
                 if (abInfo.AssetBundle != null && !abInfo.AssetBundle.isStreamedSceneAssetBundle)
                 {
                     // 异步load资源到内存cache住
-                    var assets = await AssetBundleHelper.UnityLoadAssetAsync(abInfo.AssetBundle);
+                    AssetBundleRequest request = abInfo.AssetBundle.LoadAllAssetsAsync();
+                    await request;
+                    UnityEngine.Object[] assets = request.allAssets;
 
                     foreach (UnityEngine.Object asset in assets)
                     {

+ 20 - 7
DotNet/Model/ConfigLoader.cs

@@ -1,3 +1,4 @@
+using System;
 using System.Collections.Generic;
 using System.IO;
 
@@ -8,15 +9,27 @@ namespace ET.Server
     {
         public void Handle(ConfigComponent configComponent, Dictionary<string, byte[]> output)
         {
-            foreach (string file in Directory.GetFiles($"../Config", "*.bytes"))
+            List<string> startConfigs = new List<string>()
             {
-                string key = Path.GetFileNameWithoutExtension(file);
-                output[key] = File.ReadAllBytes(file);
+                "StartMachineConfigCategory", 
+                "StartProcessConfigCategory", 
+                "StartSceneConfigCategory", 
+                "StartZoneConfigCategory",
+            };
+            HashSet<Type> configTypes = Game.EventSystem.GetTypes(typeof (ConfigAttribute));
+            foreach (Type configType in configTypes)
+            {
+                string configFilePath;
+                if (startConfigs.Contains(configType.Name))
+                {
+                    configFilePath = $"../Config/{Game.Options.StartConfig}/{configType.Name}.bytes";    
+                }
+                else
+                {
+                    configFilePath = $"../Config/{configType.Name}.bytes";
+                }
+                output[configType.Name] = File.ReadAllBytes(configFilePath);
             }
-            output["StartMachineConfigCategory"] = File.ReadAllBytes($"../Config/{Game.Options.StartConfig}/StartMachineConfigCategory.bytes");
-            output["StartProcessConfigCategory"] = File.ReadAllBytes($"../Config/{Game.Options.StartConfig}/StartProcessConfigCategory.bytes");
-            output["StartSceneConfigCategory"] = File.ReadAllBytes($"../Config/{Game.Options.StartConfig}/StartSceneConfigCategory.bytes");
-            output["StartZoneConfigCategory"] = File.ReadAllBytes($"../Config/{Game.Options.StartConfig}/StartZoneConfigCategory.bytes");
         }
     }
     

+ 2 - 2
Unity/Assets/Scripts/Core/Object/ComponentOfAttribute.cs

@@ -10,11 +10,11 @@ namespace ET
     [AttributeUsage(AttributeTargets.Class)]
     public class ComponentOfAttribute : Attribute
     {
-        public Type type;
+        public Type Type;
 
         public ComponentOfAttribute(Type type = null)
         {
-            this.type = type;
+            this.Type = type;
         }
     }
 }

+ 0 - 77
Unity/Assets/Scripts/Core/QueueDictionary.cs

@@ -1,77 +0,0 @@
-using System.Collections.Generic;
-
-namespace ET
-{
-	public class QueueDictionary<T, K>
-	{
-		private readonly List<T> list = new List<T>();
-		private readonly Dictionary<T, K> dictionary = new Dictionary<T, K>();
-
-		public void Enqueue(T t, K k)
-		{
-			this.list.Add(t);
-			this.dictionary.Add(t, k);
-		}
-
-		public void Dequeue()
-		{
-			if (this.list.Count == 0)
-			{
-				return;
-			}
-			T t = this.list[0];
-			this.list.RemoveAt(0);
-			this.dictionary.Remove(t);
-		}
-
-		public void Remove(T t)
-		{
-			this.list.Remove(t);
-			this.dictionary.Remove(t);
-		}
-
-		public bool ContainsKey(T t)
-		{
-			return this.dictionary.ContainsKey(t);
-		}
-
-		public int Count
-		{
-			get
-			{
-				return this.list.Count;
-			}
-		}
-
-		public T FirstKey
-		{
-			get
-			{
-				return this.list[0];
-			}
-		}
-		
-		public K FirstValue
-		{
-			get
-			{
-				T t = this.list[0];
-				return this[t];
-			}
-		}
-
-		public K this[T t]
-		{
-			get
-			{
-				return this.dictionary[t];
-			}
-		}
-
-		public void Clear()
-		{
-			this.list.Clear();
-			this.dictionary.Clear();
-		}
-	}
-}

+ 0 - 11
Unity/Assets/Scripts/Core/QueueDictionary.cs.meta

@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: 8df51b83ce3b4cc41ab215161b51a8ed
-MonoImporter:
-  externalObjects: {}
-  serializedVersion: 2
-  defaultReferences: []
-  executionOrder: 0
-  icon: {instanceID: 0}
-  userData: 
-  assetBundleName: 
-  assetBundleVariant: