Sfoglia il codice sorgente

修复新的分析器约束产生的代码问题

tanghai 2 anni fa
parent
commit
58d9534b11

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Demo/Gate/PlayerComponentSystem.cs

@@ -18,7 +18,7 @@ namespace ET.Server
         
         public static Player GetByAccount(this PlayerComponent self,  string account)
         {
-            self.dictionary.TryGetValue(account, out Player player);
+            self.dictionary.TryGetValue(account, out EntityRef<Player> player);
             return player;
         }
     }

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Demo/Map/MapMessageHelper.cs

@@ -24,7 +24,7 @@ namespace ET.Server
         public static void Broadcast(Unit unit, IMessage message)
         {
             (message as MessageObject).IsFromPool = false;
-            Dictionary<long, AOIEntity> dict = unit.GetBeSeePlayers();
+            Dictionary<long, EntityRef<AOIEntity>> dict = unit.GetBeSeePlayers();
             // 网络底层做了优化,同一个消息不会多次序列化
             MessageLocationSenderOneType oneTypeMessageLocationType = unit.Root().GetComponent<MessageLocationSenderComponent>().Get(LocationType.GateSession);
             foreach (AOIEntity u in dict.Values)

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Demo/Map/Unit/UnitHelper.cs

@@ -41,7 +41,7 @@ namespace ET.Server
         }
         
         // 获取看见unit的玩家,主要用于广播
-        public static Dictionary<long, AOIEntity> GetBeSeePlayers(this Unit self)
+        public static Dictionary<long, EntityRef<AOIEntity>> GetBeSeePlayers(this Unit self)
         {
             return self.GetComponent<AOIEntity>().GetBeSeePlayers();
         }

+ 5 - 5
Unity/Assets/Scripts/Hotfix/Server/Module/AOI/AOIEntitySystem.cs

@@ -33,17 +33,17 @@ namespace ET.Server
     public static partial class AOIEntitySystem
     {
         // 获取在自己视野中的对象
-        public static Dictionary<long, AOIEntity> GetSeeUnits(this AOIEntity self)
+        public static Dictionary<long, EntityRef<AOIEntity>> GetSeeUnits(this AOIEntity self)
         {
             return self.SeeUnits;
         }
 
-        public static Dictionary<long, AOIEntity> GetBeSeePlayers(this AOIEntity self)
+        public static Dictionary<long, EntityRef<AOIEntity>> GetBeSeePlayers(this AOIEntity self)
         {
             return self.BeSeePlayers;
         }
 
-        public static Dictionary<long, AOIEntity> GetSeePlayers(this AOIEntity self)
+        public static Dictionary<long, EntityRef<AOIEntity>> GetSeePlayers(this AOIEntity self)
         {
             return self.SeePlayers;
         }
@@ -52,7 +52,7 @@ namespace ET.Server
         public static void SubEnter(this AOIEntity self, Cell cell)
         {
             cell.SubsEnterEntities.Add(self.Id, self);
-            foreach (KeyValuePair<long, AOIEntity> kv in cell.AOIUnits)
+            foreach (KeyValuePair<long, EntityRef<AOIEntity>> kv in cell.AOIUnits)
             {
                 if (kv.Key == self.Id)
                 {
@@ -76,7 +76,7 @@ namespace ET.Server
         // cell中的unit离开self的视野
         public static void UnSubLeave(this AOIEntity self, Cell cell)
         {
-            foreach (KeyValuePair<long, AOIEntity> kv in cell.AOIUnits)
+            foreach (KeyValuePair<long, EntityRef<AOIEntity>> kv in cell.AOIUnits)
             {
                 if (kv.Key == self.Id)
                 {

+ 14 - 11
Unity/Assets/Scripts/Hotfix/Server/Module/AOI/AOIManagerComponentSystem.cs

@@ -38,9 +38,10 @@ namespace ET.Server
             aoiEntity.Cell = selfCell;
             selfCell.Add(aoiEntity);
             // 通知订阅该Cell Enter的Unit
-            foreach (KeyValuePair<long, AOIEntity> kv in selfCell.SubsEnterEntities)
+            foreach (KeyValuePair<long, EntityRef<AOIEntity>> kv in selfCell.SubsEnterEntities)
             {
-                kv.Value.EnterSight(aoiEntity);
+                AOIEntity e = kv.Value;
+                e.EnterSight(aoiEntity);
             }
         }
 
@@ -54,9 +55,10 @@ namespace ET.Server
             Fiber fiber = self.Fiber();
             // 通知订阅该Cell Leave的Unit
             aoiEntity.Cell.Remove(aoiEntity);
-            foreach (KeyValuePair<long, AOIEntity> kv in aoiEntity.Cell.SubsLeaveEntities)
+            foreach (KeyValuePair<long, EntityRef<AOIEntity>> kv in aoiEntity.Cell.SubsLeaveEntities)
             {
-                kv.Value.LeaveSight(aoiEntity);
+                AOIEntity e = kv.Value;
+                e.LeaveSight(aoiEntity);
             }
 
             // 通知自己订阅的Enter Cell,清理自己
@@ -101,26 +103,27 @@ namespace ET.Server
             preCell.Remove(aoiEntity);
             newCell.Add(aoiEntity);
             // 通知订阅该newCell Enter的Unit
-            foreach (KeyValuePair<long, AOIEntity> kv in newCell.SubsEnterEntities)
+            foreach (KeyValuePair<long, EntityRef<AOIEntity>> kv in newCell.SubsEnterEntities)
             {
-                if (kv.Value.SubEnterCells.Contains(preCell.Id))
+                AOIEntity e = kv.Value;
+                if (e.SubEnterCells.Contains(preCell.Id))
                 {
                     continue;
                 }
-
-                kv.Value.EnterSight(aoiEntity);
+                e.EnterSight(aoiEntity);
             }
 
             // 通知订阅preCell leave的Unit
-            foreach (KeyValuePair<long, AOIEntity> kv in preCell.SubsLeaveEntities)
+            foreach (KeyValuePair<long, EntityRef<AOIEntity>> kv in preCell.SubsLeaveEntities)
             {
                 // 如果新的cell仍然在对方订阅的subleave中
-                if (kv.Value.SubLeaveCells.Contains(newCell.Id))
+                AOIEntity e = kv.Value;
+                if (e.SubLeaveCells.Contains(newCell.Id))
                 {
                     continue;
                 }
 
-                kv.Value.LeaveSight(aoiEntity);
+                e.LeaveSight(aoiEntity);
             }
         }
 

+ 2 - 1
Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/LocationOneTypeSystem.cs

@@ -82,12 +82,13 @@ namespace ET.Server
 
         public static void UnLock(this LocationOneType self, long key, ActorId oldActorId, ActorId newInstanceId)
         {
-            if (!self.lockInfos.TryGetValue(key, out LockInfo lockInfo))
+            if (!self.lockInfos.TryGetValue(key, out EntityRef<LockInfo> lockInfoRef))
             {
                 Log.Error($"location unlock not found key: {key} {oldActorId}");
                 return;
             }
 
+            LockInfo lockInfo = lockInfoRef;
             if (oldActorId != lockInfo.LockActorId)
             {
                 Log.Error($"location unlock oldInstanceId is different: {key} {oldActorId}");

+ 5 - 5
Unity/Assets/Scripts/HotfixView/Client/Module/UI/UIComponentSystem.cs

@@ -24,7 +24,7 @@ namespace ET.Client
 
 		public static void Remove(this UIComponent self, string uiType)
 		{
-			if (!self.UIs.TryGetValue(uiType, out UI ui))
+			if (!self.UIs.TryGetValue(uiType, out EntityRef<UI> uiRef))
 			{
 				return;
 			}
@@ -32,14 +32,14 @@ namespace ET.Client
 			self.UIGlobalComponent.OnRemove(self, uiType);
 			
 			self.UIs.Remove(uiType);
-			ui.Dispose();
+			UI ui = uiRef;
+			ui?.Dispose();
 		}
 
 		public static UI Get(this UIComponent self, string name)
 		{
-			UI ui = null;
-			self.UIs.TryGetValue(name, out ui);
-			return ui;
+			self.UIs.TryGetValue(name, out EntityRef<UI> uiRef);
+			return uiRef;
 		}
 	}
 }

+ 1 - 1
Unity/Assets/Scripts/Model/Server/Demo/Gate/PlayerComponent.cs

@@ -6,6 +6,6 @@ namespace ET.Server
 	[ComponentOf(typeof(Scene))]
 	public class PlayerComponent : Entity, IAwake, IDestroy
 	{
-		public Dictionary<string, Player> dictionary = new Dictionary<string, Player>();
+		public Dictionary<string, EntityRef<Player>> dictionary = new Dictionary<string, EntityRef<Player>>();
 	}
 }

+ 4 - 4
Unity/Assets/Scripts/Model/Server/Module/AOI/AOIEntity.cs

@@ -37,15 +37,15 @@ namespace ET.Server
         public HashSet<long> leaveHashSet = new HashSet<long>();
 
         // 我看的见的Unit
-        public Dictionary<long, AOIEntity> SeeUnits = new Dictionary<long, AOIEntity>();
+        public Dictionary<long, EntityRef<AOIEntity>> SeeUnits = new Dictionary<long, EntityRef<AOIEntity>>();
         
         // 看见我的Unit
-        public Dictionary<long, AOIEntity> BeSeeUnits = new Dictionary<long, AOIEntity>();
+        public Dictionary<long, EntityRef<AOIEntity>> BeSeeUnits = new Dictionary<long, EntityRef<AOIEntity>>();
         
         // 我看的见的Player
-        public Dictionary<long, AOIEntity> SeePlayers = new Dictionary<long, AOIEntity>();
+        public Dictionary<long, EntityRef<AOIEntity>> SeePlayers = new Dictionary<long, EntityRef<AOIEntity>>();
 
         // 看见我的Player单独放一个Dict,用于广播
-        public Dictionary<long, AOIEntity> BeSeePlayers = new Dictionary<long, AOIEntity>();
+        public Dictionary<long, EntityRef<AOIEntity>> BeSeePlayers = new Dictionary<long, EntityRef<AOIEntity>>();
     }
 }

+ 3 - 3
Unity/Assets/Scripts/Model/Server/Module/AOI/Cell.cs

@@ -6,12 +6,12 @@ namespace ET.Server
     public class Cell: Entity, IAwake, IDestroy
     {
         // 处在这个cell的单位
-        public Dictionary<long, AOIEntity> AOIUnits = new Dictionary<long, AOIEntity>();
+        public Dictionary<long, EntityRef<AOIEntity>> AOIUnits = new Dictionary<long, EntityRef<AOIEntity>>();
 
         // 订阅了这个Cell的进入事件
-        public Dictionary<long, AOIEntity> SubsEnterEntities = new Dictionary<long, AOIEntity>();
+        public Dictionary<long, EntityRef<AOIEntity>> SubsEnterEntities = new Dictionary<long, EntityRef<AOIEntity>>();
 
         // 订阅了这个Cell的退出事件
-        public Dictionary<long, AOIEntity> SubsLeaveEntities = new Dictionary<long, AOIEntity>();
+        public Dictionary<long, EntityRef<AOIEntity>> SubsLeaveEntities = new Dictionary<long, EntityRef<AOIEntity>>();
     }
 }

+ 1 - 1
Unity/Assets/Scripts/Model/Server/Module/ActorLocation/LocationComponent.cs

@@ -32,7 +32,7 @@ namespace ET.Server
         
         public readonly Dictionary<long, ActorId> locations = new();
 
-        public readonly Dictionary<long, LockInfo> lockInfos = new();
+        public readonly Dictionary<long, EntityRef<LockInfo>> lockInfos = new();
     }
 
     [ComponentOf(typeof(Scene))]

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

@@ -7,7 +7,7 @@ namespace ET.Server
     [ComponentOf(typeof(Scene))]
     public class RobotCaseComponent: Entity, IAwake, IDestroy
     {
-        public Dictionary<int, RobotCase> RobotCases = new Dictionary<int, RobotCase>();
+        public Dictionary<int, EntityRef<RobotCase>> RobotCases = new Dictionary<int, EntityRef<RobotCase>>();
         public int N = 10000;
     }
 }

+ 10 - 9
Unity/Assets/Scripts/ModelView/Client/Module/UI/UI.cs

@@ -40,28 +40,29 @@ namespace ET.Client
 
         public static void Remove(this UI self, string name)
         {
-            UI ui;
-            if (!self.nameChildren.TryGetValue(name, out ui))
+            EntityRef<UI> uiRef;
+            if (!self.nameChildren.Remove(name, out uiRef))
             {
                 return;
             }
-            self.nameChildren.Remove(name);
-            ui.Dispose();
+
+            UI ui = uiRef;
+            ui?.Dispose();
         }
 
         public static UI Get(this UI self, string name)
         {
-            UI child;
-            if (self.nameChildren.TryGetValue(name, out child))
+            EntityRef<UI> uiRef;
+            if (self.nameChildren.TryGetValue(name, out uiRef))
             {
-                return child;
+                return uiRef;
             }
             GameObject childGameObject = self.GameObject.transform.Find(name)?.gameObject;
             if (childGameObject == null)
             {
                 return null;
             }
-            child = self.AddChild<UI, string, GameObject>(name, childGameObject);
+            UI child = self.AddChild<UI, string, GameObject>(name, childGameObject);
             self.Add(child);
             return child;
         }
@@ -74,6 +75,6 @@ namespace ET.Client
 		
         public string Name { get; set; }
 
-        public Dictionary<string, UI> nameChildren = new Dictionary<string, UI>();
+        public Dictionary<string, EntityRef<UI>> nameChildren = new();
     }
 }

+ 1 - 1
Unity/Assets/Scripts/ModelView/Client/Module/UI/UIComponent.cs

@@ -8,7 +8,7 @@ namespace ET.Client
 	[ComponentOf]
 	public class UIComponent: Entity, IAwake
 	{
-		public Dictionary<string, UI> UIs = new();
+		public Dictionary<string, EntityRef<UI>> UIs = new();
 
 		private EntityRef<UIGlobalComponent> uiGlobalComponent;