Browse Source

1. Model也检查ChildType分析器
2. Entity增加RemoveChild方法

tanghai 3 years ago
parent
commit
04f060eb1b

+ 1 - 1
Share/Analyzer/Analyzer/AddChildTypeAnalyzer.cs

@@ -46,7 +46,7 @@ namespace ET.Analyzer
 
         private void AnalyzeMemberAccessExpression(SyntaxNodeAnalysisContext context)
         {
-            if (!AnalyzerHelper.IsAssemblyNeedAnalyze(context.Compilation.AssemblyName, AnalyzeAssembly.AllHotfix))
+            if (!AnalyzerHelper.IsAssemblyNeedAnalyze(context.Compilation.AssemblyName, AnalyzeAssembly.All))
             {
                 return;
             }

+ 1 - 1
Share/Analyzer/Analyzer/EntityComponentAnalyzer.cs

@@ -46,7 +46,7 @@ namespace ET.Analyzer
 
         private void AnalyzeMemberAccessExpression(SyntaxNodeAnalysisContext context)
         {
-            if (!AnalyzerHelper.IsAssemblyNeedAnalyze(context.Compilation.AssemblyName, AnalyzeAssembly.AllHotfix))
+            if (!AnalyzerHelper.IsAssemblyNeedAnalyze(context.Compilation.AssemblyName, AnalyzeAssembly.All))
             {
                 return;
             }

+ 16 - 0
Unity/Codes/Model/Core/Object/Entity.cs

@@ -576,6 +576,22 @@ namespace ET
             this.children.TryGetValue(id, out Entity child);
             return child as K;
         }
+        
+        public void RemoveChild(long id)
+        {
+            if (this.children == null)
+            {
+                return;
+            }
+
+            if (!this.children.TryGetValue(id, out Entity child))
+            {
+                return;
+            }
+            
+            this.children.Remove(id);
+            child.Dispose();
+        }
 
         public void RemoveComponent<K>() where K : Entity
         {

+ 1 - 0
Unity/Codes/Model/Core/Timer/TimerComponent.cs

@@ -366,6 +366,7 @@ namespace ET
 
     
     [ComponentOf(typeof(Scene))]
+    [ChildType(typeof(TimerAction))]
     public class TimerComponent: Entity, IAwake, IUpdate, ILoad, IDestroy
     {
         public static TimerComponent Instance

+ 28 - 22
Unity/Codes/Model/Module/CoroutineLock/CoroutineLockComponent.cs

@@ -13,10 +13,11 @@ namespace ET
             {
                 CoroutineLockComponent.Instance = self;
 
-                self.list = new List<CoroutineLockQueueType>(CoroutineLockType.Max);
+                self.list.Clear();
+                
                 for (int i = 0; i < CoroutineLockType.Max; ++i)
                 {
-                    CoroutineLockQueueType coroutineLockQueueType = self.AddChildWithId<CoroutineLockQueueType>(++self.idGenerator);
+                    CoroutineLockQueueType coroutineLockQueueType = self.AddChildWithId<CoroutineLockQueueType>(i);
                     self.list.Add(coroutineLockQueueType);
                 }
             }
@@ -68,7 +69,7 @@ namespace ET
                     return;
                 }
 
-                foreach (KeyValuePair<long, List<CoroutineLockTimer>> kv in self.timers)
+                foreach (KeyValuePair<long, List<long>> kv in self.timers)
                 {
                     long k = kv.Key;
                     if (k > timeNow)
@@ -88,8 +89,7 @@ namespace ET
                     var list = self.timers[time];
                     for (int i = 0; i < list.Count; ++i)
                     {
-                        CoroutineLockTimer coroutineLockTimer = list[i];
-                        self.timerOutTimer.Enqueue(coroutineLockTimer);
+                        self.timerOutTimer.Enqueue(list[i]);
                     }
 
                     self.timers.Remove(time);
@@ -97,13 +97,14 @@ namespace ET
 
                 while (self.timerOutTimer.Count > 0)
                 {
-                    CoroutineLockTimer coroutineLockTimer = self.timerOutTimer.Dequeue();
-                    if (coroutineLockTimer.CoroutineLockInstanceId != coroutineLockTimer.CoroutineLock.InstanceId)
+                    long CoroutineLockInstanceId = self.timerOutTimer.Dequeue();
+                    CoroutineLock coroutineLock = Game.EventSystem.Get(CoroutineLockInstanceId) as CoroutineLock;
+
+                    if (coroutineLock == null)
                     {
                         continue;
                     }
-
-                    CoroutineLock coroutineLock = coroutineLockTimer.CoroutineLock;
+                    
                     // 超时直接调用下一个锁
                     self.RunNextCoroutine(coroutineLock.coroutineLockType, coroutineLock.key, coroutineLock.level + 1);
                     coroutineLock.coroutineLockType = CoroutineLockType.None; // 上面调用了下一个, dispose不再调用
@@ -123,7 +124,7 @@ namespace ET
 
         private static void AddTimer(this CoroutineLockComponent self, long tillTime, CoroutineLock coroutineLock)
         {
-            self.timers.Add(tillTime, new CoroutineLockTimer(coroutineLock));
+            self.timers.Add(tillTime, coroutineLock.InstanceId);
             if (tillTime < self.minTime)
             {
                 self.minTime = tillTime;
@@ -133,20 +134,22 @@ namespace ET
         public static async ETTask<CoroutineLock> Wait(this CoroutineLockComponent self, int coroutineLockType, long key, int time = 60000)
         {
             CoroutineLockQueueType coroutineLockQueueType = self.list[coroutineLockType];
-   
-            if (!coroutineLockQueueType.TryGetValue(key, out CoroutineLockQueue queue))
+
+            CoroutineLockQueue queue = coroutineLockQueueType.GetChild<CoroutineLockQueue>(key);
+            
+            if (queue == null)
             {
-                coroutineLockQueueType.Add(key, self.AddChildWithId<CoroutineLockQueue>(++self.idGenerator, true));
-                return self.CreateCoroutineLock(coroutineLockType, key, time, 1);
+                CoroutineLockQueue coroutineLockQueue = coroutineLockQueueType.AddChildWithId<CoroutineLockQueue>(key, true);
+                return self.CreateCoroutineLock(coroutineLockQueue, coroutineLockType, key, time, 1);
             }
             ETTask<CoroutineLock> tcs = ETTask<CoroutineLock>.Create(true);
             queue.Add(tcs, time);
             return await tcs;
         }
 
-        private static CoroutineLock CreateCoroutineLock(this CoroutineLockComponent self, int coroutineLockType, long key, int time, int level)
+        private static CoroutineLock CreateCoroutineLock(this CoroutineLockComponent self, CoroutineLockQueue coroutineLockQueue, int coroutineLockType, long key, int time, int level)
         {
-            CoroutineLock coroutineLock = self.AddChildWithId<CoroutineLock, int, long, int>(++self.idGenerator, coroutineLockType, key, level, true);
+            CoroutineLock coroutineLock = coroutineLockQueue.AddChildWithId<CoroutineLock, int, long, int>(++self.idGenerator, coroutineLockType, key, level, true);
             if (time > 0)
             {
                 self.AddTimer(TimeHelper.ClientFrameTime() + time, coroutineLock);
@@ -157,32 +160,35 @@ namespace ET
         private static void Notify(this CoroutineLockComponent self, int coroutineLockType, long key, int level)
         {
             CoroutineLockQueueType coroutineLockQueueType = self.list[coroutineLockType];
-            if (!coroutineLockQueueType.TryGetValue(key, out CoroutineLockQueue queue))
+            
+            CoroutineLockQueue queue = coroutineLockQueueType.GetChild<CoroutineLockQueue>(key);
+            if (queue == null)
             {
                 return;
             }
 
             if (queue.Count == 0)
             {
-                coroutineLockQueueType.Remove(key);
+                coroutineLockQueueType.RemoveChild(key);
                 return;
             }
 
             CoroutineLockInfo coroutineLockInfo = queue.Dequeue();
-            coroutineLockInfo.Tcs.SetResult(self.CreateCoroutineLock(coroutineLockType, key, coroutineLockInfo.Time, level));
+            coroutineLockInfo.Tcs.SetResult(self.CreateCoroutineLock(queue, coroutineLockType, key, coroutineLockInfo.Time, level));
         }
     }
 
     [ComponentOf(typeof(Scene))]
+    [ChildType(typeof(CoroutineLockQueueType))]
     public class CoroutineLockComponent: Entity, IAwake, IUpdate, IDestroy
     {
         public static CoroutineLockComponent Instance;
 
-        public List<CoroutineLockQueueType> list;
+        public List<CoroutineLockQueueType> list = new List<CoroutineLockQueueType>(CoroutineLockType.Max);
         public Queue<(int, long, int)> nextFrameRun = new Queue<(int, long, int)>();
-        public MultiMap<long, CoroutineLockTimer> timers = new MultiMap<long, CoroutineLockTimer>();
+        public MultiMap<long, long> timers = new MultiMap<long, long>();
         public Queue<long> timeOutIds = new Queue<long>();
-        public Queue<CoroutineLockTimer> timerOutTimer = new Queue<CoroutineLockTimer>();
+        public Queue<long> timerOutTimer = new Queue<long>();
         public long idGenerator;
         public long minTime;
     }

+ 1 - 0
Unity/Codes/Model/Module/CoroutineLock/CoroutineLockQueue.cs

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

+ 2 - 44
Unity/Codes/Model/Module/CoroutineLock/CoroutineLockQueueType.cs

@@ -1,49 +1,7 @@
-using System.Collections.Generic;
-
-namespace ET
+namespace ET
 {
-    [FriendClass(typeof(CoroutineLockQueueType))]
-    public static class CoroutineLockQueueTypeSystem
-    {
-        [ObjectSystem]
-        public class CoroutineLockQueueTypeAwakeSystem: AwakeSystem<CoroutineLockQueueType>
-        {
-            public override void Awake(CoroutineLockQueueType self)
-            {
-            }
-        }
-
-        [ObjectSystem]
-        public class CoroutineLockQueueTypeDestroySystem: DestroySystem<CoroutineLockQueueType>
-        {
-            public override void Destroy(CoroutineLockQueueType self)
-            {
-                self.dictionary.Clear();
-            }
-        }
-        
-        public static bool TryGetValue(this CoroutineLockQueueType self, long key, out CoroutineLockQueue value)
-        {
-            return self.dictionary.TryGetValue(key, out value);
-        }
-
-        public static void Remove(this CoroutineLockQueueType self, long key)
-        {
-            if (self.dictionary.TryGetValue(key, out CoroutineLockQueue value))
-            {
-                value.Dispose();
-            }
-            self.dictionary.Remove(key);
-        }
-        
-        public static void Add(this CoroutineLockQueueType self, long key, CoroutineLockQueue value)
-        {
-            self.dictionary.Add(key, value);
-        }
-    }
-    
+    [ChildType(typeof(CoroutineLockQueue))]
     public class CoroutineLockQueueType: Entity, IAwake, IDestroy
     {
-        public Dictionary<long, CoroutineLockQueue> dictionary = new Dictionary<long, CoroutineLockQueue>();
     }
 }

+ 1 - 0
Unity/Codes/ModelView/Client/Resource/ResourcesComponent.cs

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

+ 1 - 0
Unity/Codes/ModelView/Module/UI/UI.cs

@@ -72,6 +72,7 @@ namespace ET
         }
     }
 	
+    [ChildType(typeof(UI))]
     public sealed class UI: Entity, IAwake<string, GameObject>, IDestroy
     {
         public GameObject GameObject { get; set; }

+ 31 - 61
Unity/UserSettings/Layouts/default-2021.dwlt

@@ -19,7 +19,7 @@ MonoBehaviour:
     width: 1920
     height: 997
   m_ShowMode: 4
-  m_Title: Inspector
+  m_Title: Game
   m_RootView: {fileID: 12}
   m_MinSize: {x: 875, y: 300}
   m_MaxSize: {x: 10000, y: 10000}
@@ -74,7 +74,7 @@ MonoBehaviour:
   m_MinSize: {x: 100, y: 200}
   m_MaxSize: {x: 8096, y: 16192}
   vertical: 1
-  controlID: 135
+  controlID: 19
 --- !u!114 &4
 MonoBehaviour:
   m_ObjectHideFlags: 52
@@ -94,11 +94,11 @@ MonoBehaviour:
     y: 688
     width: 1481
     height: 259
-  m_MinSize: {x: 101, y: 121}
-  m_MaxSize: {x: 4001, y: 4021}
-  m_ActualView: {fileID: 23}
+  m_MinSize: {x: 100, y: 100}
+  m_MaxSize: {x: 4000, y: 4000}
+  m_ActualView: {fileID: 22}
   m_Panes:
-  - {fileID: 23}
+  - {fileID: 22}
   m_Selected: 0
   m_LastSelected: 0
 --- !u!114 &5
@@ -125,7 +125,7 @@ MonoBehaviour:
   m_MinSize: {x: 100, y: 200}
   m_MaxSize: {x: 8096, y: 16192}
   vertical: 1
-  controlID: 17
+  controlID: 101
 --- !u!114 &6
 MonoBehaviour:
   m_ObjectHideFlags: 52
@@ -145,11 +145,11 @@ MonoBehaviour:
     y: 0
     width: 226
     height: 632
-  m_MinSize: {x: 277, y: 71}
-  m_MaxSize: {x: 4002, y: 4021}
-  m_ActualView: {fileID: 19}
+  m_MinSize: {x: 275, y: 50}
+  m_MaxSize: {x: 4000, y: 4000}
+  m_ActualView: {fileID: 18}
   m_Panes:
-  - {fileID: 19}
+  - {fileID: 18}
   m_Selected: 0
   m_LastSelected: 0
 --- !u!114 &7
@@ -176,7 +176,7 @@ MonoBehaviour:
   m_MinSize: {x: 200, y: 200}
   m_MaxSize: {x: 16192, y: 16192}
   vertical: 0
-  controlID: 16
+  controlID: 100
 --- !u!114 &8
 MonoBehaviour:
   m_ObjectHideFlags: 52
@@ -196,11 +196,11 @@ MonoBehaviour:
     y: 632
     width: 213
     height: 315
-  m_MinSize: {x: 201, y: 221}
-  m_MaxSize: {x: 4001, y: 4021}
-  m_ActualView: {fileID: 20}
+  m_MinSize: {x: 200, y: 200}
+  m_MaxSize: {x: 4000, y: 4000}
+  m_ActualView: {fileID: 19}
   m_Panes:
-  - {fileID: 20}
+  - {fileID: 19}
   m_Selected: 0
   m_LastSelected: 0
 --- !u!114 &9
@@ -227,7 +227,7 @@ MonoBehaviour:
   m_MinSize: {x: 100, y: 200}
   m_MaxSize: {x: 8096, y: 16192}
   vertical: 1
-  controlID: 141
+  controlID: 25
 --- !u!114 &10
 MonoBehaviour:
   m_ObjectHideFlags: 52
@@ -249,9 +249,9 @@ MonoBehaviour:
     height: 632
   m_MinSize: {x: 231, y: 271}
   m_MaxSize: {x: 10001, y: 10021}
-  m_ActualView: {fileID: 18}
+  m_ActualView: {fileID: 17}
   m_Panes:
-  - {fileID: 18}
+  - {fileID: 17}
   m_Selected: 0
   m_LastSelected: 0
 --- !u!114 &11
@@ -278,7 +278,7 @@ MonoBehaviour:
   m_MinSize: {x: 300, y: 200}
   m_MaxSize: {x: 24288, y: 16192}
   vertical: 0
-  controlID: 15
+  controlID: 99
 --- !u!114 &12
 MonoBehaviour:
   m_ObjectHideFlags: 52
@@ -371,11 +371,10 @@ MonoBehaviour:
     height: 688
   m_MinSize: {x: 201, y: 221}
   m_MaxSize: {x: 4001, y: 4021}
-  m_ActualView: {fileID: 22}
+  m_ActualView: {fileID: 21}
   m_Panes:
+  - {fileID: 20}
   - {fileID: 21}
-  - {fileID: 22}
-  - {fileID: 17}
   m_Selected: 1
   m_LastSelected: 0
 --- !u!114 &16
@@ -407,35 +406,6 @@ MonoBehaviour:
     m_LastAppliedPresetName: Default
     m_SaveData: []
 --- !u!114 &17
-MonoBehaviour:
-  m_ObjectHideFlags: 52
-  m_CorrespondingSourceObject: {fileID: 0}
-  m_PrefabInstance: {fileID: 0}
-  m_PrefabAsset: {fileID: 0}
-  m_GameObject: {fileID: 0}
-  m_Enabled: 1
-  m_EditorHideFlags: 1
-  m_Script: {fileID: 12111, guid: 0000000000000000e000000000000000, type: 0}
-  m_Name: 
-  m_EditorClassIdentifier: 
-  m_MinSize: {x: 400, y: 100}
-  m_MaxSize: {x: 2048, y: 2048}
-  m_TitleContent:
-    m_Text: Asset Store
-    m_Image: {fileID: -8693916549880196297, guid: 0000000000000000d000000000000000,
-      type: 0}
-    m_Tooltip: 
-  m_Pos:
-    serializedVersion: 2
-    x: 468
-    y: 181
-    width: 973
-    height: 501
-  m_ViewDataDictionary: {fileID: 0}
-  m_OverlayCanvas:
-    m_LastAppliedPresetName: Default
-    m_SaveData: []
---- !u!114 &18
 MonoBehaviour:
   m_ObjectHideFlags: 52
   m_CorrespondingSourceObject: {fileID: 0}
@@ -575,7 +545,7 @@ MonoBehaviour:
     m_GridSize: 64
   m_SkipHiddenPackages: 0
   m_DirectoriesAreaWidth: 74
---- !u!114 &19
+--- !u!114 &18
 MonoBehaviour:
   m_ObjectHideFlags: 52
   m_CorrespondingSourceObject: {fileID: 0}
@@ -617,7 +587,7 @@ MonoBehaviour:
   m_LockTracker:
     m_IsLocked: 0
   m_PreviewWindow: {fileID: 0}
---- !u!114 &20
+--- !u!114 &19
 MonoBehaviour:
   m_ObjectHideFlags: 52
   m_CorrespondingSourceObject: {fileID: 0}
@@ -675,7 +645,7 @@ MonoBehaviour:
       m_IsLocked: 0
     m_CurrentSortingName: TransformSorting
   m_WindowGUID: cb655c4295f43f24fa5cc27df9b91f17
---- !u!114 &21
+--- !u!114 &20
 MonoBehaviour:
   m_ObjectHideFlags: 52
   m_CorrespondingSourceObject: {fileID: 0}
@@ -696,10 +666,10 @@ MonoBehaviour:
     m_Tooltip: 
   m_Pos:
     serializedVersion: 2
-    x: 338
-    y: 81
-    width: 1186
-    height: 731
+    x: 2359
+    y: 73
+    width: 1480
+    height: 667
   m_ViewDataDictionary: {fileID: 0}
   m_OverlayCanvas:
     m_LastAppliedPresetName: Default
@@ -981,7 +951,7 @@ MonoBehaviour:
   m_SceneVisActive: 1
   m_LastLockedObject: {fileID: 0}
   m_ViewIsLockedToObject: 0
---- !u!114 &22
+--- !u!114 &21
 MonoBehaviour:
   m_ObjectHideFlags: 52
   m_CorrespondingSourceObject: {fileID: 0}
@@ -1074,7 +1044,7 @@ MonoBehaviour:
   m_LowResolutionForAspectRatios: 01000000000000000000
   m_XRRenderMode: 0
   m_RenderTexture: {fileID: 0}
---- !u!114 &23
+--- !u!114 &22
 MonoBehaviour:
   m_ObjectHideFlags: 52
   m_CorrespondingSourceObject: {fileID: 0}