Răsfoiți Sursa

修复ReloadConfig的问题

tanghai 2 ani în urmă
părinte
comite
3e98203c94

+ 1 - 1
DotNet/Loader/ConfigLoader.cs

@@ -41,7 +41,7 @@ namespace ET
     {
         public override byte[] Handle(ConfigComponent.GetOneConfigBytes args)
         {
-            byte[] configBytes = File.ReadAllBytes($"../Config/{args.ConfigName}.bytes");
+            byte[] configBytes = File.ReadAllBytes($"../Config/Excel/s/{args.ConfigName}.bytes");
             return configBytes;
         }
     }

+ 1 - 1
Unity/Assets/Resources/GlobalConfig.asset

@@ -12,6 +12,6 @@ MonoBehaviour:
   m_Script: {fileID: 11500000, guid: 36527db572638af47b03c805671cba75, type: 3}
   m_Name: GlobalConfig
   m_EditorClassIdentifier: 
-  CodeMode: 1
+  CodeMode: 3
   BuildType: 1
   AppType: 7

+ 0 - 2
Unity/Assets/Scripts/Core/Fiber/Fiber.cs

@@ -144,8 +144,6 @@ namespace ET
             }
             this.IsDisposed = true;
             
-            Log.Debug($"111111111111111111111111111111111111: {this.Root.SceneType}");
-            
             FiberManager.Instance.RemoveReal(this.Id);
             
             this.Root.Dispose();

+ 1 - 1
Unity/Assets/Scripts/Core/World/Module/Config/ConfigComponent.cs

@@ -28,7 +28,7 @@ namespace ET
 		public void Reload(Type configType)
 		{
 			byte[] oneConfigBytes =
-					EventSystem.Instance.Invoke<GetOneConfigBytes, byte[]>(new GetOneConfigBytes() { ConfigName = configType.FullName });
+					EventSystem.Instance.Invoke<GetOneConfigBytes, byte[]>(new GetOneConfigBytes() { ConfigName = configType.Name });
 
 			object category = MongoHelper.Deserialize(configType, oneConfigBytes, 0, oneConfigBytes.Length);
 			ISingleton singleton = category as ISingleton;

+ 57 - 3
Unity/Assets/Scripts/Core/World/Module/Config/ConfigSingleton.cs

@@ -3,13 +3,67 @@ using System.ComponentModel;
 
 namespace ET
 {
-    public abstract class ConfigSingleton<T>: Singleton<T>, ISupportInitialize where T: ConfigSingleton<T>, new()
+    public abstract class ConfigSingleton<T>: ISingleton, ISupportInitialize where T: ConfigSingleton<T>, new()
     {
+        private bool isDisposed;
+        
+        [StaticField]
+        private static T instance;
+        
+        [StaticField]
+        private static object lockObj = new();
+
+        public static T Instance
+        {
+            get
+            {
+                lock (lockObj)
+                {
+                    return instance;
+                }
+            }
+            private set
+            {
+                lock (lockObj)
+                {
+                    instance = value;
+                }
+            }
+        }
+
+        public virtual void Register()
+        {
+            Instance = (T)this;
+        }
+
+        public bool IsDisposed()
+        {
+            return this.isDisposed;
+        }
+
+        protected virtual void Destroy()
+        {
+            
+        }
+
+        void IDisposable.Dispose()
+        {
+            if (this.isDisposed)
+            {
+                return;
+            }
+            
+            this.isDisposed = true;
+
+            Instance = null;
+            
+            this.Destroy();
+        }
+
         public virtual void BeginInit()
         {
         }
-        
-        
+
         public virtual void EndInit()
         {
         }

+ 38 - 1
Unity/Assets/Scripts/Loader/ConfigLoader.cs

@@ -72,7 +72,44 @@ namespace ET
     {
         public override byte[] Handle(ConfigComponent.GetOneConfigBytes args)
         {
-            throw new NotImplementedException("client cant use LoadOneConfig");
+            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",
+            };
+
+            string configName = args.ConfigName;
+                
+            string configFilePath;
+            if (startConfigs.Contains(configName))
+            {
+                configFilePath = $"../Config/Excel/{ct}/{Options.Instance.StartConfig}/{configName}.bytes";    
+            }
+            else
+            {
+                configFilePath = $"../Config/Excel/{ct}/{configName}.bytes";
+            }
+                
+            return File.ReadAllBytes(configFilePath);
         }
     }
 }

+ 1 - 1
Unity/ProjectSettings/ProjectSettings.asset

@@ -839,7 +839,7 @@ PlayerSettings:
   webGLDecompressionFallback: 0
   webGLPowerPreference: 2
   scriptingDefineSymbols:
-    Android: UNITY;SINGLE_THREAD;ENABLE_DLL
+    Android: UNITY;SINGLE_THREAD;ENABLE_DLL;ENABLE_VIEW
     Server: UNITY
     Standalone: UNITY;SINGLE_THREAD;ENABLE_VIEW;ENABLE_CODES
     WebGL: UNITY;ENABLE_CODES