Просмотр исходного кода

VProcess AddComponent方法增加泛型约束必须是SingletonEntity

tanghai 2 лет назад
Родитель
Сommit
3571804f44
25 измененных файлов с 81 добавлено и 150 удалено
  1. 45 1
      Unity/Assets/Scripts/Core/VProcess/VProcess.cs
  2. 2 2
      Unity/Assets/Scripts/Hotfix/Server/Demo/EntryEvent2_InitServer.cs
  3. 0 12
      Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Watcher/WatcherComponentSystem.cs
  4. 0 3
      Unity/Assets/Scripts/Hotfix/Server/Module/Actor/ActorMessageSenderComponentSystem.cs
  5. 0 1
      Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/ActorLocationSenderComponentSystem.cs
  6. 0 12
      Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/LocationProxyComponentSystem.cs
  7. 0 12
      Unity/Assets/Scripts/Hotfix/Server/Module/DB/DBManagerComponentSystem.cs
  8. 0 4
      Unity/Assets/Scripts/Hotfix/Server/Module/Message/NetInnerComponentSystem.cs
  9. 0 12
      Unity/Assets/Scripts/Hotfix/Server/Module/RobotCase/RobotCaseComponentSystem.cs
  10. 0 6
      Unity/Assets/Scripts/Hotfix/Share/Module/Recast/NavmeshComponentSystem.cs
  11. 0 12
      Unity/Assets/Scripts/Hotfix/Share/Module/Scene/ServerSceneManagerComponentSystem.cs
  12. 0 2
      Unity/Assets/Scripts/HotfixView/Client/Module/UI/UIEventComponentSystem.cs
  13. 2 4
      Unity/Assets/Scripts/Model/Server/Demo/Watcher/WatcherComponent.cs
  14. 4 6
      Unity/Assets/Scripts/Model/Server/Module/Actor/ActorMessageSenderComponent.cs
  15. 2 4
      Unity/Assets/Scripts/Model/Server/Module/ActorLocation/ActorLocationSenderOneType.cs
  16. 2 5
      Unity/Assets/Scripts/Model/Server/Module/ActorLocation/LocationProxyComponent.cs
  17. 2 6
      Unity/Assets/Scripts/Model/Server/Module/DB/DBManagerComponent.cs
  18. 2 6
      Unity/Assets/Scripts/Model/Server/Module/Message/NetInnerComponent.cs
  19. 2 5
      Unity/Assets/Scripts/Model/Server/Module/RobotCase/RobotCaseComponent.cs
  20. 2 2
      Unity/Assets/Scripts/Model/Share/Module/Console/ConsoleComponent.cs
  21. 2 6
      Unity/Assets/Scripts/Model/Share/Module/Recast/NavmeshComponent.cs
  22. 2 2
      Unity/Assets/Scripts/Model/Share/Module/Scene/ClientSceneManagerComponent.cs
  23. 2 5
      Unity/Assets/Scripts/Model/Share/Module/Scene/ServerSceneManagerComponent.cs
  24. 8 14
      Unity/Assets/Scripts/ModelView/Client/Module/Resource/ResourcesComponent.cs
  25. 2 6
      Unity/Assets/Scripts/ModelView/Client/Module/UI/UIEventComponent.cs

+ 45 - 1
Unity/Assets/Scripts/Core/VProcess/VProcess.cs

@@ -49,7 +49,7 @@ namespace ET
 
         public async ETTask WaitFrameFinish()
         {
-            
+            await ETTask.CompletedTask;
         }
 
         private void FrameFinishUpdate()
@@ -67,5 +67,49 @@ namespace ET
             
             this.IsRuning = false;
         }
+
+#region AddComponent
+
+        public new K AddComponent<K>(bool isFromPool = false) where K : SingletonEntity<K>, IAwake, new()
+        {
+            return base.AddComponent<K>(isFromPool);
+        }
+
+        public new K AddComponent<K, P1>(P1 p1, bool isFromPool = false) where K : SingletonEntity<K>, IAwake<P1>, new()
+        {
+            return base.AddComponent<K, P1>(p1, isFromPool);
+        }
+
+        public new K AddComponent<K, P1, P2>(P1 p1, P2 p2, bool isFromPool = false) where K : SingletonEntity<K>, IAwake<P1, P2>, new()
+        {
+            return base.AddComponent<K, P1, P2>(p1, p2, isFromPool);
+        }
+
+        public new K AddComponent<K, P1, P2, P3>(P1 p1, P2 p2, P3 p3, bool isFromPool = false) where K : SingletonEntity<K>, IAwake<P1, P2, P3>, new()
+        {
+            return base.AddComponent<K, P1, P2, P3>(p1, p2, p3, isFromPool);
+        }
+        
+        public new K AddComponentWithId<K>(long id, bool isFromPool = false) where K : SingletonEntity<K>, IAwake, new()
+        {
+            return base.AddComponentWithId<K>(id, isFromPool);
+        }
+
+        public new K AddComponentWithId<K, P1>(long id, P1 p1, bool isFromPool = false) where K : SingletonEntity<K>, IAwake<P1>, new()
+        {
+            return base.AddComponentWithId<K, P1>(id, p1, isFromPool);
+        }
+
+        public new K AddComponentWithId<K, P1, P2>(long id, P1 p1, P2 p2, bool isFromPool = false) where K : SingletonEntity<K>, IAwake<P1, P2>, new()
+        {
+            return base.AddComponentWithId<K, P1, P2>(id, p1, p2, isFromPool);
+        }
+
+        public new K AddComponentWithId<K, P1, P2, P3>(long id, P1 p1, P2 p2, P3 p3, bool isFromPool = false) where K : SingletonEntity<K>, IAwake<P1, P2, P3>, new()
+        {
+            return base.AddComponentWithId<K, P1, P2, P3>(id, p1, p2, p3, isFromPool);
+        }
+        
+#endregion
     }
 }

+ 2 - 2
Unity/Assets/Scripts/Hotfix/Server/Demo/EntryEvent2_InitServer.cs

@@ -20,14 +20,14 @@ namespace ET.Server
 
             scene.AddComponent<NavmeshComponent>();
 
-            StartProcessConfig processConfig = StartProcessConfigCategory.Instance.Get(Options.Instance.Process);
+            StartProcessConfig processConfig = StartProcessConfigCategory.Instance.Get(scene.Process);
             switch (Options.Instance.AppType)
             {
                 case AppType.Server:
                 {
                     scene.AddComponent<NetInnerComponent, IPEndPoint>(processConfig.InnerIPPort);
 
-                    var processScenes = StartSceneConfigCategory.Instance.GetByProcess(Options.Instance.Process);
+                    var processScenes = StartSceneConfigCategory.Instance.GetByProcess(scene.Process);
                     foreach (StartSceneConfig startConfig in processScenes)
                     {
                         await SceneFactory.CreateServerScene(ServerSceneManagerComponent.Instance, startConfig.Id, startConfig.ActorId.InstanceId, startConfig.Zone, startConfig.Name,

+ 0 - 12
Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Watcher/WatcherComponentSystem.cs

@@ -6,18 +6,6 @@ namespace ET.Server
     [FriendOf(typeof(WatcherComponent))]
     public static partial class WatcherComponentSystem
     {
-        [EntitySystem]
-        private static void Awake(this WatcherComponent self)
-        {
-            WatcherComponent.Instance = self;
-        }
-    
-        [EntitySystem]
-        private static void Destroy(this WatcherComponent self)
-        {
-            WatcherComponent.Instance = null;
-        }
-        
         public static void Start(this WatcherComponent self, int createScenes = 0)
         {
             string[] localIP = NetworkHelper.GetAddressIPs();

+ 0 - 3
Unity/Assets/Scripts/Hotfix/Server/Module/Actor/ActorMessageSenderComponentSystem.cs

@@ -25,15 +25,12 @@ namespace ET.Server
         [EntitySystem]
         private static void Awake(this ActorMessageSenderComponent self)
         {
-            ActorMessageSenderComponent.Instance = self;
-
             self.TimeoutCheckTimer = TimerComponent.Instance.NewRepeatedTimer(1000, TimerInvokeType.ActorMessageSenderChecker, self);
         }
         
         [EntitySystem]
         private static void Destroy(this ActorMessageSenderComponent self)
         {
-            ActorMessageSenderComponent.Instance = null;
             TimerComponent.Instance?.Remove(ref self.TimeoutCheckTimer);
             self.TimeoutCheckTimer = 0;
             self.TimeoutActorMessageSenders.Clear();

+ 0 - 1
Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/ActorLocationSenderComponentSystem.cs

@@ -284,7 +284,6 @@ namespace ET.Server
         [EntitySystem]
         private static void Awake(this ActorLocationSenderComponent self)
         {
-            ActorLocationSenderComponent.Instance = self;
             for (int i = 0; i < self.ActorLocationSenderComponents.Length; ++i)
             {
                 self.ActorLocationSenderComponents[i] = self.AddChild<ActorLocationSenderOneType, int>(i);

+ 0 - 12
Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/LocationProxyComponentSystem.cs

@@ -4,18 +4,6 @@ namespace ET.Server
 {
     public static partial class LocationProxyComponentSystem
     {
-        [EntitySystem]
-        private static void Awake(this LocationProxyComponent self)
-        {
-            LocationProxyComponent.Instance = self;
-        }
-    
-        [EntitySystem]
-        private static void Destroy(this LocationProxyComponent self)
-        {
-            LocationProxyComponent.Instance = null;
-        }
-        
         private static ActorId GetLocationSceneId(long key)
         {
             return StartSceneConfigCategory.Instance.LocationConfig.ActorId;

+ 0 - 12
Unity/Assets/Scripts/Hotfix/Server/Module/DB/DBManagerComponentSystem.cs

@@ -5,18 +5,6 @@ namespace ET.Server
     [FriendOf(typeof(DBManagerComponent))]
     public static partial class DBManagerComponentSystem
     {
-        [EntitySystem]
-        private static void Awake(this DBManagerComponent self)
-        {
-            DBManagerComponent.Instance = self;
-        }
-
-        [EntitySystem]
-        private static void Destroy(this DBManagerComponent self)
-        {
-            DBManagerComponent.Instance = null;
-        }
-        
         public static DBComponent GetZoneDB(this DBManagerComponent self, int zone)
         {
             DBComponent dbComponent = self.DBComponents[zone];

+ 0 - 4
Unity/Assets/Scripts/Hotfix/Server/Module/Message/NetInnerComponentSystem.cs

@@ -9,8 +9,6 @@ namespace ET.Server
         [EntitySystem]
         private static void Awake(this NetInnerComponent self)
         {
-            NetInnerComponent.Instance = self;
-            
             switch (self.InnerProtocol)
             {
                 case NetworkProtocol.TCP:
@@ -32,8 +30,6 @@ namespace ET.Server
         [EntitySystem]
         private static void Awake(this NetInnerComponent self, IPEndPoint address)
         {
-            NetInnerComponent.Instance = self;
-                
             switch (self.InnerProtocol)
             {
                 case NetworkProtocol.TCP:

+ 0 - 12
Unity/Assets/Scripts/Hotfix/Server/Module/RobotCase/RobotCaseComponentSystem.cs

@@ -6,18 +6,6 @@ namespace ET.Server
     [FriendOf(typeof(RobotCaseComponent))]
     public static partial class RobotCaseComponentSystem
     {
-        [EntitySystem]
-        private static void Awake(this RobotCaseComponent self)
-        {
-            RobotCaseComponent.Instance = self;
-        }
-
-        [EntitySystem]
-        private static void Destroy(this RobotCaseComponent self)
-        {
-            RobotCaseComponent.Instance = null;
-        }
-        
         public static int GetN(this RobotCaseComponent self)
         {
             return ++self.N;

+ 0 - 6
Unity/Assets/Scripts/Hotfix/Share/Module/Recast/NavmeshComponentSystem.cs

@@ -5,12 +5,6 @@ namespace ET
     [FriendOf(typeof(NavmeshComponent))]
     public static partial class NavmeshComponentSystem
     {
-        [EntitySystem]
-        private static void Awake(this NavmeshComponent self)
-        {
-            NavmeshComponent.Instance = self;
-        }
-        
         public static long Get(this NavmeshComponent self, string name)
         {
             long ptr;

+ 0 - 12
Unity/Assets/Scripts/Hotfix/Share/Module/Scene/ServerSceneManagerComponentSystem.cs

@@ -3,18 +3,6 @@
     [FriendOf(typeof(ServerSceneManagerComponent))]
     public static partial class ServerSceneManagerComponentSystem
     {
-        [EntitySystem]
-        private static void Awake(this ServerSceneManagerComponent self)
-        {
-            ServerSceneManagerComponent.Instance = self;
-        }
-
-        [EntitySystem]
-        private static void Destroy(this ServerSceneManagerComponent self)
-        {
-            ServerSceneManagerComponent.Instance = null;
-        }
-        
         public static Scene Get(this ServerSceneManagerComponent self, int id)
         {
             Scene scene = self.GetChild<Scene>(id);

+ 0 - 2
Unity/Assets/Scripts/HotfixView/Client/Module/UI/UIEventComponentSystem.cs

@@ -13,8 +13,6 @@ namespace ET.Client
         [EntitySystem]
         private static void Awake(this UIEventComponent self)
         {
-            UIEventComponent.Instance = self;
-
             GameObject uiRoot = GameObject.Find("/Global/UI");
             ReferenceCollector referenceCollector = uiRoot.GetComponent<ReferenceCollector>();
 

+ 2 - 4
Unity/Assets/Scripts/Model/Server/Demo/Watcher/WatcherComponent.cs

@@ -3,11 +3,9 @@ using System.Diagnostics;
 
 namespace ET.Server
 {
-    [ComponentOf(typeof(Scene))]
-    public class WatcherComponent: Entity, IAwake, IDestroy
+    [ComponentOf(typeof(VProcess))]
+    public class WatcherComponent: SingletonEntity<WatcherComponent>, IAwake, IDestroy
     {
-        public static WatcherComponent Instance { get; set; }
-
         public readonly Dictionary<int, System.Diagnostics.Process> Processes = new Dictionary<int, System.Diagnostics.Process>();
     }
 }

+ 4 - 6
Unity/Assets/Scripts/Model/Server/Module/Actor/ActorMessageSenderComponent.cs

@@ -2,19 +2,17 @@
 
 namespace ET.Server
 {
-    [ComponentOf(typeof(Scene))]
-    public class ActorMessageSenderComponent: Entity, IAwake, IDestroy
+    [ComponentOf(typeof(VProcess))]
+    public class ActorMessageSenderComponent: SingletonEntity<ActorMessageSenderComponent>, IAwake, IDestroy
     {
         public const long TIMEOUT_TIME = 40 * 1000;
 
-        public static ActorMessageSenderComponent Instance { get; set; }
-
         public int RpcId;
 
-        public readonly SortedDictionary<int, ActorMessageSender> requestCallback = new SortedDictionary<int, ActorMessageSender>();
+        public readonly SortedDictionary<int, ActorMessageSender> requestCallback = new();
 
         public long TimeoutCheckTimer;
 
-        public List<int> TimeoutActorMessageSenders = new List<int>();
+        public List<int> TimeoutActorMessageSenders = new();
     }
 }

+ 2 - 4
Unity/Assets/Scripts/Model/Server/Module/ActorLocation/ActorLocationSenderOneType.cs

@@ -14,13 +14,11 @@ namespace ET.Server
     }
     
     
-    [ComponentOf(typeof(Scene))]
-    public class ActorLocationSenderComponent: Entity, IAwake, IDestroy
+    [ComponentOf(typeof(VProcess))]
+    public class ActorLocationSenderComponent: SingletonEntity<ActorLocationSenderComponent>, IAwake, IDestroy
     {
         public const long TIMEOUT_TIME = 60 * 1000;
 
-        public static ActorLocationSenderComponent Instance { get; set; }
-
         public long CheckTimer;
 
         public ActorLocationSenderOneType[] ActorLocationSenderComponents = new ActorLocationSenderOneType[LocationType.Max];

+ 2 - 5
Unity/Assets/Scripts/Model/Server/Module/ActorLocation/LocationProxyComponent.cs

@@ -2,11 +2,8 @@
 
 namespace ET.Server
 {
-    [ComponentOf(typeof(Scene))]
-    public class LocationProxyComponent: Entity, IAwake, IDestroy
+    [ComponentOf(typeof(VProcess))]
+    public class LocationProxyComponent: SingletonEntity<LocationProxyComponent>, IAwake
     {
-        [ThreadStatic]
-        [StaticField]
-        public static LocationProxyComponent Instance;
     }
 }

+ 2 - 6
Unity/Assets/Scripts/Model/Server/Module/DB/DBManagerComponent.cs

@@ -2,13 +2,9 @@
 
 namespace ET.Server
 {
-    
-    public class DBManagerComponent: Entity, IAwake, IDestroy
+    [ComponentOf(typeof(VProcess))]
+    public class DBManagerComponent: SingletonEntity<DBManagerComponent>, IAwake
     {
-        [ThreadStatic]
-        [StaticField]
-        public static DBManagerComponent Instance;
-        
         public DBComponent[] DBComponents = new DBComponent[IdGenerater.MaxZone];
     }
 }

+ 2 - 6
Unity/Assets/Scripts/Model/Server/Module/Message/NetInnerComponent.cs

@@ -9,15 +9,11 @@ namespace ET.Server
         public object Message;
     }
     
-    [ComponentOf(typeof(Scene))]
-    public class NetInnerComponent: Entity, IAwake<IPEndPoint>, IAwake, IDestroy
+    [ComponentOf(typeof(VProcess))]
+    public class NetInnerComponent: SingletonEntity<NetInnerComponent>, IAwake<IPEndPoint>, IAwake, IDestroy
     {
         public int ServiceId;
         
         public NetworkProtocol InnerProtocol = NetworkProtocol.KCP;
-
-        [ThreadStatic]
-        [StaticField]
-        public static NetInnerComponent Instance;
     }
 }

+ 2 - 5
Unity/Assets/Scripts/Model/Server/Module/RobotCase/RobotCaseComponent.cs

@@ -4,12 +4,9 @@ using System.Collections.Generic;
 namespace ET.Server
 {
     
-    [ComponentOf(typeof(Scene))]
-    public class RobotCaseComponent: Entity, IAwake, IDestroy
+    [ComponentOf(typeof(VProcess))]
+    public class RobotCaseComponent: SingletonEntity<RobotCaseComponent>, IAwake, IDestroy
     {
-        [ThreadStatic]
-        [StaticField]
-        public static RobotCaseComponent Instance;
         public Dictionary<int, RobotCase> RobotCases = new Dictionary<int, RobotCase>();
         public int N = 10000;
     }

+ 2 - 2
Unity/Assets/Scripts/Model/Share/Module/Console/ConsoleComponent.cs

@@ -14,8 +14,8 @@ namespace ET
         public const string Robot = "Robot";
     }
 
-    [ComponentOf(typeof(Scene))]
-    public class ConsoleComponent: Entity, IAwake, ILoad
+    [ComponentOf(typeof(VProcess))]
+    public class ConsoleComponent: SingletonEntity<ConsoleComponent>, IAwake, ILoad
     {
         public CancellationTokenSource CancellationTokenSource;
         public Dictionary<string, IConsoleHandler> Handlers = new Dictionary<string, IConsoleHandler>();

+ 2 - 6
Unity/Assets/Scripts/Model/Share/Module/Recast/NavmeshComponent.cs

@@ -3,13 +3,9 @@ using System.Collections.Generic;
 
 namespace ET
 {
-    [ComponentOf(typeof(Scene))]
-    public class NavmeshComponent: Entity, IAwake
+    [ComponentOf(typeof(VProcess))]
+    public class NavmeshComponent: SingletonEntity<NavmeshComponent>, IAwake
     {
-        [ThreadStatic]
-        [StaticField]
-        public static NavmeshComponent Instance;
-        
         public struct RecastFileLoader
         {
             public string Name { get; set; }

+ 2 - 2
Unity/Assets/Scripts/Model/Share/Module/Scene/ClientSceneManagerComponent.cs

@@ -2,8 +2,8 @@ using System;
 
 namespace ET
 {
-    [ComponentOf(typeof(Scene))]
-    public class ClientSceneManagerComponent: Entity, IAwake, IDestroy
+    [ComponentOf(typeof(VProcess))]
+    public class ClientSceneManagerComponent: SingletonEntity<ClientSceneManagerComponent>, IAwake
     {
     }
 }

+ 2 - 5
Unity/Assets/Scripts/Model/Share/Module/Scene/ServerSceneManagerComponent.cs

@@ -2,11 +2,8 @@ using System;
 
 namespace ET
 {
-    [ComponentOf(typeof(Scene))]
-    public class ServerSceneManagerComponent: Entity, IAwake, IDestroy
+    [ComponentOf(typeof(VProcess))]
+    public class ServerSceneManagerComponent: SingletonEntity<ServerSceneManagerComponent>, IAwake, IDestroy
     {
-        [ThreadStatic]
-        [StaticField]
-        public static ServerSceneManagerComponent Instance;
     }
 }

+ 8 - 14
Unity/Assets/Scripts/ModelView/Client/Module/Resource/ResourcesComponent.cs

@@ -109,7 +109,6 @@ namespace ET.Client
         [EntitySystem]
         private static void Awake(this ResourcesComponent self)
         {
-            ResourcesComponent.Instance = self;
             if (Define.IsAsync)
             {
                 self.LoadOneBundle("StreamingAssets");
@@ -121,8 +120,6 @@ namespace ET.Client
         [EntitySystem]
         private static void Destroy(this ResourcesComponent self)
         {
-            ResourcesComponent.Instance = null;
-
             foreach (var abInfo in self.bundles)
             {
                 abInfo.Value.Destroy();
@@ -553,25 +550,22 @@ namespace ET.Client
         }
     }
 
-    [ComponentOf]
-    public class ResourcesComponent: Entity, IAwake, IDestroy
+    [ComponentOf(typeof(VProcess))]
+    public class ResourcesComponent: SingletonEntity<ResourcesComponent>, IAwake, IDestroy
     {
-        public static ResourcesComponent Instance { get; set; }
-
         public AssetBundleManifest AssetBundleManifestObject { get; set; }
 
-        public Dictionary<int, string> IntToStringDict = new Dictionary<int, string>();
+        public Dictionary<int, string> IntToStringDict = new();
 
-        public Dictionary<string, string> StringToABDict = new Dictionary<string, string>();
+        public Dictionary<string, string> StringToABDict = new();
 
-        public Dictionary<string, string> BundleNameToLowerDict = new Dictionary<string, string>() { { "StreamingAssets", "StreamingAssets" } };
+        public Dictionary<string, string> BundleNameToLowerDict = new() { { "StreamingAssets", "StreamingAssets" } };
 
-        public readonly Dictionary<string, Dictionary<string, UnityEngine.Object>> resourceCache =
-                new Dictionary<string, Dictionary<string, UnityEngine.Object>>();
+        public readonly Dictionary<string, Dictionary<string, UnityEngine.Object>> resourceCache = new();
 
-        public readonly Dictionary<string, ABInfo> bundles = new Dictionary<string, ABInfo>();
+        public readonly Dictionary<string, ABInfo> bundles = new();
 
         // 缓存包依赖,不用每次计算
-        public readonly Dictionary<string, string[]> DependenciesCache = new Dictionary<string, string[]>();
+        public readonly Dictionary<string, string[]> DependenciesCache = new();
     }
 }

+ 2 - 6
Unity/Assets/Scripts/ModelView/Client/Module/UI/UIEventComponent.cs

@@ -7,13 +7,9 @@ namespace ET.Client
 	/// <summary>
 	/// 管理所有UI GameObject
 	/// </summary>
-	[ComponentOf(typeof(Scene))]
-	public class UIEventComponent: Entity, IAwake
+	[ComponentOf(typeof(VProcess))]
+	public class UIEventComponent: SingletonEntity<UIEventComponent>, IAwake
 	{
-		[ThreadStatic]
-		[StaticField]
-		public static UIEventComponent Instance;
-		
 		public Dictionary<string, AUIEvent> UIEvents = new Dictionary<string, AUIEvent>();
 		
 		public Dictionary<int, Transform> UILayers = new Dictionary<int, Transform>();