Przeglądaj źródła

合并ET8.1的修改

tanghai 1 rok temu
rodzic
commit
e5a0d7b697

+ 17 - 0
Share/Analyzer/Analyzer/EntityMemberDeclarationAnalyzer.cs

@@ -115,6 +115,22 @@ namespace ET.Analyzer
                     continue;
                 }
 
+                // 字段类型是否是实体类型数组
+                if (fieldSymbol.Type is IArrayTypeSymbol arrayTypeSymbol)
+                {
+                    if (arrayTypeSymbol.ElementType.IsETEntity())
+                    {
+                        var syntaxReference = fieldSymbol.DeclaringSyntaxReferences.FirstOrDefault();
+                        if (syntaxReference==null)
+                        {
+                            continue;
+                        }
+                        Diagnostic diagnostic = Diagnostic.Create(EntityFieldDeclarationInEntityAnalyzerRule.Rule, syntaxReference.GetSyntax().GetLocation(),namedTypeSymbol.Name,fieldSymbol.Name);
+                        context.ReportDiagnostic(diagnostic);
+                    }
+                    continue;
+                }
+
                 if (fieldSymbol.Type is not INamedTypeSymbol namedTypeSymbol2)
                 {
                     continue;
@@ -144,6 +160,7 @@ namespace ET.Analyzer
                     Diagnostic diagnostic = Diagnostic.Create(EntityFieldDeclarationInEntityAnalyzerRule.Rule, syntaxReference.GetSyntax().GetLocation(),namedTypeSymbol.Name,fieldSymbol.Name);
                     context.ReportDiagnostic(diagnostic);
                 }
+                
             }
         }
 

+ 1 - 1
Share/SourceGenerator/ET.SourceGenerator.csproj

@@ -1,7 +1,7 @@
 <Project Sdk="Microsoft.NET.Sdk">
 
     <PropertyGroup>
-        <TargetFramework>netstandard2.0</TargetFramework>
+        <TargetFramework>netstandard2.1</TargetFramework>
         <IncludeBuildOutput>false</IncludeBuildOutput>
         <Nullable>enable</Nullable>
         <LangVersion>12</LangVersion>

+ 7 - 0
Unity/Assets/Bundles/Config/UnitConfigCategory.bytes.meta

@@ -0,0 +1,7 @@
+fileFormatVersion: 2
+guid: 4c54687c04c629d488376e5ef067ef18
+TextScriptImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 16 - 11
Unity/Packages/com.et.actorlocation/Scripts/Hotfix/Server/LocationOneTypeSystem.cs

@@ -3,6 +3,7 @@
 namespace ET.Server
 {
     [EntitySystemOf(typeof(LockInfo))]
+    [FriendOf(typeof(LockInfo))]
     public static partial class LockInfoSystem
     {
         [EntitySystem]
@@ -22,18 +23,18 @@ namespace ET.Server
     
 
     [EntitySystemOf(typeof(LocationOneType))]
+    [FriendOf(typeof(LocationOneType))]
     [FriendOf(typeof(LockInfo))]
     public static partial class LocationOneTypeSystem
     {
         [EntitySystem]
-        private static void Awake(this LocationOneType self, int locationType)
+        private static void Awake(this LocationOneType self)
         {
-            self.LocationType = locationType;
         }
         
         public static async ETTask Add(this LocationOneType self, long key, ActorId instanceId)
         {
-            int coroutineLockType = (self.LocationType << 16) | CoroutineLockType.Location;
+            int coroutineLockType = ((int)self.Id << 16) | CoroutineLockType.Location;
             using (await self.Root().GetComponent<CoroutineLockComponent>().Wait(coroutineLockType, key))
             {
                 self.locations[key] = instanceId;
@@ -43,7 +44,7 @@ namespace ET.Server
 
         public static async ETTask Remove(this LocationOneType self, long key)
         {
-            int coroutineLockType = (self.LocationType << 16) | CoroutineLockType.Location;
+            int coroutineLockType = ((int)self.Id << 16) | CoroutineLockType.Location;
             using (await self.Root().GetComponent<CoroutineLockComponent>().Wait(coroutineLockType, key))
             {
                 self.locations.Remove(key);
@@ -53,7 +54,7 @@ namespace ET.Server
 
         public static async ETTask Lock(this LocationOneType self, long key, ActorId actorId, int time = 0)
         {
-            int coroutineLockType = (self.LocationType << 16) | CoroutineLockType.Location;
+            int coroutineLockType = ((int)self.Id << 16) | CoroutineLockType.Location;
             CoroutineLock coroutineLock = await self.Root().GetComponent<CoroutineLockComponent>().Wait(coroutineLockType, key);
 
             LockInfo lockInfo = self.AddChild<LockInfo, ActorId, CoroutineLock>(actorId, coroutineLock);
@@ -105,7 +106,7 @@ namespace ET.Server
 
         public static async ETTask<ActorId> Get(this LocationOneType self, long key)
         {
-            int coroutineLockType = (self.LocationType << 16) | CoroutineLockType.Location;
+            int coroutineLockType = ((int)self.Id << 16) | CoroutineLockType.Location;
             using (await self.Root().GetComponent<CoroutineLockComponent>().Wait(coroutineLockType, key))
             {
                 self.locations.TryGetValue(key, out ActorId actorId);
@@ -116,20 +117,24 @@ namespace ET.Server
     }
 
     [EntitySystemOf(typeof(LocationManagerComoponent))]
+    [FriendOf(typeof(LocationManagerComoponent))]
     public static partial class LocationComoponentSystem
     {
         [EntitySystem]
         private static void Awake(this LocationManagerComoponent self)
         {
-            for (int i = 0; i < self.LocationOneTypes.Length; ++i)
-            {
-                self.LocationOneTypes[i] = self.AddChild<LocationOneType, int>(i);
-            }
         }
         
         public static LocationOneType Get(this LocationManagerComoponent self, int locationType)
         {
-            return self.LocationOneTypes[locationType];
+            LocationOneType locationOneType = self.GetChild<LocationOneType>(locationType);
+            if (locationOneType != null)
+            {
+                return locationOneType;
+            }
+            locationOneType = self.AddChildWithId<LocationOneType>(locationType);
+            return locationOneType;
         }
+
     }
 }

+ 30 - 25
Unity/Packages/com.et.actorlocation/Scripts/Hotfix/Server/MessageLocationSenderComponentSystem.cs

@@ -5,6 +5,7 @@ using MongoDB.Bson;
 namespace ET.Server
 {
     [EntitySystemOf(typeof(MessageLocationSenderOneType))]
+    [FriendOf(typeof(MessageLocationSenderOneType))]
     [FriendOf(typeof(MessageLocationSender))]
     public static partial class MessageLocationSenderComponentSystem
     {
@@ -25,9 +26,8 @@ namespace ET.Server
         }
     
         [EntitySystem]
-        private static void Awake(this MessageLocationSenderOneType self, int locationType)
+        private static void Awake(this MessageLocationSenderOneType self)
         {
-            self.LocationType = locationType;
             // 每10s扫描一次过期的actorproxy进行回收,过期时间是2分钟
             // 可能由于bug或者进程挂掉,导致ActorLocationSender发送的消息没有确认,结果无法自动删除,每一分钟清理一次这种ActorLocationSender
             self.CheckTimer = self.Root().GetComponent<TimerComponent>().NewRepeatedTimer(10 * 1000, TimerInvokeType.MessageLocationSenderChecker, self);
@@ -41,22 +41,23 @@ namespace ET.Server
 
         private static void Check(this MessageLocationSenderOneType self)
         {
-            using ListComponent<long> list = ListComponent<long>.Create();
-            
-            long timeNow = TimeInfo.Instance.ServerNow();
-            foreach ((long key, Entity value) in self.Children)
+            using (ListComponent<long> list = ListComponent<long>.Create())
             {
-                MessageLocationSender messageLocationMessageSender = (MessageLocationSender) value;
-
-                if (timeNow > messageLocationMessageSender.LastSendOrRecvTime + MessageLocationSenderOneType.TIMEOUT_TIME)
+                long timeNow = TimeInfo.Instance.ServerNow();
+                foreach ((long key, Entity value) in self.Children)
                 {
-                    list.Add(key);
+                    MessageLocationSender messageLocationMessageSender = (MessageLocationSender) value;
+
+                    if (timeNow > messageLocationMessageSender.LastSendOrRecvTime + MessageLocationSenderOneType.TIMEOUT_TIME)
+                    {
+                        list.Add(key);
+                    }
                 }
-            }
 
-            foreach (long id in list)
-            {
-                self.Remove(id);
+                foreach (long id in list)
+                {
+                    self.Remove(id);
+                }
             }
         }
 
@@ -110,7 +111,7 @@ namespace ET.Server
             
             long instanceId = messageLocationSender.InstanceId;
             
-            int coroutineLockType = (self.LocationType << 16) | CoroutineLockType.MessageLocationSender;
+            int coroutineLockType = ((int)self.Id << 16) | CoroutineLockType.MessageLocationSender;
             using (await root.Root().GetComponent<CoroutineLockComponent>().Wait(coroutineLockType, entityId))
             {
                 if (messageLocationSender.InstanceId != instanceId)
@@ -120,7 +121,7 @@ namespace ET.Server
                 
                 if (messageLocationSender.ActorId == default)
                 {
-                    messageLocationSender.ActorId = await root.GetComponent<LocationProxyComponent>().Get(self.LocationType, messageLocationSender.Id);
+                    messageLocationSender.ActorId = await root.GetComponent<LocationProxyComponent>().Get((int)self.Id, messageLocationSender.Id);
                     if (messageLocationSender.InstanceId != instanceId)
                     {
                         throw new RpcException(ErrorCore.ERR_ActorLocationSenderTimeout2, $"{message}");
@@ -148,7 +149,7 @@ namespace ET.Server
             
             long instanceId = messageLocationSender.InstanceId;
             
-            int coroutineLockType = (self.LocationType << 16) | CoroutineLockType.MessageLocationSender;
+            int coroutineLockType = ((int)self.Id << 16) | CoroutineLockType.MessageLocationSender;
             using (await root.GetComponent<CoroutineLockComponent>().Wait(coroutineLockType, entityId))
             {
                 if (messageLocationSender.InstanceId != instanceId)
@@ -158,7 +159,7 @@ namespace ET.Server
 
                 if (messageLocationSender.ActorId == default)
                 {
-                    messageLocationSender.ActorId = await root.GetComponent<LocationProxyComponent>().Get(self.LocationType, messageLocationSender.Id);
+                    messageLocationSender.ActorId = await root.GetComponent<LocationProxyComponent>().Get((int)self.Id, messageLocationSender.Id);
                     if (messageLocationSender.InstanceId != instanceId)
                     {
                         throw new RpcException(ErrorCore.ERR_ActorLocationSenderTimeout2, $"{request}");
@@ -182,7 +183,7 @@ namespace ET.Server
             Scene root = self.Root();
             Type iRequestType = iRequest.GetType();
             long actorLocationSenderInstanceId = messageLocationSender.InstanceId;
-            int coroutineLockType = (self.LocationType << 16) | CoroutineLockType.MessageLocationSender;
+            int coroutineLockType = ((int)self.Id << 16) | CoroutineLockType.MessageLocationSender;
             using (await root.GetComponent<CoroutineLockComponent>().Wait(coroutineLockType, entityId))
             {
                 if (messageLocationSender.InstanceId != actorLocationSenderInstanceId)
@@ -220,7 +221,7 @@ namespace ET.Server
             {
                 if (messageLocationSender.ActorId == default)
                 {
-                    messageLocationSender.ActorId = await root.GetComponent<LocationProxyComponent>().Get(self.LocationType, messageLocationSender.Id);
+                    messageLocationSender.ActorId = await root.GetComponent<LocationProxyComponent>().Get((int)self.Id, messageLocationSender.Id);
                     if (messageLocationSender.InstanceId != instanceId)
                     {
                         throw new RpcException(ErrorCore.ERR_ActorLocationSenderTimeout2, $"{iRequest}");
@@ -280,20 +281,24 @@ namespace ET.Server
     }
 
     [EntitySystemOf(typeof(MessageLocationSenderComponent))]
+    [FriendOf(typeof (MessageLocationSenderComponent))]
     public static partial class MessageLocationSenderManagerComponentSystem
     {
         [EntitySystem]
         private static void Awake(this MessageLocationSenderComponent self)
         {
-            for (int i = 0; i < self.messageLocationSenders.Length; ++i)
-            {
-                self.messageLocationSenders[i] = self.AddChild<MessageLocationSenderOneType, int>(i);
-            }
         }
         
         public static MessageLocationSenderOneType Get(this MessageLocationSenderComponent self, int locationType)
         {
-            return self.messageLocationSenders[locationType];
+            MessageLocationSenderOneType messageLocationSenderOneType = self.GetChild<MessageLocationSenderOneType>(locationType);
+            if (messageLocationSenderOneType != null)
+            {
+                return messageLocationSenderOneType;
+            }
+
+            messageLocationSenderOneType = self.AddChildWithId<MessageLocationSenderOneType>(locationType);
+            return messageLocationSenderOneType;
         }
     }
 }

+ 2 - 5
Unity/Packages/com.et.actorlocation/Scripts/Model/Server/LocationComponent.cs

@@ -10,7 +10,7 @@ namespace ET.Server
         public const int Friend = 2;
         public const int Chat = 3;
         public const int GateSession = 4;
-        public const int Max = 100;
+        public const int Max = 10;
     }
     
     [ChildOf(typeof(LocationOneType))]
@@ -26,10 +26,8 @@ namespace ET.Server
     }
 
     [ChildOf(typeof(LocationManagerComoponent))]
-    public class LocationOneType: Entity, IAwake<int>
+    public class LocationOneType: Entity, IAwake
     {
-        public int LocationType;
-        
         public readonly Dictionary<long, ActorId> locations = new();
 
         public readonly Dictionary<long, EntityRef<LockInfo>> lockInfos = new();
@@ -38,6 +36,5 @@ namespace ET.Server
     [ComponentOf(typeof(Scene))]
     public class LocationManagerComoponent: Entity, IAwake
     {
-        public LocationOneType[] LocationOneTypes = new LocationOneType[LocationType.Max];
     }
 }

+ 3 - 9
Unity/Packages/com.et.actorlocation/Scripts/Model/Server/MessageLocationSenderOneType.cs

@@ -1,16 +1,12 @@
-using System.Collections.Generic;
-
-namespace ET.Server
+namespace ET.Server
 {
     
     [ChildOf(typeof(MessageLocationSenderComponent))]
-    public class MessageLocationSenderOneType: Entity, IAwake<int>, IDestroy
+    public class MessageLocationSenderOneType: Entity, IAwake, IDestroy
     {
         public const long TIMEOUT_TIME = 60 * 1000;
 
         public long CheckTimer;
-
-        public int LocationType;
     }
     
     
@@ -20,7 +16,5 @@ namespace ET.Server
         public const long TIMEOUT_TIME = 60 * 1000;
 
         public long CheckTimer;
-
-        public MessageLocationSenderOneType[] messageLocationSenders = new MessageLocationSenderOneType[LocationType.Max];
     }
-}
+}

+ 2 - 1
Unity/Packages/com.et.db/Scripts/Hotfix/Server/DBComponentSystem.cs

@@ -6,10 +6,11 @@ using MongoDB.Driver;
 namespace ET.Server
 {
 	[EntitySystemOf(typeof(DBComponent))]
+	[FriendOf(typeof(DBComponent))]
     public static partial class DBComponentSystem
     {
 	    [EntitySystem]
-	    private static void Awake(this DBComponent self, string dbConnection, string dbName, int zone)
+	    private static void Awake(this DBComponent self, string dbConnection, string dbName)
 		{
 			self.mongoClient = new MongoClient(dbConnection);
 			self.database = self.mongoClient.GetDatabase(dbName);

+ 2 - 3
Unity/Packages/com.et.db/Scripts/Hotfix/Server/DBManagerComponentSystem.cs

@@ -7,7 +7,7 @@ namespace ET.Server
     {
         public static DBComponent GetZoneDB(this DBManagerComponent self, int zone)
         {
-            DBComponent dbComponent = self.DBComponents[zone];
+            DBComponent dbComponent = self.GetChild<DBComponent>(zone);
             if (dbComponent != null)
             {
                 return dbComponent;
@@ -19,8 +19,7 @@ namespace ET.Server
                 throw new Exception($"zone: {zone} not found mongo connect string");
             }
 
-            dbComponent = self.AddChild<DBComponent, string, string, int>(startZoneConfig.DBConnection, startZoneConfig.DBName, zone);
-            self.DBComponents[zone] = dbComponent;
+            dbComponent = self.AddChildWithId<DBComponent, string, string>(zone, startZoneConfig.DBConnection, startZoneConfig.DBName);
             return dbComponent;
         }
     }

+ 1 - 1
Unity/Packages/com.et.db/Scripts/Model/Server/DBComponent.cs

@@ -6,7 +6,7 @@ namespace ET.Server
     /// 用来缓存数据
     /// </summary>
     [ChildOf(typeof(DBManagerComponent))]
-    public class DBComponent: Entity, IAwake<string, string, int>
+    public class DBComponent: Entity, IAwake<string, string>
     {
         public const int TaskCount = 32;
 

+ 0 - 1
Unity/Packages/com.et.db/Scripts/Model/Server/DBManagerComponent.cs

@@ -5,6 +5,5 @@ namespace ET.Server
     [ComponentOf(typeof(Scene))]
     public class DBManagerComponent: Entity, IAwake
     {
-        public DBComponent[] DBComponents = new DBComponent[IdGenerater.MaxZone];
     }
 }