Преглед изворни кода

ChildType标签改名ChildOf, 要挂在Child实体上 (#381)

* ChildType标签改名ChildOf, 要挂在Child实体上
susices пре 3 година
родитељ
комит
bed2097cee
29 измењених фајлова са 56 додато и 48 уклоњено
  1. 29 26
      Codes/Analyzer/Analyzer/AddChildTypeAnalyzer.cs
  2. 2 0
      Codes/Hotfix/Server/Demo/Gate/C2G_EnterMapHandler.cs
  3. 1 0
      Codes/Model/Server/Demo/Gate/Player.cs
  4. 0 1
      Codes/Model/Server/Demo/Gate/PlayerComponent.cs
  5. 0 1
      Codes/Model/Server/Module/AOI/AOIManagerComponent.cs
  6. 1 0
      Codes/Model/Server/Module/AOI/Cell.cs
  7. 1 0
      Codes/Model/Server/Module/ActorLocation/ActorLocationSender.cs
  8. 1 1
      Codes/Model/Server/Module/ActorLocation/ActorLocationSenderComponent.cs
  9. 2 2
      Codes/Model/Server/Module/ActorLocation/LocationComponent.cs
  10. 1 0
      Codes/Model/Server/Module/DB/DBComponent.cs
  11. 1 1
      Codes/Model/Server/Module/DB/DBManagerComponent.cs
  12. 1 1
      Codes/Model/Server/Module/MessageInner/NetInnerComponent.cs
  13. 1 0
      Codes/Model/Server/Module/RobotCase/RobotCase.cs
  14. 1 1
      Codes/Model/Server/Module/RobotCase/RobotCaseComponent.cs
  15. 1 1
      Codes/Model/Server/Module/Router/RouterComponent.cs
  16. 1 0
      Codes/Model/Server/Module/Router/RouterNode.cs
  17. 1 1
      Codes/Model/Share/Module/CoroutineLock/CoroutineLock.cs
  18. 0 1
      Codes/Model/Share/Module/CoroutineLock/CoroutineLockComponent.cs
  19. 1 1
      Codes/Model/Share/Module/CoroutineLock/CoroutineLockQueue.cs
  20. 1 1
      Codes/Model/Share/Module/CoroutineLock/CoroutineLockQueueType.cs
  21. 0 1
      Codes/Model/Share/Module/Message/NetKcpComponent.cs
  22. 1 0
      Codes/Model/Share/Module/Message/Session.cs
  23. 1 1
      Codes/Model/Share/Module/Timer/TimerComponent.cs
  24. 1 0
      Codes/Model/Share/Module/Unit/Unit.cs
  25. 1 1
      Codes/Model/Share/Module/Unit/UnitComponent.cs
  26. 1 1
      Codes/ModelView/Client/Module/Resource/ResourcesComponent.cs
  27. 2 2
      Codes/ModelView/Client/Module/UI/UI.cs
  28. 0 1
      Codes/ModelView/Client/Module/UI/UIComponent.cs
  29. 2 2
      Unity/Assets/Scripts/Core/Object/ChildOfAttribute.cs

+ 29 - 26
Codes/Analyzer/Analyzer/AddChildTypeAnalyzer.cs

@@ -13,9 +13,9 @@ namespace ET.Analyzer
     {
         private const string Title = "AddChild方法类型约束错误";
 
-        private const string MessageFormat = "Type: {0} 不允许作为实体: {1} 的AddChild函数参数类型! 若要允许该类型作为参数,请使用ChildTypeAttribute对实体类进行标记";
+        private const string MessageFormat = "Type: {0} 不允许作为实体: {1} 的AddChild函数参数类型! 若要允许该类型作为参数,请使用ChildOfAttribute对child实体类标记父级类型";
 
-        private const string Description = "请使用被允许的ChildType 或添加该类型至ChildType.";
+        private const string Description = "AddChild方法类型约束错误.";
 
         private static readonly string[] AddChildMethods = { "AddChild", "AddChildWithId" };
         
@@ -83,28 +83,6 @@ namespace ET.Analyzer
                 return;
             }
 
-            // 获取实体类 ChildType标签的约束类型
-            INamedTypeSymbol? availableChildTypeSymbol = null;
-            bool hasChildTypeAttribute = false;
-            foreach (AttributeData? attributeData in parentTypeSymbol.GetAttributes())
-            {
-                if (attributeData.AttributeClass?.Name == "ChildTypeAttribute")
-                {
-                    hasChildTypeAttribute = true;
-                    if (!(attributeData.ConstructorArguments[0].Value is INamedTypeSymbol s))
-                    {
-                        continue;
-                    }
-
-                    availableChildTypeSymbol = s;
-                }
-            }
-            
-            if (hasChildTypeAttribute &&(availableChildTypeSymbol==null))
-            {
-                return;
-            }
-
             // 获取 child实体类型
             ISymbol? childTypeSymbol = null;
             // addChild为泛型调用
@@ -186,8 +164,33 @@ namespace ET.Analyzer
                 return;
             }
             
-            // 判断child类型是否属于约束类型
-            if (availableChildTypeSymbol?.ToString() == childTypeSymbol.ToString())
+            // 获取ChildOf标签的约束类型
+
+            if (!(childTypeSymbol is ITypeSymbol childType))
+            {
+                throw new Exception($"{childTypeSymbol} 不是typeSymbol");
+            }
+
+            INamedTypeSymbol? availableParentType = null;
+            bool hasAttribute = false;
+
+            foreach (AttributeData? attributeData in childType.GetAttributes())
+            {
+                if (attributeData.AttributeClass?.Name == "ChildOfAttribute")
+                {
+                    hasAttribute = true;
+                    availableParentType = attributeData.ConstructorArguments[0].Value as INamedTypeSymbol;
+                    break;
+                }
+            }
+
+            if (hasAttribute && availableParentType==null)
+            {
+                return;
+            }
+            
+            // 判断父级类型是否属于child约束的父级类型
+            if (availableParentType?.ToString() == parentTypeSymbol.ToString())
             {
                 return;
             }

+ 2 - 0
Codes/Hotfix/Server/Demo/Gate/C2G_EnterMapHandler.cs

@@ -10,6 +10,8 @@ namespace ET.Server
 		{
 			Player player = session.GetComponent<SessionPlayerComponent>().GetMyPlayer();
 
+			
+			
 			// 在Gate上动态创建一个Map Scene,把Unit从DB中加载放进来,然后传送到真正的Map中,这样登陆跟传送的逻辑就完全一样了
 			GateMapComponent gateMapComponent = player.AddComponent<GateMapComponent>();
 			gateMapComponent.Scene = await SceneFactory.Create(gateMapComponent, "GateMap", SceneType.Map);

+ 1 - 0
Codes/Model/Server/Demo/Gate/Player.cs

@@ -1,5 +1,6 @@
 namespace ET.Server
 {
+    [ChildOf(typeof(PlayerComponent))]
     public sealed class Player : Entity, IAwake<string>
     {
         public string Account { get; set; }

+ 0 - 1
Codes/Model/Server/Demo/Gate/PlayerComponent.cs

@@ -3,7 +3,6 @@ using System.Linq;
 
 namespace ET.Server
 {
-	[ChildType(typeof(Player))]
 	[ComponentOf(typeof(Scene))]
 	public class PlayerComponent : Entity, IAwake, IDestroy
 	{

+ 0 - 1
Codes/Model/Server/Module/AOI/AOIManagerComponent.cs

@@ -1,6 +1,5 @@
 namespace ET.Server
 {
-    [ChildType(typeof(Cell))]
     [ComponentOf(typeof(Scene))]
     public class AOIManagerComponent: Entity, IAwake
     {

+ 1 - 0
Codes/Model/Server/Module/AOI/Cell.cs

@@ -2,6 +2,7 @@
 
 namespace ET.Server
 {
+    [ChildOf(typeof(AOIManagerComponent))]
     public class Cell: Entity, IAwake, IDestroy
     {
         // 处在这个cell的单位

+ 1 - 0
Codes/Model/Server/Module/ActorLocation/ActorLocationSender.cs

@@ -3,6 +3,7 @@
 namespace ET.Server
 {
     // 知道对方的Id,使用这个类发actor消息
+    [ChildOf(typeof(ActorLocationSenderComponent))]
     public class ActorLocationSender: Entity, IAwake, IDestroy
     {
         public long ActorId;

+ 1 - 1
Codes/Model/Server/Module/ActorLocation/ActorLocationSenderComponent.cs

@@ -2,7 +2,7 @@
 
 namespace ET.Server
 {
-    [ChildType(typeof(ActorLocationSender))]
+    
     [ComponentOf(typeof(Scene))]
     public class ActorLocationSenderComponent: Entity, IAwake, IDestroy
     {

+ 2 - 2
Codes/Model/Server/Module/ActorLocation/LocationComponent.cs

@@ -2,14 +2,14 @@
 
 namespace ET.Server
 {
+    [ChildOf(typeof(LocationComponent))]
     public class LockInfo: Entity, IAwake<long, CoroutineLock>, IDestroy
     {
         public long LockInstanceId;
 
         public CoroutineLock CoroutineLock;
     }
-
-    [ChildType(typeof(LockInfo))]
+    
     [ComponentOf(typeof(Scene))]
     public class LocationComponent: Entity, IAwake
     {

+ 1 - 0
Codes/Model/Server/Module/DB/DBComponent.cs

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

+ 1 - 1
Codes/Model/Server/Module/DB/DBManagerComponent.cs

@@ -1,6 +1,6 @@
 namespace ET.Server
 {
-    [ChildType(typeof(DBComponent))]
+    
     public class DBManagerComponent: Entity, IAwake, IDestroy
     {
         public static DBManagerComponent Instance;

+ 1 - 1
Codes/Model/Server/Module/MessageInner/NetInnerComponent.cs

@@ -19,7 +19,7 @@ namespace ET.Server
         }
     }
 
-    [ChildType(typeof(Session))]
+    
     [ComponentOf(typeof(Scene))]
     public class NetInnerComponent: Entity, IAwake<IPEndPoint, int>, IAwake<int>, IDestroy
     {

+ 1 - 0
Codes/Model/Server/Module/RobotCase/RobotCase.cs

@@ -2,6 +2,7 @@
 
 namespace ET.Server
 {
+    [ChildOf(typeof(RobotCaseComponent))]
     public class RobotCase: Entity, IAwake
     {
         public ETCancellationToken CancellationToken;

+ 1 - 1
Codes/Model/Server/Module/RobotCase/RobotCaseComponent.cs

@@ -2,7 +2,7 @@
 
 namespace ET.Server
 {
-    [ChildType(typeof(RobotCase))]
+    
     [ComponentOf(typeof(Scene))]
     public class RobotCaseComponent: Entity, IAwake, IDestroy
     {

+ 1 - 1
Codes/Model/Server/Module/Router/RouterComponent.cs

@@ -5,7 +5,7 @@ using System.Net.Sockets;
 
 namespace ET.Server
 {
-    [ChildType(typeof(RouterNode))]
+    
     [ComponentOf(typeof(Scene))]
     public class RouterComponent: Entity, IAwake<IPEndPoint, string>, IDestroy, IUpdate
     {

+ 1 - 0
Codes/Model/Server/Module/Router/RouterNode.cs

@@ -8,6 +8,7 @@ namespace ET.Server
         Msg,
     }
 
+    [ChildOf(typeof(RouterComponent))]
     public class RouterNode: Entity, IDestroy, IAwake
     {
         public uint ConnectId;

+ 1 - 1
Codes/Model/Share/Module/CoroutineLock/CoroutineLock.cs

@@ -32,7 +32,7 @@ namespace ET
             self.level = 0;
         }
     }
-    
+    [ChildOf(typeof(CoroutineLockQueue))]
     public class CoroutineLock: Entity, IAwake<int, long, int>, IDestroy
     {
         public int coroutineLockType;

+ 0 - 1
Codes/Model/Share/Module/CoroutineLock/CoroutineLockComponent.cs

@@ -179,7 +179,6 @@ namespace ET
     }
 
     [ComponentOf(typeof(Scene))]
-    [ChildType(typeof(CoroutineLockQueueType))]
     public class CoroutineLockComponent: Entity, IAwake, IUpdate, IDestroy
     {
         public static CoroutineLockComponent Instance;

+ 1 - 1
Codes/Model/Share/Module/CoroutineLock/CoroutineLockQueue.cs

@@ -40,7 +40,7 @@ namespace ET
         }
     }
     
-    [ChildType(typeof(CoroutineLock))]
+    [ChildOf(typeof(CoroutineLockQueueType))]
     public class CoroutineLockQueue: Entity, IAwake, IDestroy
     {
         public Queue<CoroutineLockInfo> queue = new Queue<CoroutineLockInfo>();

+ 1 - 1
Codes/Model/Share/Module/CoroutineLock/CoroutineLockQueueType.cs

@@ -1,6 +1,6 @@
 namespace ET
 {
-    [ChildType(typeof(CoroutineLockQueue))]
+    [ChildOf(typeof(CoroutineLockComponent))]
     public class CoroutineLockQueueType: Entity, IAwake, IDestroy
     {
     }

+ 0 - 1
Codes/Model/Share/Module/Message/NetKcpComponent.cs

@@ -2,7 +2,6 @@
 
 namespace ET
 {
-    [ChildType(typeof(Session))]
     [ComponentOf(typeof(Scene))]
     public class NetKcpComponent: Entity, IAwake<int>, IAwake<IPEndPoint, int>, IDestroy, IAwake<IAction<int>>
     {

+ 1 - 0
Codes/Model/Share/Module/Message/Session.cs

@@ -143,6 +143,7 @@ namespace ET
         }
     }
 
+    [ChildOf]
     public sealed class Session: Entity, IAwake<AService>, IDestroy
     {
         public AService AService { get; set; }

+ 1 - 1
Codes/Model/Share/Module/Timer/TimerComponent.cs

@@ -35,6 +35,7 @@ namespace ET
         }
     }
     
+    [ChildOf(typeof(TimerComponent))]
     public class TimerAction: Entity, IAwake, IAwake<TimerClass, long, int, object>, IDestroy
     {
         public TimerClass TimerClass;
@@ -314,7 +315,6 @@ namespace ET
 
     
     [ComponentOf(typeof(Scene))]
-    [ChildType(typeof(TimerAction))]
     public class TimerComponent: Entity, IAwake, IUpdate, ILoad, IDestroy
     {
         public static TimerComponent Instance

+ 1 - 0
Codes/Model/Share/Module/Unit/Unit.cs

@@ -3,6 +3,7 @@ using UnityEngine;
 
 namespace ET
 {
+    [ChildOf(typeof(UnitComponent))]
     public class Unit: Entity, IAwake<int>
     {
         public int ConfigId { get; set; } //配置表id

+ 1 - 1
Codes/Model/Share/Module/Unit/UnitComponent.cs

@@ -1,6 +1,6 @@
 namespace ET
 {
-	[ChildType(typeof(Unit))]
+	
 	[ComponentOf(typeof(Scene))]
 	public class UnitComponent: Entity, IAwake, IDestroy
 	{

+ 1 - 1
Codes/ModelView/Client/Module/Resource/ResourcesComponent.cs

@@ -47,6 +47,7 @@ namespace ET.Client
         }
     }
 
+    [ChildOf(typeof(ResourcesComponent))]
     public class ABInfo: Entity, IAwake<string, AssetBundle>, IDestroy
     {
         public string Name { get; set; }
@@ -600,7 +601,6 @@ namespace ET.Client
     }
     
     [ComponentOf(typeof(Scene))]
-    [ChildType(typeof(ABInfo))]
     public class ResourcesComponent: Entity, IAwake, IDestroy
     {
         public static ResourcesComponent Instance { get; set; }

+ 2 - 2
Codes/ModelView/Client/Module/UI/UI.cs

@@ -71,8 +71,8 @@ namespace ET
             return child;
         }
     }
-	
-    [ChildType(typeof(UI))]
+    
+    [ChildOf()]
     public sealed class UI: Entity, IAwake<string, GameObject>, IDestroy
     {
         public GameObject GameObject { get; set; }

+ 0 - 1
Codes/ModelView/Client/Module/UI/UIComponent.cs

@@ -5,7 +5,6 @@ namespace ET
 	/// <summary>
 	/// 管理Scene上的UI
 	/// </summary>
-	[ChildType(typeof(UI))]
 	[ComponentOf(typeof(Scene))]
 	public class UIComponent: Entity, IAwake
 	{

+ 2 - 2
Unity/Assets/Scripts/Core/Object/ChildTypeAttribute.cs → Unity/Assets/Scripts/Core/Object/ChildOfAttribute.cs

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