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

去掉所有的Fiber中的Instance,还剩下NetService

tanghai 2 лет назад
Родитель
Сommit
e51cf21349
78 измененных файлов с 410 добавлено и 376 удалено
  1. 5 0
      Unity/Assets/Scripts/Core/Entity/EntityHelper.cs
  2. 48 5
      Unity/Assets/Scripts/Core/Entity/EntityRef.cs
  3. 0 13
      Unity/Assets/Scripts/Core/Entity/SingletonEntity.cs
  4. 0 3
      Unity/Assets/Scripts/Core/Entity/SingletonEntity.cs.meta
  5. 0 44
      Unity/Assets/Scripts/Core/Fiber/Fiber.cs
  6. 20 21
      Unity/Assets/Scripts/Core/Fiber/Module/CoroutineLock/CoroutineLock.cs
  7. 8 23
      Unity/Assets/Scripts/Core/Fiber/Module/CoroutineLock/CoroutineLockComponent.cs
  8. 46 40
      Unity/Assets/Scripts/Core/Fiber/Module/CoroutineLock/CoroutineLockQueue.cs
  9. 21 24
      Unity/Assets/Scripts/Core/Fiber/Module/CoroutineLock/CoroutineLockQueueType.cs
  10. 1 1
      Unity/Assets/Scripts/Core/Fiber/Module/Synchronization/MainThreadSynchronizationContext.cs
  11. 1 1
      Unity/Assets/Scripts/Core/Fiber/Module/Timer/TimerComponent.cs
  12. 1 1
      Unity/Assets/Scripts/Core/Helper/ETCancelationTokenHelper.cs
  13. 1 1
      Unity/Assets/Scripts/Core/World/Module/Network/NetServices.cs
  14. 1 1
      Unity/Assets/Scripts/Hotfix/Client/Demo/AI/AI_Attack.cs
  15. 3 2
      Unity/Assets/Scripts/Hotfix/Client/Demo/Ping/PingComponentSystem.cs
  16. 1 1
      Unity/Assets/Scripts/Hotfix/Client/Demo/Router/RouterAddressComponentSystem.cs
  17. 2 1
      Unity/Assets/Scripts/Hotfix/Client/Demo/Router/RouterCheckComponentSystem.cs
  18. 1 1
      Unity/Assets/Scripts/Hotfix/Client/Demo/Router/RouterHelper.cs
  19. 2 2
      Unity/Assets/Scripts/Hotfix/Client/Demo/Scene/SceneFactory.cs
  20. 15 8
      Unity/Assets/Scripts/Hotfix/Client/Module/Message/NetClientComponentSystem.cs
  21. 14 14
      Unity/Assets/Scripts/Hotfix/Server/Demo/EntryEvent2_InitServer.cs
  22. 4 12
      Unity/Assets/Scripts/Hotfix/Server/Demo/Helper/MessageHelper.cs
  23. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Benchmark/BenchmarkClientComponentSystem.cs
  24. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Gate/C2G_EnterMapHandler.cs
  25. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Gate/C2G_LoginGateHandler.cs
  26. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Gate/GateSessionKeyComponentSystem.cs
  27. 2 2
      Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Gate/SessionPlayerComponentSystem.cs
  28. 3 3
      Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Map/Transfer/M2M_UnitTransferRequestHandler.cs
  29. 4 2
      Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Map/Transfer/TransferHelper.cs
  30. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Realm/C2R_LoginHandler.cs
  31. 4 3
      Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Robot/Console/CreateRobotConsoleHandler.cs
  32. 3 3
      Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Robot/RobotConsoleHandler.cs
  33. 5 4
      Unity/Assets/Scripts/Hotfix/Server/Demo/Session/NetServerComponentOnReadEvent.cs
  34. 1 1
      Unity/Assets/Scripts/Hotfix/Server/LockStep/Gate/C2G_MatchHandler.cs
  35. 1 1
      Unity/Assets/Scripts/Hotfix/Server/LockStep/Map/C2Room_ChangeSceneFinishHandler.cs
  36. 1 1
      Unity/Assets/Scripts/Hotfix/Server/LockStep/Map/FrameMessageHandler.cs
  37. 3 2
      Unity/Assets/Scripts/Hotfix/Server/LockStep/Map/RoomMessageHelper.cs
  38. 3 2
      Unity/Assets/Scripts/Hotfix/Server/LockStep/Match/MatchComponentSystem.cs
  39. 1 1
      Unity/Assets/Scripts/Hotfix/Server/LockStep/Room/C2Room_CheckHashHandler.cs
  40. 19 15
      Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/ActorLocationSenderComponentSystem.cs
  41. 2 2
      Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/ActorMessageLocationHandler.cs
  42. 5 5
      Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/LocationOneTypeSystem.cs
  43. 7 7
      Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/LocationProxyComponentSystem.cs
  44. 14 14
      Unity/Assets/Scripts/Hotfix/Server/Module/DB/DBComponentSystem.cs
  45. 19 11
      Unity/Assets/Scripts/Hotfix/Server/Module/Message/NetInnerComponentSystem.cs
  46. 7 5
      Unity/Assets/Scripts/Hotfix/Server/Module/Message/NetServerComponentSystem.cs
  47. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Module/RobotCase/ARobotCase.cs
  48. 2 1
      Unity/Assets/Scripts/Hotfix/Server/Module/Router/RouterComponentSystem.cs
  49. 9 5
      Unity/Assets/Scripts/Hotfix/Share/Module/AI/AIComponentSystem.cs
  50. 1 1
      Unity/Assets/Scripts/Hotfix/Share/Module/Actor/ActorMessageHandler.cs
  51. 6 4
      Unity/Assets/Scripts/Hotfix/Share/Module/Actor/ActorMessageRecvComponentSystem.cs
  52. 6 2
      Unity/Assets/Scripts/Hotfix/Share/Module/Actor/ActorMessageSenderComponentSystem.cs
  53. 1 1
      Unity/Assets/Scripts/Hotfix/Share/Module/Console/ConsoleComponentSystem.cs
  54. 1 1
      Unity/Assets/Scripts/Hotfix/Share/Module/Console/ReloadConfigConsoleHandler.cs
  55. 1 1
      Unity/Assets/Scripts/Hotfix/Share/Module/Console/ReloadDllConsoleHandler.cs
  56. 6 2
      Unity/Assets/Scripts/Hotfix/Share/Module/Message/SessionAcceptTimeoutComponentSystem.cs
  57. 6 2
      Unity/Assets/Scripts/Hotfix/Share/Module/Message/SessionIdleCheckerComponentSystem.cs
  58. 6 2
      Unity/Assets/Scripts/Hotfix/Share/Module/Move/MoveComponentSystem.cs
  59. 1 1
      Unity/Assets/Scripts/Hotfix/Share/Module/Recast/PathfindingComponentSystem.cs
  60. 1 1
      Unity/Assets/Scripts/Model/Server/Demo/Watcher/WatcherComponent.cs
  61. 1 1
      Unity/Assets/Scripts/Model/Server/Module/ActorLocation/ActorLocationSenderOneType.cs
  62. 15 3
      Unity/Assets/Scripts/Model/Server/Module/ActorLocation/LocationComponent.cs
  63. 1 1
      Unity/Assets/Scripts/Model/Server/Module/ActorLocation/LocationProxyComponent.cs
  64. 1 1
      Unity/Assets/Scripts/Model/Server/Module/DB/DBManagerComponent.cs
  65. 1 1
      Unity/Assets/Scripts/Model/Server/Module/Message/NetInnerComponent.cs
  66. 1 1
      Unity/Assets/Scripts/Model/Server/Module/RobotCase/RobotCaseComponent.cs
  67. 1 0
      Unity/Assets/Scripts/Model/Server/Module/RobotCase/RobotInvokeArgs.cs
  68. 1 1
      Unity/Assets/Scripts/Model/Share/Module/Actor/ActorMessageRecvComponent.cs
  69. 1 1
      Unity/Assets/Scripts/Model/Share/Module/Actor/ActorMessageSenderComponent.cs
  70. 1 1
      Unity/Assets/Scripts/Model/Share/Module/Console/ConsoleComponent.cs
  71. 1 1
      Unity/Assets/Scripts/Model/Share/Module/Console/IConsoleHandler.cs
  72. 2 2
      Unity/Assets/Scripts/Model/Share/Module/Message/Session.cs
  73. 1 1
      Unity/Assets/Scripts/Model/Share/Module/ObjectWait/ObjectWait.cs
  74. 1 1
      Unity/Assets/Scripts/Model/Share/Module/Recast/NavmeshComponent.cs
  75. 1 1
      Unity/Assets/Scripts/Model/Share/Module/Scene/ClientSceneManagerComponent.cs
  76. 1 1
      Unity/Assets/Scripts/Model/Share/Module/Scene/ServerSceneManagerComponent.cs
  77. 6 5
      Unity/Assets/Scripts/ModelView/Client/Module/Resource/ResourcesComponent.cs
  78. 21 20
      Unity/Assets/Scripts/ModelView/Client/Module/Resource/ResourcesLoaderComponent.cs

+ 5 - 0
Unity/Assets/Scripts/Core/Entity/EntityHelper.cs

@@ -12,6 +12,11 @@ namespace ET
             return entity.IScene as Scene;
         }
         
+        public static T Scene<T>(this Entity entity) where T: class, IScene 
+        {
+            return entity.IScene as T;
+        }
+        
         public static Fiber Fiber(this Entity entity)
         {
             return entity.IScene.Root as Fiber;

+ 48 - 5
Unity/Assets/Scripts/Core/Entity/EntityRef.cs

@@ -2,15 +2,58 @@ using System;
 
 namespace ET
 {
-    public struct EntityRef<T> where T: Entity
+    public readonly struct EntityRef<T> where T: Entity
+    {
+        private readonly long instanceId;
+        private readonly T entity;
+
+        private EntityRef(T t)
+        {
+            this.instanceId = t.InstanceId;
+            this.entity = t;
+        }
+        
+        private T UnWrap
+        {
+            get
+            {
+                if (this.entity == null)
+                {
+                    return null;
+                }
+                if (this.entity.InstanceId != this.instanceId)
+                {
+                    return null;
+                }
+                return this.entity;
+            }
+        }
+        
+        public static implicit operator EntityRef<T>(T t)
+        {
+            return new EntityRef<T>(t);
+        }
+
+        public static implicit operator T(EntityRef<T> v)
+        {
+            return v.UnWrap;
+        }
+    }
+    
+    
+    public struct EntityWeakRef<T> where T: Entity
     {
         private long instanceId;
         // 使用WeakReference,这样不会导致entity dispose了却无法gc的问题
         // 不过暂时没有测试WeakReference的性能
         private readonly WeakReference<T> weakRef;
 
-        private EntityRef(T t)
+        private EntityWeakRef(T t)
         {
+            if (t == null)
+            {
+                return;
+            }
             this.instanceId = t.InstanceId;
             this.weakRef = new WeakReference<T>(t);
         }
@@ -39,12 +82,12 @@ namespace ET
             }
         }
         
-        public static implicit operator EntityRef<T>(T t)
+        public static implicit operator EntityWeakRef<T>(T t)
         {
-            return new EntityRef<T>(t);
+            return new EntityWeakRef<T>(t);
         }
 
-        public static implicit operator T(EntityRef<T> v)
+        public static implicit operator T(EntityWeakRef<T> v)
         {
             return v.UnWrap;
         }

+ 0 - 13
Unity/Assets/Scripts/Core/Entity/SingletonEntity.cs

@@ -1,13 +0,0 @@
-namespace ET
-{
-    public class SingletonEntity<T>: Entity where T: SingletonEntity<T>
-    {
-        public static T Instance
-        {
-            get
-            {
-                return Fiber.Instance.GetComponent<T>();
-            }
-        }
-    }
-}

+ 0 - 3
Unity/Assets/Scripts/Core/Entity/SingletonEntity.cs.meta

@@ -1,3 +0,0 @@
-fileFormatVersion: 2
-guid: 937fcae73be34d13ae7946b632e1ab52
-timeCreated: 1687330710

+ 0 - 44
Unity/Assets/Scripts/Core/Fiber/Fiber.cs

@@ -98,49 +98,5 @@ namespace ET
 
             instance = null;
         }
-
-        #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
     }
 }

+ 20 - 21
Unity/Assets/Scripts/Core/Fiber/Module/CoroutineLock/CoroutineLock.cs

@@ -2,32 +2,31 @@ using System;
 
 namespace ET
 {
-    public class CoroutineLock: IDisposable
+    public static partial class CoroutineLockSystem
     {
-        private int type;
-        private long key;
-        private int level;
-        
-        public static CoroutineLock Create(int type, long k, int count)
+        [EntitySystem]
+        private static void Awake(this CoroutineLock self, int type, long k, int count)
         {
-            CoroutineLock coroutineLock = ObjectPool.Instance.Fetch<CoroutineLock>();
-            coroutineLock.type = type;
-            coroutineLock.key = k;
-            coroutineLock.level = count;
-            return coroutineLock;
+            self.type = type;
+            self.key = k;
+            self.level = count;
         }
         
-        public void Dispose()
+        [EntitySystem]
+        private static void Destroy(this CoroutineLock self)
         {
-            CoroutineLockComponent.Instance.RunNextCoroutine(this.type, this.key, this.level + 1);
-            
-            this.type = CoroutineLockType.None;
-            this.key = 0;
-            this.level = 0;
-            
-            ObjectPool.Instance.Recycle(this);
+            self.Scene<CoroutineLockComponent>().RunNextCoroutine(self.type, self.key, self.level + 1);
+            self.type = CoroutineLockType.None;
+            self.key = 0;
+            self.level = 0;
         }
-
-        public bool IsFromPool { get; set; }
+    }
+    
+    [ChildOf(typeof(CoroutineLockQueue))]
+    public class CoroutineLock: Entity, IAwake<int, long, int>
+    {
+        public int type;
+        public long key;
+        public int level;
     }
 }

+ 8 - 23
Unity/Assets/Scripts/Core/Fiber/Module/CoroutineLock/CoroutineLockComponent.cs

@@ -4,21 +4,12 @@ using System.Collections.Generic;
 namespace ET
 {
     [ComponentOf(typeof(Fiber))]
-    public class CoroutineLockComponent: SingletonEntity<CoroutineLockComponent>, IAwake
+    public class CoroutineLockComponent: Entity, IAwake, IScene
     {
-        private readonly Dictionary<int, CoroutineLockQueueType> dictionary = new();
-        private readonly Queue<(int, long, int)> nextFrameRun = new Queue<(int, long, int)>();
-
-        public override void Dispose()
-        {
-            if (this.IsDisposed)
-            {
-                return;
-            }
-            base.Dispose();
-            
-            this.nextFrameRun.Clear();
-        }
+        public IScene Root { get; set; }
+        public SceneType SceneType { get; set; }
+        
+        private readonly Queue<(int, long, int)> nextFrameRun = new();
 
         public void Update()
         {
@@ -43,23 +34,17 @@ namespace ET
 
         public async ETTask<CoroutineLock> Wait(int coroutineLockType, long key, int time = 60000)
         {
-            CoroutineLockQueueType coroutineLockQueueType;
-            if (!this.dictionary.TryGetValue(coroutineLockType, out coroutineLockQueueType))
-            {
-                coroutineLockQueueType = new CoroutineLockQueueType(coroutineLockType);
-                this.dictionary.Add(coroutineLockType, coroutineLockQueueType);
-            }
+            CoroutineLockQueueType coroutineLockQueueType = this.GetChild<CoroutineLockQueueType>(coroutineLockType) ?? this.AddChildWithId<CoroutineLockQueueType>(coroutineLockType);
             return await coroutineLockQueueType.Wait(key, time);
         }
 
         private void Notify(int coroutineLockType, long key, int level)
         {
-            CoroutineLockQueueType coroutineLockQueueType;
-            if (!this.dictionary.TryGetValue(coroutineLockType, out coroutineLockQueueType))
+            CoroutineLockQueueType coroutineLockQueueType = this.GetChild<CoroutineLockQueueType>(coroutineLockType);
+            if (coroutineLockQueueType == null)
             {
                 return;
             }
-            
             coroutineLockQueueType.Notify(key, level);
         }
     }

+ 46 - 40
Unity/Assets/Scripts/Core/Fiber/Module/CoroutineLock/CoroutineLockQueue.cs

@@ -3,82 +3,88 @@ using System.Collections.Generic;
 
 namespace ET
 {
-    public class CoroutineLockQueue: IDisposable
+    public static partial class CoroutineLockQueueSystem
     {
-        private int type;
-        private long key;
-        
-        public static CoroutineLockQueue Create(int type, long key)
+        [EntitySystem]
+        private static void Awake(this CoroutineLockQueue self, int type)
         {
-            CoroutineLockQueue coroutineLockQueue = ObjectPool.Instance.Fetch<CoroutineLockQueue>();
-            coroutineLockQueue.type = type;
-            coroutineLockQueue.key = key;
-            return coroutineLockQueue;
+            self.type = type;
         }
-
-        private CoroutineLock currentCoroutineLock;
         
-        private readonly Queue<WaitCoroutineLock> queue = new Queue<WaitCoroutineLock>();
-
-        public int Count
+        [EntitySystem]
+        private static void Destroy(this CoroutineLockQueue self)
         {
-            get
-            {
-                return this.queue.Count;
-            }
+            self.queue.Clear();
+            self.type = 0;
+            self.CurrentCoroutineLock = null;
         }
-
-        public async ETTask<CoroutineLock> Wait(int time)
+        
+        public static async ETTask<CoroutineLock> Wait(this CoroutineLockQueue self, int time)
         {
-            if (this.currentCoroutineLock == null)
+            if (self.CurrentCoroutineLock == null)
             {
-                this.currentCoroutineLock = CoroutineLock.Create(type, key, 1);
-                return this.currentCoroutineLock;
+                self.CurrentCoroutineLock = self.AddChild<CoroutineLock, int, long, int>(self.type, self.Id, 1, true);
+                return self.CurrentCoroutineLock;
             }
 
             WaitCoroutineLock waitCoroutineLock = WaitCoroutineLock.Create();
-            this.queue.Enqueue(waitCoroutineLock);
+            self.queue.Enqueue(waitCoroutineLock);
             if (time > 0)
             {
                 long tillTime = TimeHelper.ClientFrameTime() + time;
-                TimerComponent.Instance.NewOnceTimer(tillTime, TimerCoreInvokeType.CoroutineTimeout, waitCoroutineLock);
+                self.Fiber().GetComponent<TimerComponent>().NewOnceTimer(tillTime, TimerCoreInvokeType.CoroutineTimeout, waitCoroutineLock);
             }
-            this.currentCoroutineLock = await waitCoroutineLock.Wait();
-            return this.currentCoroutineLock;
+            self.CurrentCoroutineLock = await waitCoroutineLock.Wait();
+            return self.CurrentCoroutineLock;
         }
 
-        public void Notify(int level)
+        public static void Notify(this CoroutineLockQueue self, int level)
         {
             // 有可能WaitCoroutineLock已经超时抛出异常,所以要找到一个未处理的WaitCoroutineLock
-            while (this.queue.Count > 0)
+            while (self.queue.Count > 0)
             {
-                WaitCoroutineLock waitCoroutineLock = queue.Dequeue();
+                WaitCoroutineLock waitCoroutineLock = self.queue.Dequeue();
 
                 if (waitCoroutineLock.IsDisposed())
                 {
                     continue;
                 }
 
-                CoroutineLock coroutineLock = CoroutineLock.Create(type, key, level);
+                CoroutineLock coroutineLock = self.AddChild<CoroutineLock, int, long, int>(self.type, self.Id, level, true);
 
                 waitCoroutineLock.SetResult(coroutineLock);
                 break;
             }
         }
+    }
+    
+    [ChildOf(typeof(CoroutineLockQueueType))]
+    public class CoroutineLockQueue: Entity, IAwake<int>
+    {
+        public int type;
 
-        public void Recycle()
+        private EntityRef<CoroutineLock> currentCoroutineLock;
+
+        public CoroutineLock CurrentCoroutineLock
         {
-            ObjectPool.Instance.Recycle(this);
+            get
+            {
+                return this.currentCoroutineLock;
+            }
+            set
+            {
+                this.currentCoroutineLock = value;
+            }
         }
+        
+        public Queue<WaitCoroutineLock> queue = new();
 
-        public void Dispose()
+        public int Count
         {
-            this.queue.Clear();
-            this.key = 0;
-            this.type = 0;
-            this.currentCoroutineLock = null;
-            
-            ObjectPool.Instance.Recycle(this);
+            get
+            {
+                return this.queue.Count;
+            }
         }
     }
 }

+ 21 - 24
Unity/Assets/Scripts/Core/Fiber/Module/CoroutineLock/CoroutineLockQueueType.cs

@@ -2,47 +2,39 @@
 
 namespace ET
 {
-    public class CoroutineLockQueueType
+    [FriendOf(typeof(CoroutineLockQueueType))]
+    public static partial class CoroutineLockQueueTypeSystem
     {
-        private readonly int type;
-        
-        private readonly Dictionary<long, CoroutineLockQueue> coroutineLockQueues = new Dictionary<long, CoroutineLockQueue>();
-
-        public CoroutineLockQueueType(int type)
+        [EntitySystem]
+        private static void Awake(this CoroutineLockQueueType self)
         {
-            this.type = type;
         }
-
-        private CoroutineLockQueue Get(long key)
+        
+        public static CoroutineLockQueue Get(this CoroutineLockQueueType self, long key)
         {
-            this.coroutineLockQueues.TryGetValue(key, out CoroutineLockQueue queue);
-            return queue;
+            return self.GetChild<CoroutineLockQueue>(key);
         }
 
-        private CoroutineLockQueue New(long key)
+        public static CoroutineLockQueue New(this CoroutineLockQueueType self, long key)
         {
-            CoroutineLockQueue queue = CoroutineLockQueue.Create(this.type, key);
-            this.coroutineLockQueues.Add(key, queue);
+            CoroutineLockQueue queue = self.AddChildWithId<CoroutineLockQueue, int>(key, (int)self.Id, true);
             return queue;
         }
 
-        private void Remove(long key)
+        public static void Remove(this CoroutineLockQueueType self, long key)
         {
-            if (this.coroutineLockQueues.Remove(key, out CoroutineLockQueue queue))
-            {
-                queue.Dispose();
-            }
+            self.RemoveChild(key);
         }
 
-        public async ETTask<CoroutineLock> Wait(long key, int time)
+        public static async ETTask<CoroutineLock> Wait(this CoroutineLockQueueType self, long key, int time)
         {
-            CoroutineLockQueue queue = this.Get(key) ?? this.New(key);
+            CoroutineLockQueue queue = self.Get(key) ?? self.New(key);
             return await queue.Wait(time);
         }
 
-        public void Notify(long key, int level)
+        public static void Notify(this CoroutineLockQueueType self, long key, int level)
         {
-            CoroutineLockQueue queue = this.Get(key);
+            CoroutineLockQueue queue = self.Get(key);
             if (queue == null)
             {
                 return;
@@ -50,10 +42,15 @@ namespace ET
             
             if (queue.Count == 0)
             {
-                this.Remove(key);
+                self.Remove(key);
             }
 
             queue.Notify(level);
         }
     }
+    
+    [ChildOf(typeof(CoroutineLockComponent))]
+    public class CoroutineLockQueueType: Entity, IAwake
+    {
+    }
 }

+ 1 - 1
Unity/Assets/Scripts/Core/Fiber/Module/Synchronization/MainThreadSynchronizationContext.cs

@@ -4,7 +4,7 @@ using System.Threading;
 namespace ET
 {
     [ComponentOf(typeof(Fiber))]
-    public class MainThreadSynchronizationContext: SingletonEntity<MainThreadSynchronizationContext>, IAwake
+    public class MainThreadSynchronizationContext: Entity, IAwake
     {
         private readonly ThreadSynchronizationContext threadSynchronizationContext = new();
 

+ 1 - 1
Unity/Assets/Scripts/Core/Fiber/Module/Timer/TimerComponent.cs

@@ -54,7 +54,7 @@ namespace ET
     }
 
     [ComponentOf(typeof(Fiber))]
-    public class TimerComponent: SingletonEntity<TimerComponent>, IAwake
+    public class TimerComponent: Entity, IAwake
     {
         /// <summary>
         /// key: time, value: timer id

+ 1 - 1
Unity/Assets/Scripts/Core/Helper/ETCancelationTokenHelper.cs

@@ -9,7 +9,7 @@ namespace ET
                 return;
             }
 
-            await TimerComponent.Instance.WaitAsync(afterTimeCancel);
+            await Fiber.Instance.GetComponent<TimerComponent>().WaitAsync(afterTimeCancel);
             
             if (self.IsCancel())
             {

+ 1 - 1
Unity/Assets/Scripts/Core/World/Module/Network/NetServices.cs

@@ -15,7 +15,7 @@ namespace ET
     }
 
     [ComponentOf(typeof(Fiber))]
-    public class NetServices: SingletonEntity<NetServices>, IAwake
+    public class NetServices: Entity, IAwake
     {
         private readonly Dictionary<int, Action<long, IPEndPoint>> acceptCallback = new();
         private readonly Dictionary<int, Action<long, ActorId, object>> readCallback = new();

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Client/Demo/AI/AI_Attack.cs

@@ -32,7 +32,7 @@ namespace ET.Client
                 Log.Debug($"攻击: {i}次");
 
                 // 因为协程可能被中断,任何协程都要传入cancellationToken,判断如果是中断则要返回
-                await TimerComponent.Instance.WaitAsync(1000, cancellationToken);
+                await aiComponent.Fiber().GetComponent<TimerComponent>().WaitAsync(1000, cancellationToken);
                 if (cancellationToken.IsCancel())
                 {
                     return;

+ 3 - 2
Unity/Assets/Scripts/Hotfix/Client/Demo/Ping/PingComponentSystem.cs

@@ -20,6 +20,7 @@ namespace ET.Client
         {
             Session session = self.GetParent<Session>();
             long instanceId = self.InstanceId;
+            Fiber fiber = self.Fiber();
             
             while (true)
             {
@@ -42,9 +43,9 @@ namespace ET.Client
                     long time2 = TimeHelper.ClientNow();
                     self.Ping = time2 - time1;
                     
-                    self.Fiber().TimeInfo.ServerMinusClientTime = response.Time + (time2 - time1) / 2 - time2;
+                    fiber.TimeInfo.ServerMinusClientTime = response.Time + (time2 - time1) / 2 - time2;
                     
-                    await TimerComponent.Instance.WaitAsync(2000);
+                    await fiber.GetComponent<TimerComponent>().WaitAsync(2000);
                 }
                 catch (RpcException e)
                 {

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Client/Demo/Router/RouterAddressComponentSystem.cs

@@ -40,7 +40,7 @@ namespace ET.Client
         // 等10分钟再获取一次
         public static async ETTask WaitTenMinGetAllRouter(this RouterAddressComponent self)
         {
-            await TimerComponent.Instance.WaitAsync(5 * 60 * 1000);
+            await self.Fiber().GetComponent<TimerComponent>().WaitAsync(5 * 60 * 1000);
             if (self.IsDisposed)
             {
                 return;

+ 2 - 1
Unity/Assets/Scripts/Hotfix/Client/Demo/Router/RouterCheckComponentSystem.cs

@@ -15,6 +15,7 @@ namespace ET.Client
         {
             Session session = self.GetParent<Session>();
             long instanceId = self.InstanceId;
+            Fiber fiber = self.Fiber();
             
             while (true)
             {
@@ -23,7 +24,7 @@ namespace ET.Client
                     return;
                 }
 
-                await TimerComponent.Instance.WaitAsync(1000);
+                await fiber.GetComponent<TimerComponent>().WaitAsync(1000);
                 
                 if (self.InstanceId != instanceId)
                 {

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Client/Demo/Router/RouterHelper.cs

@@ -78,7 +78,7 @@ namespace ET.Client
                     socket.SendTo(sendCache, 0, addressBytes.Length + 13, SocketFlags.None, routerAddress);
                 }
                     
-                await TimerComponent.Instance.WaitFrameAsync();
+                await Fiber.Instance.GetComponent<TimerComponent>().WaitFrameAsync();
                     
                 // 接收
                 if (socket.Available > 0)

+ 2 - 2
Unity/Assets/Scripts/Hotfix/Client/Demo/Scene/SceneFactory.cs

@@ -2,11 +2,11 @@ namespace ET.Client
 {
     public static partial class SceneFactory
     {
-        public static async ETTask<Scene> CreateClientScene(Fiber scene, int zone, SceneType sceneType, string name)
+        public static async ETTask<Scene> CreateClientScene(Fiber fiber, int zone, SceneType sceneType, string name)
         {
             await ETTask.CompletedTask;
             
-            Scene clientScene = EntitySceneFactory.CreateScene(zone, sceneType, name, scene.GetComponent<ClientSceneManagerComponent>());
+            Scene clientScene = EntitySceneFactory.CreateScene(zone, sceneType, name, fiber.GetComponent<ClientSceneManagerComponent>());
             clientScene.AddComponent<ObjectWait>();
             clientScene.AddComponent<PlayerComponent>();
             clientScene.AddComponent<CurrentScenesComponent>();

+ 15 - 8
Unity/Assets/Scripts/Hotfix/Client/Module/Message/NetClientComponentSystem.cs

@@ -10,15 +10,21 @@ namespace ET.Client
         [EntitySystem]
         private static void Awake(this NetClientComponent self, AddressFamily addressFamily)
         {
-            self.ServiceId = NetServices.Instance.AddService(new KService(addressFamily, ServiceType.Outer));
-            NetServices.Instance.RegisterReadCallback(self.ServiceId, self.OnRead);
-            NetServices.Instance.RegisterErrorCallback(self.ServiceId, self.OnError);
+            NetServices netServices = self.Fiber().GetComponent<NetServices>();
+            self.ServiceId = netServices.AddService(new KService(addressFamily, ServiceType.Outer));
+            netServices.RegisterReadCallback(self.ServiceId, self.OnRead);
+            netServices.RegisterErrorCallback(self.ServiceId, self.OnError);
         }
         
         [EntitySystem]
         private static void Destroy(this NetClientComponent self)
         {
-            NetServices.Instance.RemoveService(self.ServiceId);
+            if (self.Fiber().IsDisposed)
+            {
+                return;
+            }
+            NetServices netServices = self.Fiber().GetComponent<NetServices>();
+            netServices.RemoveService(self.ServiceId);
         }
 
         private static void OnRead(this NetClientComponent self, long channelId, ActorId actorId, object message)
@@ -50,20 +56,22 @@ namespace ET.Client
 
         public static Session Create(this NetClientComponent self, IPEndPoint realIPEndPoint)
         {
-            long channelId = NetServices.Instance.CreateConnectChannelId();
+            NetServices netServices = self.Fiber().GetComponent<NetServices>();
+            long channelId = netServices.CreateConnectChannelId();
             Session session = self.AddChildWithId<Session, int>(channelId, self.ServiceId);
             session.RemoteAddress = realIPEndPoint;
             if (self.IScene.SceneType != SceneType.Benchmark)
             {
                 session.AddComponent<SessionIdleCheckerComponent>();
             }
-            NetServices.Instance.CreateChannel(self.ServiceId, session.Id, realIPEndPoint);
+            netServices.CreateChannel(self.ServiceId, session.Id, realIPEndPoint);
 
             return session;
         }
         
         public static Session Create(this NetClientComponent self, IPEndPoint routerIPEndPoint, IPEndPoint realIPEndPoint, uint localConn)
         {
+            NetServices netServices = self.Fiber().GetComponent<NetServices>();
             long channelId = localConn;
             Session session = self.AddChildWithId<Session, int>(channelId, self.ServiceId);
             session.RemoteAddress = realIPEndPoint;
@@ -71,8 +79,7 @@ namespace ET.Client
             {
                 session.AddComponent<SessionIdleCheckerComponent>();
             }
-            NetServices.Instance.CreateChannel(self.ServiceId, session.Id, routerIPEndPoint);
-
+            netServices.CreateChannel(self.ServiceId, session.Id, routerIPEndPoint);
             return session;
         }
     }

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

@@ -5,29 +5,29 @@ namespace ET.Server
     [Event(SceneType.Process)]
     public class EntryEvent2_InitServer: AEvent<Fiber, ET.EventType.EntryEvent2>
     {
-        protected override async ETTask Run(Fiber scene, ET.EventType.EntryEvent2 args)
+        protected override async ETTask Run(Fiber fiber, ET.EventType.EntryEvent2 args)
         {
             // 发送普通actor消息
-            scene.AddComponent<ActorMessageSenderComponent>();
+            fiber.AddComponent<ActorMessageSenderComponent>();
             // 发送location actor消息
-            scene.AddComponent<ActorLocationSenderComponent>();
+            fiber.AddComponent<ActorLocationSenderComponent>();
             // 访问location server的组件
-            scene.AddComponent<LocationProxyComponent>();
-            scene.AddComponent<ServerSceneManagerComponent>();
-            scene.AddComponent<RobotCaseComponent>();
-            scene.AddComponent<NavmeshComponent>();
+            fiber.AddComponent<LocationProxyComponent>();
+            ServerSceneManagerComponent serverSceneManagerComponent = fiber.AddComponent<ServerSceneManagerComponent>();
+            fiber.AddComponent<RobotCaseComponent>();
+            fiber.AddComponent<NavmeshComponent>();
 
-            StartProcessConfig processConfig = StartProcessConfigCategory.Instance.Get(scene.Process);
+            StartProcessConfig processConfig = StartProcessConfigCategory.Instance.Get(fiber.Process);
             switch (Options.Instance.AppType)
             {
                 case AppType.Server:
                 {
-                    scene.AddComponent<NetInnerComponent, IPEndPoint>(processConfig.InnerIPPort);
+                    fiber.AddComponent<NetInnerComponent, IPEndPoint>(processConfig.InnerIPPort);
 
-                    var processScenes = StartSceneConfigCategory.Instance.GetByProcess(scene.Process);
+                    var processScenes = StartSceneConfigCategory.Instance.GetByProcess(fiber.Process);
                     foreach (StartSceneConfig startConfig in processScenes)
                     {
-                        await SceneFactory.CreateServerScene(ServerSceneManagerComponent.Instance, startConfig.Id, startConfig.ActorId.InstanceId, startConfig.Zone, startConfig.Name,
+                        await SceneFactory.CreateServerScene(serverSceneManagerComponent, startConfig.Id, startConfig.ActorId.InstanceId, startConfig.Zone, startConfig.Name,
                             startConfig.Type, startConfig);
                     }
 
@@ -36,9 +36,9 @@ namespace ET.Server
                 case AppType.Watcher:
                 {
                     StartMachineConfig startMachineConfig = WatcherHelper.GetThisMachineConfig();
-                    WatcherComponent watcherComponent = scene.AddComponent<WatcherComponent>();
+                    WatcherComponent watcherComponent = fiber.AddComponent<WatcherComponent>();
                     watcherComponent.Start(Options.Instance.CreateScenes);
-                    scene.AddComponent<NetInnerComponent, IPEndPoint>(NetworkHelper.ToIPEndPoint($"{startMachineConfig.InnerIP}:{startMachineConfig.WatcherPort}"));
+                    fiber.AddComponent<NetInnerComponent, IPEndPoint>(NetworkHelper.ToIPEndPoint($"{startMachineConfig.InnerIP}:{startMachineConfig.WatcherPort}"));
                     break;
                 }
                 case AppType.GameTool:
@@ -47,7 +47,7 @@ namespace ET.Server
 
             if (Options.Instance.Console == 1)
             {
-                scene.AddComponent<ConsoleComponent>();
+                fiber.AddComponent<ConsoleComponent>();
             }
         }
     }

+ 4 - 12
Unity/Assets/Scripts/Hotfix/Server/Demo/Helper/MessageHelper.cs

@@ -25,7 +25,7 @@ namespace ET.Server
         {
             Dictionary<long, AOIEntity> dict = unit.GetBeSeePlayers();
             // 网络底层做了优化,同一个消息不会多次序列化
-            ActorLocationSenderOneType oneTypeLocationType = ActorLocationSenderComponent.Instance.Get(LocationType.GateSession);
+            ActorLocationSenderOneType oneTypeLocationType = unit.Fiber().GetComponent<ActorLocationSenderComponent>().Get(LocationType.GateSession);
             foreach (AOIEntity u in dict.Values)
             {
                 oneTypeLocationType.Send(u.Unit.Id, message);
@@ -34,23 +34,15 @@ namespace ET.Server
         
         public static void SendToClient(Unit unit, IActorMessage message)
         {
-            ActorLocationSenderComponent.Instance.Get(LocationType.GateSession).Send(unit.Id, message);
-        }
-        
-        
-        public static void SendToLocationActor(int locationType, long id, IActorLocationMessage message)
-        {
-            ActorLocationSenderComponent.Instance.Get(locationType).Send(id, message);
+            unit.Fiber().GetComponent<ActorLocationSenderComponent>().Get(LocationType.GateSession).Send(unit.Id, message);
         }
         
         /// <summary>
         /// 发送协议给Actor
         /// </summary>
-        /// <param name="actorId">注册Actor的InstanceId</param>
-        /// <param name="message"></param>
-        public static void SendActor(ActorId actorId, IActorMessage message)
+        public static void SendActor(Fiber fiber, ActorId actorId, IActorMessage message)
         {
-            ActorMessageSenderComponent.Instance.Send(actorId, message);
+            fiber.GetComponent<ActorMessageSenderComponent>().Send(actorId, message);
         }
     }
 }

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Benchmark/BenchmarkClientComponentSystem.cs

@@ -17,7 +17,7 @@ namespace ET.Server
 
         private static async ETTask Start(this BenchmarkClientComponent self)
         {
-            await TimerComponent.Instance.WaitAsync(1000);
+            await self.Fiber().GetComponent<TimerComponent>().WaitAsync(1000);
 
             Scene scene = await SceneFactory.CreateServerScene(self, Fiber.Instance.IdGenerater.GenerateId(), Fiber.Instance.IdGenerater.GenerateInstanceId(),
                 self.DomainZone(), "bechmark", SceneType.Benchmark);

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

@@ -9,7 +9,7 @@
 
 			// 在Gate上动态创建一个Map Scene,把Unit从DB中加载放进来,然后传送到真正的Map中,这样登陆跟传送的逻辑就完全一样了
 			GateMapComponent gateMapComponent = player.AddComponent<GateMapComponent>();
-			gateMapComponent.Scene = await SceneFactory.CreateServerScene(gateMapComponent, player.Id, Fiber.Instance.IdGenerater.GenerateInstanceId(), gateMapComponent.DomainZone(), "GateMap", SceneType.Map);
+			gateMapComponent.Scene = await SceneFactory.CreateServerScene(gateMapComponent, player.Id, session.Fiber().IdGenerater.GenerateInstanceId(), gateMapComponent.DomainZone(), "GateMap", SceneType.Map);
 
 			Scene scene = gateMapComponent.Scene;
 			

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

@@ -58,7 +58,7 @@ namespace ET.Server
         {
             await player.Fiber().WaitFrameFinish();
             
-            Room2G_Reconnect room2GateReconnect = await ActorMessageSenderComponent.Instance.Call(
+            Room2G_Reconnect room2GateReconnect = await player.Fiber().GetComponent<ActorMessageSenderComponent>().Call(
                 player.GetComponent<PlayerRoomComponent>().RoomActorId,
                 new G2Room_Reconnect() { PlayerId = player.Id }) as Room2G_Reconnect;
             session.Send(new G2C_Reconnect() { StartTime = room2GateReconnect.StartTime, UnitInfos = room2GateReconnect.UnitInfos, Frame = room2GateReconnect.Frame});

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

@@ -23,7 +23,7 @@
 
         private static async ETTask TimeoutRemoveKey(this GateSessionKeyComponent self, long key)
         {
-            await TimerComponent.Instance.WaitAsync(20000);
+            await self.Fiber().GetComponent<TimerComponent>().WaitAsync(20000);
             self.sessionKey.Remove(key);
         }
     }

+ 2 - 2
Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Gate/SessionPlayerComponentSystem.cs

@@ -5,12 +5,12 @@
         [EntitySystem]
         private static void Destroy(this SessionPlayerComponent self)
         {
-            if (ActorLocationSenderComponent.Instance.IsDisposed)
+            if (self.Fiber().IsDisposed)
             {
                 return;
             }
             // 发送断线消息
-            ActorLocationSenderComponent.Instance.Get(LocationType.Unit).Send(self.Player.Id, new G2M_SessionDisconnect());
+            self.Fiber().GetComponent<ActorLocationSenderComponent>().Get(LocationType.Unit).Send(self.Player.Id, new G2M_SessionDisconnect());
         }
     }
 }

+ 3 - 3
Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Map/Transfer/M2M_UnitTransferRequestHandler.cs

@@ -27,11 +27,11 @@ namespace ET.Server
             unit.AddComponent<MailBoxComponent, MailboxType>(MailboxType.OrderedMessage);
 
             // 通知客户端开始切场景
-            M2C_StartSceneChange m2CStartSceneChange = new M2C_StartSceneChange() { SceneInstanceId = scene.InstanceId, SceneName = scene.Name };
+            M2C_StartSceneChange m2CStartSceneChange = new() { SceneInstanceId = scene.InstanceId, SceneName = scene.Name };
             MessageHelper.SendToClient(unit, m2CStartSceneChange);
 
             // 通知客户端创建My Unit
-            M2C_CreateMyUnit m2CCreateUnits = new M2C_CreateMyUnit();
+            M2C_CreateMyUnit m2CCreateUnits = new();
             m2CCreateUnits.Unit = UnitHelper.CreateUnitInfo(unit);
             MessageHelper.SendToClient(unit, m2CCreateUnits);
 
@@ -39,7 +39,7 @@ namespace ET.Server
             unit.AddComponent<AOIEntity, int, float3>(9 * 1000, unit.Position);
 
             // 解锁location,可以接收发给Unit的消息
-            await LocationProxyComponent.Instance.UnLock(LocationType.Unit, unit.Id, request.OldActorId, unit.GetActorId());
+            await scene.Fiber().GetComponent<LocationProxyComponent>().UnLock(LocationType.Unit, unit.Id, request.OldActorId, unit.GetActorId());
         }
     }
 }

+ 4 - 2
Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Map/Transfer/TransferHelper.cs

@@ -15,6 +15,8 @@ namespace ET.Server
 
         public static async ETTask Transfer(Unit unit, ActorId sceneInstanceId, string sceneName)
         {
+            Fiber fiber = unit.Fiber();
+            
             // location加锁
             long unitId = unit.Id;
             
@@ -30,8 +32,8 @@ namespace ET.Server
             }
             unit.Dispose();
             
-            await LocationProxyComponent.Instance.Lock(LocationType.Unit, unitId, request.OldActorId);
-            await ActorMessageSenderComponent.Instance.Call(sceneInstanceId, request);
+            await fiber.GetComponent<LocationProxyComponent>().Lock(LocationType.Unit, unitId, request.OldActorId);
+            await fiber.GetComponent<ActorMessageSenderComponent>().Call(sceneInstanceId, request);
         }
     }
 }

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Realm/C2R_LoginHandler.cs

@@ -14,7 +14,7 @@ namespace ET.Server
 			Log.Debug($"gate address: {MongoHelper.ToJson(config)}");
 			
 			// 向gate请求一个key,客户端可以拿着这个key连接gate
-			G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey) await ActorMessageSenderComponent.Instance.Call(
+			G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey) await session.Fiber().GetComponent<ActorMessageSenderComponent>().Call(
 				config.ActorId, new R2G_GetLoginKey() {Account = request.Account});
 
 			response.Address = config.InnerIPOutPort.ToString();

+ 4 - 3
Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Robot/Console/CreateRobotConsoleHandler.cs

@@ -7,7 +7,7 @@ namespace ET.Server
     [ConsoleHandler(ConsoleMode.CreateRobot)]
     public class CreateRobotConsoleHandler: IConsoleHandler
     {
-        public async ETTask Run(ModeContex contex, string content)
+        public async ETTask Run(Fiber fiber, ModeContex contex, string content)
         {
             switch (content)
             {
@@ -34,16 +34,17 @@ namespace ET.Server
                         }
                         
                         // 创建机器人
+                        TimerComponent timerComponent = fiber.GetComponent<TimerComponent>();
                         for (int i = 0; i < options.Num; ++i)
                         {
                             int index = i % thisProcessRobotScenes.Count;
                             StartSceneConfig robotSceneConfig = thisProcessRobotScenes[index];
-                            Scene robotScene = ServerSceneManagerComponent.Instance.Get(robotSceneConfig.Id);
+                            Scene robotScene = fiber.GetComponent<ServerSceneManagerComponent>().Get(robotSceneConfig.Id);
                             RobotManagerComponent robotManagerComponent = robotScene.GetComponent<RobotManagerComponent>();
                             Scene robot = await robotManagerComponent.NewRobot(Options.Instance.Process * 10000 + i);
                             robot.AddComponent<AIComponent, int>(1);
                             Log.Console($"create robot {robot.Zone}");
-                            await TimerComponent.Instance.WaitAsync(2000);
+                            await timerComponent.WaitAsync(2000);
                         }
                     }
                     break;

+ 3 - 3
Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Robot/RobotConsoleHandler.cs

@@ -6,7 +6,7 @@ namespace ET.Server
     [ConsoleHandler(ConsoleMode.Robot)]
     public class RobotConsoleHandler: IConsoleHandler
     {
-        public async ETTask Run(ModeContex contex, string content)
+        public async ETTask Run(Fiber fiber, ModeContex contex, string content)
         {
             string[] ss = content.Split(" ");
             switch (ss[0])
@@ -21,7 +21,7 @@ namespace ET.Server
                     try
                     {
                         RobotLog.Debug($"run case start: {caseType}");
-                        await EventSystem.Instance.Invoke<RobotInvokeArgs, ETTask>(caseType, new RobotInvokeArgs() { Content = content });
+                        await EventSystem.Instance.Invoke<RobotInvokeArgs, ETTask>(caseType, new RobotInvokeArgs() { Fiber = fiber, Content = content });
                         RobotLog.Debug($"run case finish: {caseType}");
                     }
                     catch (Exception e)
@@ -44,7 +44,7 @@ namespace ET.Server
                         try
                         {
                             RobotLog.Debug($"run case start: {caseType}");
-                            await EventSystem.Instance.Invoke<RobotInvokeArgs, ETTask>(caseType, new RobotInvokeArgs() { Content = content});
+                            await EventSystem.Instance.Invoke<RobotInvokeArgs, ETTask>(caseType, new RobotInvokeArgs() { Fiber = fiber, Content = content});
                             RobotLog.Debug($"---------run case finish: {caseType}");
                         }
                         catch (Exception e)

+ 5 - 4
Unity/Assets/Scripts/Hotfix/Server/Demo/Session/NetServerComponentOnReadEvent.cs

@@ -7,6 +7,7 @@
         {
             Session session = args.Session;
             object message = args.Message;
+            Fiber fiber = scene.Fiber();
 
             if (message is IResponse response)
             {
@@ -22,7 +23,7 @@
                     Player player = session.GetComponent<SessionPlayerComponent>().Player;
                     ActorId roomActorId = player.GetComponent<PlayerRoomComponent>().RoomActorId;
                     frameMessage.PlayerId = player.Id;
-                    ActorMessageSenderComponent.Instance.Send(roomActorId, frameMessage);
+                    fiber.GetComponent<ActorMessageSenderComponent>().Send(roomActorId, frameMessage);
                     break;
                 }
                 case IActorRoom actorRoom:
@@ -30,13 +31,13 @@
                     Player player = session.GetComponent<SessionPlayerComponent>().Player;
                     ActorId roomActorId = player.GetComponent<PlayerRoomComponent>().RoomActorId;
                     actorRoom.PlayerId = player.Id;
-                    ActorMessageSenderComponent.Instance.Send(roomActorId, actorRoom);
+                    fiber.GetComponent<ActorMessageSenderComponent>().Send(roomActorId, actorRoom);
                     break;
                 }
                 case IActorLocationMessage actorLocationMessage:
                 {
                     long unitId = session.GetComponent<SessionPlayerComponent>().Player.Id;
-                    ActorLocationSenderComponent.Instance.Get(LocationType.Unit).Send(unitId, actorLocationMessage);
+                    fiber.GetComponent<ActorLocationSenderComponent>().Get(LocationType.Unit).Send(unitId, actorLocationMessage);
                     break;
                 }
                 case IActorLocationRequest actorLocationRequest: // gate session收到actor rpc消息,先向actor 发送rpc请求,再将请求结果返回客户端
@@ -44,7 +45,7 @@
                     long unitId = session.GetComponent<SessionPlayerComponent>().Player.Id;
                     int rpcId = actorLocationRequest.RpcId; // 这里要保存客户端的rpcId
                     long instanceId = session.InstanceId;
-                    IResponse iResponse = await ActorLocationSenderComponent.Instance.Get(LocationType.Unit).Call(unitId, actorLocationRequest);
+                    IResponse iResponse = await fiber.GetComponent<ActorLocationSenderComponent>().Get(LocationType.Unit).Call(unitId, actorLocationRequest);
                     iResponse.RpcId = rpcId;
                     // session可能已经断开了,所以这里需要判断
                     if (session.InstanceId == instanceId)

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/LockStep/Gate/C2G_MatchHandler.cs

@@ -9,7 +9,7 @@
 
 			StartSceneConfig startSceneConfig = StartSceneConfigCategory.Instance.Match;
 
-			await ActorMessageSenderComponent.Instance.Call(startSceneConfig.ActorId,
+			await session.Fiber().GetComponent<ActorMessageSenderComponent>().Call(startSceneConfig.ActorId,
 				new G2Match_Match() { Id = player.Id });
 		}
 	}

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/LockStep/Map/C2Room_ChangeSceneFinishHandler.cs

@@ -18,7 +18,7 @@ namespace ET.Server
                 return;
             }
             
-            await TimerComponent.Instance.WaitAsync(1000);
+            await room.Fiber().GetComponent<TimerComponent>().WaitAsync(1000);
 
             Room2C_Start room2CStart = new() { StartTime = TimeHelper.ServerFrameTime() };
             foreach (RoomPlayer rp in roomServerComponent.Children.Values)

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/LockStep/Map/FrameMessageHandler.cs

@@ -15,7 +15,7 @@ namespace ET.Server
                 long nowFrameTime = room.FixedTimeCounter.FrameTime(message.Frame);
                 int diffTime = (int)(nowFrameTime - TimeHelper.ServerFrameTime());
 
-                ActorLocationSenderComponent.Instance.Get(LocationType.GateSession).Send(message.PlayerId, new Room2C_AdjustUpdateTime() {DiffTime = diffTime});
+                room.Fiber().GetComponent<ActorLocationSenderComponent>().Get(LocationType.GateSession).Send(message.PlayerId, new Room2C_AdjustUpdateTime() {DiffTime = diffTime});
             }
 
             if (message.Frame < room.AuthorityFrame)  // 小于AuthorityFrame,丢弃

+ 3 - 2
Unity/Assets/Scripts/Hotfix/Server/LockStep/Map/RoomMessageHelper.cs

@@ -6,7 +6,8 @@ namespace ET.Server
         public static void BroadCast(Room room, IActorMessage message)
         {
             RoomServerComponent roomServerComponent = room.GetComponent<RoomServerComponent>();
-            
+
+            ActorLocationSenderComponent actorLocationSenderComponent = room.Fiber().GetComponent<ActorLocationSenderComponent>();
             foreach (var kv in roomServerComponent.Children)
             {
                 RoomPlayer roomPlayer = kv.Value as RoomPlayer;
@@ -16,7 +17,7 @@ namespace ET.Server
                     continue;
                 }
                 
-                ActorLocationSenderComponent.Instance.Get(LocationType.GateSession).Send(roomPlayer.Id, message);
+                actorLocationSenderComponent.Get(LocationType.GateSession).Send(roomPlayer.Id, message);
             }
         }
     }

+ 3 - 2
Unity/Assets/Scripts/Hotfix/Server/LockStep/Match/MatchComponentSystem.cs

@@ -30,13 +30,14 @@ namespace ET.Server
             }
             self.waitMatchPlayers.Clear();
             
-            Map2Match_GetRoom map2MatchGetRoom = await ActorMessageSenderComponent.Instance.Call(
+            Map2Match_GetRoom map2MatchGetRoom = await self.Fiber().GetComponent<ActorMessageSenderComponent>().Call(
                 startSceneConfig.ActorId, match2MapGetRoom) as Map2Match_GetRoom;
 
             Match2G_NotifyMatchSuccess match2GNotifyMatchSuccess = new() { ActorId = map2MatchGetRoom.ActorId };
+            ActorLocationSenderComponent actorLocationSenderComponent = self.Fiber().GetComponent<ActorLocationSenderComponent>();
             foreach (long id in match2MapGetRoom.PlayerIds) // 这里发送消息线程不会修改PlayerInfo,所以可以直接使用
             {
-                ActorLocationSenderComponent.Instance.Get(LocationType.Player).Send(id, match2GNotifyMatchSuccess);
+                actorLocationSenderComponent.Get(LocationType.Player).Send(id, match2GNotifyMatchSuccess);
                 // 等待进入房间的确认消息,如果超时要通知所有玩家退出房间,重新匹配
             }
         }

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/LockStep/Room/C2Room_CheckHashHandler.cs

@@ -10,7 +10,7 @@ namespace ET.Server
             {
                 byte[] bytes = room.FrameBuffer.Snapshot(message.Frame).ToArray();
                 Room2C_CheckHashFail room2CCheckHashFail = new() { Frame = message.Frame, LSWorldBytes = bytes };
-                ActorLocationSenderComponent.Instance.Get(LocationType.GateSession).Send(message.PlayerId, room2CCheckHashFail);
+                room.Fiber().GetComponent<ActorLocationSenderComponent>().Get(LocationType.GateSession).Send(message.PlayerId, room2CCheckHashFail);
             }
             await ETTask.CompletedTask;
         }

+ 19 - 15
Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/ActorLocationSenderComponentSystem.cs

@@ -30,13 +30,17 @@ namespace ET.Server
             self.LocationType = locationType;
             // 每10s扫描一次过期的actorproxy进行回收,过期时间是2分钟
             // 可能由于bug或者进程挂掉,导致ActorLocationSender发送的消息没有确认,结果无法自动删除,每一分钟清理一次这种ActorLocationSender
-            self.CheckTimer = TimerComponent.Instance.NewRepeatedTimer(10 * 1000, TimerInvokeType.ActorLocationSenderChecker, self);
+            self.CheckTimer = self.Fiber().GetComponent<TimerComponent>().NewRepeatedTimer(10 * 1000, TimerInvokeType.ActorLocationSenderChecker, self);
         }
         
         [EntitySystem]
         private static void Destroy(this ActorLocationSenderOneType self)
         {
-            TimerComponent.Instance?.Remove(ref self.CheckTimer);
+            if (self.Fiber().InstanceId == 0)
+            {
+                return;
+            }
+            self.Fiber().GetComponent<TimerComponent>().Remove(ref self.CheckTimer);
         }
 
         private static void Check(this ActorLocationSenderOneType self)
@@ -101,14 +105,14 @@ namespace ET.Server
             if (actorLocationSender.ActorId != default)
             {
                 actorLocationSender.LastSendOrRecvTime = TimeHelper.ServerNow();
-                ActorMessageSenderComponent.Instance.Send(actorLocationSender.ActorId, message);
+                self.Fiber().GetComponent<ActorMessageSenderComponent>().Send(actorLocationSender.ActorId, message);
                 return;
             }
             
             long instanceId = actorLocationSender.InstanceId;
             
             int coroutineLockType = (self.LocationType << 16) | CoroutineLockType.ActorLocationSender;
-            using (await CoroutineLockComponent.Instance.Wait(coroutineLockType, entityId))
+            using (await self.Fiber().GetComponent<CoroutineLockComponent>().Wait(coroutineLockType, entityId))
             {
                 if (actorLocationSender.InstanceId != instanceId)
                 {
@@ -117,7 +121,7 @@ namespace ET.Server
                 
                 if (actorLocationSender.ActorId == default)
                 {
-                    actorLocationSender.ActorId = await LocationProxyComponent.Instance.Get(self.LocationType, actorLocationSender.Id);
+                    actorLocationSender.ActorId = await self.Fiber().GetComponent<LocationProxyComponent>().Get(self.LocationType, actorLocationSender.Id);
                     if (actorLocationSender.InstanceId != instanceId)
                     {
                         throw new RpcException(ErrorCore.ERR_ActorLocationSenderTimeout2, $"{message}");
@@ -125,7 +129,7 @@ namespace ET.Server
                 }
                 
                 actorLocationSender.LastSendOrRecvTime = TimeHelper.ServerNow();
-                ActorMessageSenderComponent.Instance.Send(actorLocationSender.ActorId, message);
+                self.Fiber().GetComponent<ActorMessageSenderComponent>().Send(actorLocationSender.ActorId, message);
             }
         }
 
@@ -138,13 +142,13 @@ namespace ET.Server
             if (actorLocationSender.ActorId != default)
             {
                 actorLocationSender.LastSendOrRecvTime = TimeHelper.ServerNow();
-                return await ActorMessageSenderComponent.Instance.Call(actorLocationSender.ActorId, request);
+                return await self.Fiber().GetComponent<ActorMessageSenderComponent>().Call(actorLocationSender.ActorId, request);
             }
             
             long instanceId = actorLocationSender.InstanceId;
             
             int coroutineLockType = (self.LocationType << 16) | CoroutineLockType.ActorLocationSender;
-            using (await CoroutineLockComponent.Instance.Wait(coroutineLockType, entityId))
+            using (await self.Fiber().GetComponent<CoroutineLockComponent>().Wait(coroutineLockType, entityId))
             {
                 if (actorLocationSender.InstanceId != instanceId)
                 {
@@ -153,7 +157,7 @@ namespace ET.Server
 
                 if (actorLocationSender.ActorId == default)
                 {
-                    actorLocationSender.ActorId = await LocationProxyComponent.Instance.Get(self.LocationType, actorLocationSender.Id);
+                    actorLocationSender.ActorId = await self.Fiber().GetComponent<LocationProxyComponent>().Get(self.LocationType, actorLocationSender.Id);
                     if (actorLocationSender.InstanceId != instanceId)
                     {
                         throw new RpcException(ErrorCore.ERR_ActorLocationSenderTimeout2, $"{request}");
@@ -162,7 +166,7 @@ namespace ET.Server
             }
 
             actorLocationSender.LastSendOrRecvTime = TimeHelper.ServerNow();
-            return await ActorMessageSenderComponent.Instance.Call(actorLocationSender.ActorId, request);
+            return await self.Fiber().GetComponent<ActorMessageSenderComponent>().Call(actorLocationSender.ActorId, request);
         }
 
         public static void Send(this ActorLocationSenderOneType self, long entityId, IActorLocationMessage message)
@@ -175,12 +179,12 @@ namespace ET.Server
             ActorLocationSender actorLocationSender = self.GetOrCreate(entityId);
 
             // 先序列化好
-            int rpcId = ActorMessageSenderComponent.Instance.GetRpcId();
+            int rpcId = self.Fiber().GetComponent<ActorMessageSenderComponent>().GetRpcId();
             iActorRequest.RpcId = rpcId;
             
             long actorLocationSenderInstanceId = actorLocationSender.InstanceId;
             int coroutineLockType = (self.LocationType << 16) | CoroutineLockType.ActorLocationSender;
-            using (await CoroutineLockComponent.Instance.Wait(coroutineLockType, entityId))
+            using (await self.Fiber().GetComponent<CoroutineLockComponent>().Wait(coroutineLockType, entityId))
             {
                 if (actorLocationSender.InstanceId != actorLocationSenderInstanceId)
                 {
@@ -220,7 +224,7 @@ namespace ET.Server
             {
                 if (actorLocationSender.ActorId == default)
                 {
-                    actorLocationSender.ActorId = await LocationProxyComponent.Instance.Get(self.LocationType, actorLocationSender.Id);
+                    actorLocationSender.ActorId = await self.Fiber().GetComponent<LocationProxyComponent>().Get(self.LocationType, actorLocationSender.Id);
                     if (actorLocationSender.InstanceId != instanceId)
                     {
                         throw new RpcException(ErrorCore.ERR_ActorLocationSenderTimeout2, $"{iActorRequest}");
@@ -232,7 +236,7 @@ namespace ET.Server
                     actorLocationSender.Error = ErrorCore.ERR_NotFoundActor;
                     return ActorHelper.CreateResponse(iActorRequest, ErrorCore.ERR_NotFoundActor);
                 }
-                IActorResponse response = await ActorMessageSenderComponent.Instance.Call(actorLocationSender.ActorId, rpcId, iActorRequest, false);
+                IActorResponse response = await self.Fiber().GetComponent<ActorMessageSenderComponent>().Call(actorLocationSender.ActorId, rpcId, iActorRequest, false);
                 if (actorLocationSender.InstanceId != instanceId)
                 {
                     throw new RpcException(ErrorCore.ERR_ActorLocationSenderTimeout3, $"{iActorRequest}");
@@ -253,7 +257,7 @@ namespace ET.Server
                         }
 
                         // 等待0.5s再发送
-                        await TimerComponent.Instance.WaitAsync(500);
+                        await self.Fiber().GetComponent<TimerComponent>().WaitAsync(500);
                         if (actorLocationSender.InstanceId != instanceId)
                         {
                             throw new RpcException(ErrorCore.ERR_ActorLocationSenderTimeout4, $"{iActorRequest}");

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

@@ -22,7 +22,7 @@ namespace ET.Server
             }
             
             ActorResponse response = new() {RpcId = message.RpcId};
-            ActorMessageSenderComponent.Instance.Reply(actorId, response);
+            entity.Fiber().GetComponent<ActorMessageSenderComponent>().Reply(actorId, response);
 
             await this.Run(e, message);
         }
@@ -75,7 +75,7 @@ namespace ET.Server
                     response.Message = exception.ToString();
                 }
                 response.RpcId = rpcId;
-                ActorMessageSenderComponent.Instance.Reply(actorId, response);
+                entity.Fiber().GetComponent<ActorMessageSenderComponent>().Reply(actorId, response);
             }
             catch (Exception e)
             {

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

@@ -35,7 +35,7 @@ namespace ET.Server
         public static async ETTask Add(this LocationOneType self, long key, ActorId instanceId)
         {
             int coroutineLockType = (self.LocationType << 16) | CoroutineLockType.Location;
-            using (await CoroutineLockComponent.Instance.Wait(coroutineLockType, key))
+            using (await self.Fiber().GetComponent<CoroutineLockComponent>().Wait(coroutineLockType, key))
             {
                 self.locations[key] = instanceId;
                 Log.Info($"location add key: {key} instanceId: {instanceId}");
@@ -45,7 +45,7 @@ namespace ET.Server
         public static async ETTask Remove(this LocationOneType self, long key)
         {
             int coroutineLockType = (self.LocationType << 16) | CoroutineLockType.Location;
-            using (await CoroutineLockComponent.Instance.Wait(coroutineLockType, key))
+            using (await self.Fiber().GetComponent<CoroutineLockComponent>().Wait(coroutineLockType, key))
             {
                 self.locations.Remove(key);
                 Log.Info($"location remove key: {key}");
@@ -55,7 +55,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;
-            CoroutineLock coroutineLock = await CoroutineLockComponent.Instance.Wait(coroutineLockType, key);
+            CoroutineLock coroutineLock = await self.Fiber().GetComponent<CoroutineLockComponent>().Wait(coroutineLockType, key);
 
             LockInfo lockInfo = self.AddChild<LockInfo, ActorId, CoroutineLock>(actorId, coroutineLock);
             self.lockInfos.Add(key, lockInfo);
@@ -67,7 +67,7 @@ namespace ET.Server
                 async ETTask TimeWaitAsync()
                 {
                     long lockInfoInstanceId = lockInfo.InstanceId;
-                    await TimerComponent.Instance.WaitAsync(time);
+                    await self.Fiber().GetComponent<TimerComponent>().WaitAsync(time);
                     if (lockInfo.InstanceId != lockInfoInstanceId)
                     {
                         return;
@@ -106,7 +106,7 @@ namespace ET.Server
         public static async ETTask<ActorId> Get(this LocationOneType self, long key)
         {
             int coroutineLockType = (self.LocationType << 16) | CoroutineLockType.Location;
-            using (await CoroutineLockComponent.Instance.Wait(coroutineLockType, key))
+            using (await self.Fiber().GetComponent<CoroutineLockComponent>().Wait(coroutineLockType, key))
             {
                 self.locations.TryGetValue(key, out ActorId actorId);
                 Log.Info($"location get key: {key} actorId: {actorId}");

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

@@ -12,28 +12,28 @@ namespace ET.Server
         public static async ETTask Add(this LocationProxyComponent self, int type, long key, ActorId actorId)
         {
             Log.Info($"location proxy add {key}, {actorId} {TimeHelper.ServerNow()}");
-            await ActorMessageSenderComponent.Instance.Call(GetLocationSceneId(key),
+            await self.Fiber().GetComponent<ActorMessageSenderComponent>().Call(GetLocationSceneId(key),
                 new ObjectAddRequest() { Type = type, Key = key, ActorId = actorId });
         }
 
         public static async ETTask Lock(this LocationProxyComponent self, int type, long key, ActorId actorId, int time = 60000)
         {
             Log.Info($"location proxy lock {key}, {actorId} {TimeHelper.ServerNow()}");
-            await ActorMessageSenderComponent.Instance.Call(GetLocationSceneId(key),
+            await self.Fiber().GetComponent<ActorMessageSenderComponent>().Call(GetLocationSceneId(key),
                 new ObjectLockRequest() { Type = type, Key = key, ActorId = actorId, Time = time });
         }
 
         public static async ETTask UnLock(this LocationProxyComponent self, int type, long key, ActorId oldActorId, ActorId newActorId)
         {
             Log.Info($"location proxy unlock {key}, {newActorId} {TimeHelper.ServerNow()}");
-            await ActorMessageSenderComponent.Instance.Call(GetLocationSceneId(key),
+            await self.Fiber().GetComponent<ActorMessageSenderComponent>().Call(GetLocationSceneId(key),
                 new ObjectUnLockRequest() { Type = type, Key = key, OldActorId = oldActorId, NewActorId = newActorId });
         }
 
         public static async ETTask Remove(this LocationProxyComponent self, int type, long key)
         {
             Log.Info($"location proxy add {key}, {TimeHelper.ServerNow()}");
-            await ActorMessageSenderComponent.Instance.Call(GetLocationSceneId(key),
+            await self.Fiber().GetComponent<ActorMessageSenderComponent>().Call(GetLocationSceneId(key),
                 new ObjectRemoveRequest() { Type = type, Key = key });
         }
 
@@ -46,19 +46,19 @@ namespace ET.Server
 
             // location server配置到共享区,一个大战区可以配置N多个location server,这里暂时为1
             ObjectGetResponse response =
-                    (ObjectGetResponse) await ActorMessageSenderComponent.Instance.Call(GetLocationSceneId(key),
+                    (ObjectGetResponse) await self.Fiber().GetComponent<ActorMessageSenderComponent>().Call(GetLocationSceneId(key),
                         new ObjectGetRequest() { Type = type, Key = key });
             return response.ActorId;
         }
 
         public static async ETTask AddLocation(this Entity self, int type)
         {
-            await LocationProxyComponent.Instance.Add(type, self.Id, self.GetActorId());
+            await self.Fiber().GetComponent<LocationProxyComponent>().Add(type, self.Id, self.GetActorId());
         }
 
         public static async ETTask RemoveLocation(this Entity self, int type)
         {
-            await LocationProxyComponent.Instance.Remove(type, self.Id);
+            await self.Fiber().GetComponent<LocationProxyComponent>().Remove(type, self.Id);
         }
     }
 }

+ 14 - 14
Unity/Assets/Scripts/Hotfix/Server/Module/DB/DBComponentSystem.cs

@@ -29,7 +29,7 @@ namespace ET.Server
 
 	    public static async ETTask<T> Query<T>(this DBComponent self, long id, string collection = null) where T : Entity
 	    {
-		    using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.DB, id % DBComponent.TaskCount))
+		    using (await self.Fiber().GetComponent<CoroutineLockComponent>().Wait(CoroutineLockType.DB, id % DBComponent.TaskCount))
 		    {
 			    IAsyncCursor<T> cursor = await self.GetCollection<T>(collection).FindAsync(d => d.Id == id);
 
@@ -40,7 +40,7 @@ namespace ET.Server
 	    public static async ETTask<List<T>> Query<T>(this DBComponent self, Expression<Func<T, bool>> filter, string collection = null)
 			    where T : Entity
 	    {
-		    using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.DB, RandomGenerator.RandInt64() % DBComponent.TaskCount))
+		    using (await self.Fiber().GetComponent<CoroutineLockComponent>().Wait(CoroutineLockType.DB, RandomGenerator.RandInt64() % DBComponent.TaskCount))
 		    {
 			    IAsyncCursor<T> cursor = await self.GetCollection<T>(collection).FindAsync(filter);
 
@@ -51,7 +51,7 @@ namespace ET.Server
 	    public static async ETTask<List<T>> Query<T>(this DBComponent self, long taskId, Expression<Func<T, bool>> filter, string collection = null)
 			    where T : Entity
 	    {
-		    using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.DB, taskId % DBComponent.TaskCount))
+		    using (await self.Fiber().GetComponent<CoroutineLockComponent>().Wait(CoroutineLockType.DB, taskId % DBComponent.TaskCount))
 		    {
 			    IAsyncCursor<T> cursor = await self.GetCollection<T>(collection).FindAsync(filter);
 
@@ -66,7 +66,7 @@ namespace ET.Server
 			    return;
 		    }
 
-		    using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.DB, id % DBComponent.TaskCount))
+		    using (await self.Fiber().GetComponent<CoroutineLockComponent>().Wait(CoroutineLockType.DB, id % DBComponent.TaskCount))
 		    {
 			    foreach (string collectionName in collectionNames)
 			    {
@@ -86,7 +86,7 @@ namespace ET.Server
 
 	    public static async ETTask<List<T>> QueryJson<T>(this DBComponent self, string json, string collection = null) where T : Entity
 	    {
-		    using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.DB, RandomGenerator.RandInt64() % DBComponent.TaskCount))
+		    using (await self.Fiber().GetComponent<CoroutineLockComponent>().Wait(CoroutineLockType.DB, RandomGenerator.RandInt64() % DBComponent.TaskCount))
 		    {
 			    FilterDefinition<T> filterDefinition = new JsonFilterDefinition<T>(json);
 			    IAsyncCursor<T> cursor = await self.GetCollection<T>(collection).FindAsync(filterDefinition);
@@ -96,7 +96,7 @@ namespace ET.Server
 
 	    public static async ETTask<List<T>> QueryJson<T>(this DBComponent self, long taskId, string json, string collection = null) where T : Entity
 	    {
-		    using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.DB, RandomGenerator.RandInt64() % DBComponent.TaskCount))
+		    using (await self.Fiber().GetComponent<CoroutineLockComponent>().Wait(CoroutineLockType.DB, RandomGenerator.RandInt64() % DBComponent.TaskCount))
 		    {
 			    FilterDefinition<T> filterDefinition = new JsonFilterDefinition<T>(json);
 			    IAsyncCursor<T> cursor = await self.GetCollection<T>(collection).FindAsync(filterDefinition);
@@ -115,7 +115,7 @@ namespace ET.Server
 			    collection = typeof (T).Name;
 		    }
 		    
-		    using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.DB, RandomGenerator.RandInt64() % DBComponent.TaskCount))
+		    using (await self.Fiber().GetComponent<CoroutineLockComponent>().Wait(CoroutineLockType.DB, RandomGenerator.RandInt64() % DBComponent.TaskCount))
 		    {
 			    await self.GetCollection(collection).InsertManyAsync(list);
 		    }
@@ -139,7 +139,7 @@ namespace ET.Server
 			    collection = entity.GetType().FullName;
 		    }
 
-		    using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.DB, entity.Id % DBComponent.TaskCount))
+		    using (await self.Fiber().GetComponent<CoroutineLockComponent>().Wait(CoroutineLockType.DB, entity.Id % DBComponent.TaskCount))
 		    {
 			    await self.GetCollection(collection).ReplaceOneAsync(d => d.Id == entity.Id, entity, new ReplaceOptions { IsUpsert = true });
 		    }
@@ -159,7 +159,7 @@ namespace ET.Server
 			    collection = entity.GetType().FullName;
 		    }
 
-		    using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.DB, taskId % DBComponent.TaskCount))
+		    using (await self.Fiber().GetComponent<CoroutineLockComponent>().Wait(CoroutineLockType.DB, taskId % DBComponent.TaskCount))
 		    {
 			    await self.GetCollection(collection).ReplaceOneAsync(d => d.Id == entity.Id, entity, new ReplaceOptions { IsUpsert = true });
 		    }
@@ -173,7 +173,7 @@ namespace ET.Server
 			    return;
 		    }
 
-		    using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.DB, id % DBComponent.TaskCount))
+		    using (await self.Fiber().GetComponent<CoroutineLockComponent>().Wait(CoroutineLockType.DB, id % DBComponent.TaskCount))
 		    {
 			    foreach (Entity entity in entities)
 			    {
@@ -206,7 +206,7 @@ namespace ET.Server
 	    
 	    public static async ETTask<long> Remove<T>(this DBComponent self, long id, string collection = null) where T : Entity
 	    {
-		    using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.DB, id % DBComponent.TaskCount))
+		    using (await self.Fiber().GetComponent<CoroutineLockComponent>().Wait(CoroutineLockType.DB, id % DBComponent.TaskCount))
 		    {
 			    DeleteResult result = await self.GetCollection<T>(collection).DeleteOneAsync(d => d.Id == id);
 
@@ -216,7 +216,7 @@ namespace ET.Server
 
 	    public static async ETTask<long> Remove<T>(this DBComponent self, long taskId, long id, string collection = null) where T : Entity
 	    {
-		    using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.DB, taskId % DBComponent.TaskCount))
+		    using (await self.Fiber().GetComponent<CoroutineLockComponent>().Wait(CoroutineLockType.DB, taskId % DBComponent.TaskCount))
 		    {
 			    DeleteResult result = await self.GetCollection<T>(collection).DeleteOneAsync(d => d.Id == id);
 
@@ -226,7 +226,7 @@ namespace ET.Server
 
 	    public static async ETTask<long> Remove<T>(this DBComponent self, Expression<Func<T, bool>> filter, string collection = null) where T : Entity
 	    {
-		    using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.DB, RandomGenerator.RandInt64() % DBComponent.TaskCount))
+		    using (await self.Fiber().GetComponent<CoroutineLockComponent>().Wait(CoroutineLockType.DB, RandomGenerator.RandInt64() % DBComponent.TaskCount))
 		    {
 			    DeleteResult result = await self.GetCollection<T>(collection).DeleteManyAsync(filter);
 
@@ -237,7 +237,7 @@ namespace ET.Server
 	    public static async ETTask<long> Remove<T>(this DBComponent self, long taskId, Expression<Func<T, bool>> filter, string collection = null)
 			    where T : Entity
 	    {
-		    using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.DB, taskId % DBComponent.TaskCount))
+		    using (await self.Fiber().GetComponent<CoroutineLockComponent>().Wait(CoroutineLockType.DB, taskId % DBComponent.TaskCount))
 		    {
 			    DeleteResult result = await self.GetCollection<T>(collection).DeleteManyAsync(filter);
 

+ 19 - 11
Unity/Assets/Scripts/Hotfix/Server/Module/Message/NetInnerComponentSystem.cs

@@ -9,50 +9,57 @@ namespace ET.Server
         [EntitySystem]
         private static void Awake(this NetInnerComponent self)
         {
+            NetServices netServices = self.Fiber().GetComponent<NetServices>();
             switch (self.InnerProtocol)
             {
                 case NetworkProtocol.TCP:
                 {
-                    self.ServiceId = NetServices.Instance.AddService(new TService(AddressFamily.InterNetwork, ServiceType.Inner));
+                    self.ServiceId = netServices.AddService(new TService(AddressFamily.InterNetwork, ServiceType.Inner));
                     break;
                 }
                 case NetworkProtocol.KCP:
                 {
-                    self.ServiceId = NetServices.Instance.AddService(new KService(AddressFamily.InterNetwork, ServiceType.Inner));
+                    self.ServiceId = netServices.AddService(new KService(AddressFamily.InterNetwork, ServiceType.Inner));
                     break;
                 }
             }
                 
-            NetServices.Instance.RegisterReadCallback(self.ServiceId, self.OnRead);
-            NetServices.Instance.RegisterErrorCallback(self.ServiceId, self.OnError);
+            netServices.RegisterReadCallback(self.ServiceId, self.OnRead);
+            netServices.RegisterErrorCallback(self.ServiceId, self.OnError);
         }
 
         [EntitySystem]
         private static void Awake(this NetInnerComponent self, IPEndPoint address)
         {
+            NetServices netServices = self.Fiber().GetComponent<NetServices>();
             switch (self.InnerProtocol)
             {
                 case NetworkProtocol.TCP:
                 {
-                    self.ServiceId = NetServices.Instance.AddService(new TService(address, ServiceType.Inner));
+                    self.ServiceId = netServices.AddService(new TService(address, ServiceType.Inner));
                     break;
                 }
                 case NetworkProtocol.KCP:
                 {
-                    self.ServiceId = NetServices.Instance.AddService(new KService(address, ServiceType.Inner));
+                    self.ServiceId = netServices.AddService(new KService(address, ServiceType.Inner));
                     break;
                 }
             }
                 
-            NetServices.Instance.RegisterAcceptCallback(self.ServiceId, self.OnAccept);
-            NetServices.Instance.RegisterReadCallback(self.ServiceId, self.OnRead);
-            NetServices.Instance.RegisterErrorCallback(self.ServiceId, self.OnError);
+            netServices.RegisterAcceptCallback(self.ServiceId, self.OnAccept);
+            netServices.RegisterReadCallback(self.ServiceId, self.OnRead);
+            netServices.RegisterErrorCallback(self.ServiceId, self.OnError);
         }
 
         [EntitySystem]
         private static void Destroy(this NetInnerComponent self)
         {
-            NetServices.Instance.RemoveService(self.ServiceId);
+            if (self.Fiber().InstanceId == 0)
+            {
+                return;
+            }
+            NetServices netServices = self.Fiber().GetComponent<NetServices>();
+            netServices.RemoveService(self.ServiceId);
         }
 
         private static void OnRead(this NetInnerComponent self, long channelId, ActorId actorId, object message)
@@ -98,7 +105,8 @@ namespace ET.Server
         {
             Session session = self.AddChildWithId<Session, int>(channelId, self.ServiceId);
             session.RemoteAddress = ipEndPoint;
-            NetServices.Instance.CreateChannel(self.ServiceId, channelId, ipEndPoint);
+            NetServices netServices = self.Fiber().GetComponent<NetServices>();
+            netServices.CreateChannel(self.ServiceId, channelId, ipEndPoint);
 
             //session.AddComponent<InnerPingComponent>();
             //session.AddComponent<SessionIdleCheckerComponent, int, int, int>(NetThreadComponent.checkInteral, NetThreadComponent.recvMaxIdleTime, NetThreadComponent.sendMaxIdleTime);

+ 7 - 5
Unity/Assets/Scripts/Hotfix/Server/Module/Message/NetServerComponentSystem.cs

@@ -9,16 +9,18 @@ namespace ET.Server
         [EntitySystem]
         private static void Awake(this NetServerComponent self, IPEndPoint address)
         {
-            self.ServiceId = NetServices.Instance.AddService(new KService(address, ServiceType.Outer));
-            NetServices.Instance.RegisterAcceptCallback(self.ServiceId, self.OnAccept);
-            NetServices.Instance.RegisterReadCallback(self.ServiceId, self.OnRead);
-            NetServices.Instance.RegisterErrorCallback(self.ServiceId, self.OnError);
+            NetServices netServices = self.Fiber().GetComponent<NetServices>();
+            self.ServiceId = netServices.AddService(new KService(address, ServiceType.Outer));
+            netServices.RegisterAcceptCallback(self.ServiceId, self.OnAccept);
+            netServices.RegisterReadCallback(self.ServiceId, self.OnRead);
+            netServices.RegisterErrorCallback(self.ServiceId, self.OnError);
         }
 
         [EntitySystem]
         private static void Destroy(this NetServerComponent self)
         {
-            NetServices.Instance.RemoveService(self.ServiceId);
+            NetServices netServices = self.Fiber().GetComponent<NetServices>();
+            netServices.RemoveService(self.ServiceId);
         }
 
         private static void OnError(this NetServerComponent self, long channelId, int error)

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Module/RobotCase/ARobotCase.cs

@@ -8,7 +8,7 @@ namespace ET.Server
 
         public override async ETTask Handle(RobotInvokeArgs a)
         {
-            using RobotCase robotCase = await RobotCaseComponent.Instance.New();
+            using RobotCase robotCase = await a.Fiber.GetComponent<RobotCaseComponent>().New();
             
             try
             {

+ 2 - 1
Unity/Assets/Scripts/Hotfix/Server/Module/Router/RouterComponentSystem.cs

@@ -247,7 +247,8 @@ namespace ET.Server
                     self.ConnectIdNodes.TryGetValue(connectId, out routerNode);
                     if (routerNode == null)
                     {
-                        outerConn = NetServices.Instance.CreateConnectChannelId();
+                        NetServices netServices = self.Fiber().GetComponent<NetServices>();
+                        outerConn = netServices.CreateConnectChannelId();
                         routerNode = self.New(realAddress, connectId, outerConn, innerConn, self.CloneAddress());
                         Log.Info($"router create: {realAddress} {connectId} {outerConn} {innerConn} {routerNode.SyncIpEndPoint}");
                         self.OuterNodes.Add(routerNode.OuterConn, routerNode);

+ 9 - 5
Unity/Assets/Scripts/Hotfix/Share/Module/AI/AIComponentSystem.cs

@@ -26,23 +26,27 @@ namespace ET
         private static void Awake(this AIComponent self, int aiConfigId)
         {
             self.AIConfigId = aiConfigId;
-            self.Timer = TimerComponent.Instance.NewRepeatedTimer(1000, TimerInvokeType.AITimer, self);
+            self.Timer = self.Fiber().GetComponent<TimerComponent>().NewRepeatedTimer(1000, TimerInvokeType.AITimer, self);
         }
 
         [EntitySystem]
         private static void Destroy(this AIComponent self)
         {
-            TimerComponent.Instance?.Remove(ref self.Timer);
+            if (self.Fiber().InstanceId == 0)
+            {
+                return;
+            }
+            self.Fiber().GetComponent<TimerComponent>().Remove(ref self.Timer);
             self.CancellationToken?.Cancel();
             self.CancellationToken = null;
             self.Current = 0;
         }
-        
-        public static void Check(this AIComponent self)
+
+        private static void Check(this AIComponent self)
         {
             if (self.Parent == null)
             {
-                TimerComponent.Instance.Remove(ref self.Timer);
+                self.Fiber().GetComponent<TimerComponent>().Remove(ref self.Timer);
                 return;
             }
 

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Share/Module/Actor/ActorMessageHandler.cs

@@ -79,7 +79,7 @@ namespace ET
                 }
                 
                 response.RpcId = rpcId;
-                ActorMessageSenderComponent.Instance.Reply(actorId, response);
+                entity.Fiber().GetComponent<ActorMessageSenderComponent>().Reply(actorId, response);
             }
             catch (Exception e)
             {

+ 6 - 4
Unity/Assets/Scripts/Hotfix/Share/Module/Actor/ActorMessageRecvComponentSystem.cs

@@ -2,6 +2,7 @@
 
 namespace ET
 {
+    [FriendOf(typeof(ActorMessageRecvComponent))]
     public static partial class ActorMessageRecvComponentSystem
     {
         [EntitySystem]
@@ -22,24 +23,25 @@ namespace ET
             self.list.Clear();
             Fiber fiber = self.Fiber();
             ActorMessageQueue.Instance.Fetch((int)fiber.Id, 1000, self.list);
-            
+
+            ActorMessageSenderComponent actorMessageSenderComponent = self.Fiber().GetComponent<ActorMessageSenderComponent>();
             foreach (ActorMessageInfo actorMessageInfo in self.list)
             {
                 if (actorMessageInfo.MessageObject is IActorResponse response)
                 {
-                    ActorMessageSenderComponent.Instance.HandleIActorResponse(response);
+                    actorMessageSenderComponent.HandleIActorResponse(response);
                     continue;
                 }
 
                 ActorId actorId = actorMessageInfo.ActorId;
                 MessageObject message = actorMessageInfo.MessageObject;
                 actorId.Address = fiber.Address;
-                MailBoxComponent mailBoxComponent = Fiber.Instance.Mailboxes.Get(actorId.InstanceId);
+                MailBoxComponent mailBoxComponent = self.Fiber().Mailboxes.Get(actorId.InstanceId);
                 if (mailBoxComponent == null)
                 {
                     Log.Warning($"actor not found mailbox: {actorId} {message}");
                     IActorResponse resp = ActorHelper.CreateResponse((IActorRequest)message, ErrorCore.ERR_NotFoundActor);
-                    ActorMessageSenderComponent.Instance.Reply(actorId, resp);
+                    actorMessageSenderComponent.Reply(actorId, resp);
                     return;
                 }
                 mailBoxComponent.Add(message);

+ 6 - 2
Unity/Assets/Scripts/Hotfix/Share/Module/Actor/ActorMessageSenderComponentSystem.cs

@@ -25,13 +25,17 @@ namespace ET
         [EntitySystem]
         private static void Awake(this ActorMessageSenderComponent self)
         {
-            self.TimeoutCheckTimer = TimerComponent.Instance.NewRepeatedTimer(1000, TimerInvokeType.ActorMessageSenderChecker, self);
+            self.TimeoutCheckTimer = self.Fiber().GetComponent<TimerComponent>().NewRepeatedTimer(1000, TimerInvokeType.ActorMessageSenderChecker, self);
         }
         
         [EntitySystem]
         private static void Destroy(this ActorMessageSenderComponent self)
         {
-            TimerComponent.Instance?.Remove(ref self.TimeoutCheckTimer);
+            if (self.Fiber().InstanceId == 0)
+            {
+                return;
+            }
+            self.Fiber().GetComponent<TimerComponent>().Remove(ref self.TimeoutCheckTimer);
             self.TimeoutCheckTimer = 0;
             self.TimeoutActorMessageSenders.Clear();
         }

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Share/Module/Console/ConsoleComponentSystem.cs

@@ -86,7 +86,7 @@ namespace ET
                                 modeContex = self.AddComponent<ModeContex>();
                                 modeContex.Mode = mode;
                             }
-                            await iConsoleHandler.Run(modeContex, line);
+                            await iConsoleHandler.Run(self.Fiber(), modeContex, line);
                             break;
                         }
                     }

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Share/Module/Console/ReloadConfigConsoleHandler.cs

@@ -5,7 +5,7 @@ namespace ET
     [ConsoleHandler(ConsoleMode.ReloadConfig)]
     public class ReloadConfigConsoleHandler: IConsoleHandler
     {
-        public async ETTask Run(ModeContex contex, string content)
+        public async ETTask Run(Fiber fiber, ModeContex contex, string content)
         {
             switch (content)
             {

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Share/Module/Console/ReloadDllConsoleHandler.cs

@@ -3,7 +3,7 @@ namespace ET
     [ConsoleHandler(ConsoleMode.ReloadDll)]
     public class ReloadDllConsoleHandler: IConsoleHandler
     {
-        public async ETTask Run(ModeContex contex, string content)
+        public async ETTask Run(Fiber fiber, ModeContex contex, string content)
         {
             await ETTask.CompletedTask;
         }

+ 6 - 2
Unity/Assets/Scripts/Hotfix/Share/Module/Message/SessionAcceptTimeoutComponentSystem.cs

@@ -24,13 +24,17 @@ namespace ET
         [EntitySystem]
         private static void Awake(this SessionAcceptTimeoutComponent self)
         {
-            self.Timer = TimerComponent.Instance.NewOnceTimer(TimeHelper.ServerNow() + 5000, TimerInvokeType.SessionAcceptTimeout, self);
+            self.Timer = self.Fiber().GetComponent<TimerComponent>().NewOnceTimer(TimeHelper.ServerNow() + 5000, TimerInvokeType.SessionAcceptTimeout, self);
         }
         
         [EntitySystem]
         private static void Destroy(this SessionAcceptTimeoutComponent self)
         {
-            TimerComponent.Instance.Remove(ref self.Timer);
+            if (self.Fiber().IsDisposed)
+            {
+                return;
+            }
+            self.Fiber().GetComponent<TimerComponent>().Remove(ref self.Timer);
         }
         
     }

+ 6 - 2
Unity/Assets/Scripts/Hotfix/Share/Module/Message/SessionIdleCheckerComponentSystem.cs

@@ -24,13 +24,17 @@ namespace ET
         [EntitySystem]
         private static void Awake(this SessionIdleCheckerComponent self)
         {
-            self.RepeatedTimer = TimerComponent.Instance.NewRepeatedTimer(SessionIdleCheckerComponentSystem.CheckInteral, TimerInvokeType.SessionIdleChecker, self);
+            self.RepeatedTimer = self.Fiber().GetComponent<TimerComponent>().NewRepeatedTimer(SessionIdleCheckerComponentSystem.CheckInteral, TimerInvokeType.SessionIdleChecker, self);
         }
         
         [EntitySystem]
         private static void Destroy(this SessionIdleCheckerComponent self)
         {
-            TimerComponent.Instance?.Remove(ref self.RepeatedTimer);
+            if (self.IsDisposed)
+            {
+                return;
+            }
+            self.Fiber().GetComponent<TimerComponent>().Remove(ref self.RepeatedTimer);
         }
         
         public const int CheckInteral = 2000;

+ 6 - 2
Unity/Assets/Scripts/Hotfix/Share/Module/Move/MoveComponentSystem.cs

@@ -181,7 +181,7 @@ namespace ET
             self.StartTime = self.BeginTime;
             self.SetNextTarget();
 
-            self.MoveTimer = TimerComponent.Instance.NewFrameTimer(TimerInvokeType.MoveTimer, self);
+            self.MoveTimer = self.Fiber().GetComponent<TimerComponent>().NewFrameTimer(TimerInvokeType.MoveTimer, self);
         }
 
         private static void SetNextTarget(this MoveComponent self)
@@ -266,6 +266,10 @@ namespace ET
 
         private static void MoveFinish(this MoveComponent self, bool ret)
         {
+            if (self.Fiber().IsDisposed)
+            {
+                return;
+            }
             if (self.StartTime == 0)
             {
                 return;
@@ -275,7 +279,7 @@ namespace ET
             self.StartPos = float3.zero;
             self.BeginTime = 0;
             self.NeedTime = 0;
-            TimerComponent.Instance?.Remove(ref self.MoveTimer);
+            self.Fiber().GetComponent<TimerComponent>().Remove(ref self.MoveTimer);
             self.Targets.Clear();
             self.Speed = 0;
             self.N = 0;

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Share/Module/Recast/PathfindingComponentSystem.cs

@@ -11,7 +11,7 @@ namespace ET
         private static void Awake(this PathfindingComponent self, string name)
         {
             self.Name = name;
-            self.NavMesh = NavmeshComponent.Instance.Get(name);
+            self.NavMesh = self.Fiber().GetComponent<NavmeshComponent>().Get(name);
 
             if (self.NavMesh == 0)
             {

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

@@ -4,7 +4,7 @@ using System.Diagnostics;
 namespace ET.Server
 {
     [ComponentOf(typeof(Fiber))]
-    public class WatcherComponent: SingletonEntity<WatcherComponent>, IAwake, IDestroy
+    public class WatcherComponent: Entity, IAwake, IDestroy
     {
         public readonly Dictionary<int, System.Diagnostics.Process> Processes = new Dictionary<int, System.Diagnostics.Process>();
     }

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

@@ -15,7 +15,7 @@ namespace ET.Server
     
     
     [ComponentOf(typeof(Fiber))]
-    public class ActorLocationSenderComponent: SingletonEntity<ActorLocationSenderComponent>, IAwake, IDestroy
+    public class ActorLocationSenderComponent: Entity, IAwake, IDestroy
     {
         public const long TIMEOUT_TIME = 60 * 1000;
 

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

@@ -18,7 +18,19 @@ namespace ET.Server
     {
         public ActorId LockActorId;
 
-        public CoroutineLock CoroutineLock;
+        private EntityRef<CoroutineLock> coroutineLock;
+
+        public CoroutineLock CoroutineLock
+        {
+            get
+            {
+                return this.coroutineLock;
+            }
+            set
+            {
+                this.coroutineLock = value;
+            }
+        }
     }
 
     [ChildOf(typeof(LocationManagerComoponent))]
@@ -26,9 +38,9 @@ namespace ET.Server
     {
         public int LocationType;
         
-        public readonly Dictionary<long, ActorId> locations = new Dictionary<long, ActorId>();
+        public readonly Dictionary<long, ActorId> locations = new();
 
-        public readonly Dictionary<long, LockInfo> lockInfos = new Dictionary<long, LockInfo>();
+        public readonly Dictionary<long, LockInfo> lockInfos = new();
     }
 
     [ComponentOf(typeof(Scene))]

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

@@ -3,7 +3,7 @@
 namespace ET.Server
 {
     [ComponentOf(typeof(Fiber))]
-    public class LocationProxyComponent: SingletonEntity<LocationProxyComponent>, IAwake
+    public class LocationProxyComponent: Entity, IAwake
     {
     }
 }

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

@@ -3,7 +3,7 @@
 namespace ET.Server
 {
     [ComponentOf(typeof(Fiber))]
-    public class DBManagerComponent: SingletonEntity<DBManagerComponent>, IAwake
+    public class DBManagerComponent: Entity, IAwake
     {
         public DBComponent[] DBComponents = new DBComponent[IdGenerater.MaxZone];
     }

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

@@ -4,7 +4,7 @@ using System.Net;
 namespace ET.Server
 {
     [ComponentOf(typeof(Fiber))]
-    public class NetInnerComponent: SingletonEntity<NetInnerComponent>, IAwake<IPEndPoint>, IAwake, IDestroy
+    public class NetInnerComponent: Entity, IAwake<IPEndPoint>, IAwake, IDestroy
     {
         public int ServiceId;
         

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

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

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

@@ -2,6 +2,7 @@ namespace ET.Server
 {
     public struct RobotInvokeArgs
     {
+        public Fiber Fiber { get; set; }
         public string Content { get; set; }
     }
 }

+ 1 - 1
Unity/Assets/Scripts/Model/Share/Module/Actor/ActorMessageRecvComponent.cs

@@ -3,7 +3,7 @@
 namespace ET
 {
     [ComponentOf(typeof(Fiber))]
-    public class ActorMessageRecvComponent: SingletonEntity<ActorMessageRecvComponent>, IAwake, IDestroy, IUpdate
+    public class ActorMessageRecvComponent: Entity, IAwake, IDestroy, IUpdate
     {
         public readonly List<ActorMessageInfo> list = new();
     }

+ 1 - 1
Unity/Assets/Scripts/Model/Share/Module/Actor/ActorMessageSenderComponent.cs

@@ -3,7 +3,7 @@
 namespace ET
 {
     [ComponentOf(typeof(Fiber))]
-    public class ActorMessageSenderComponent: SingletonEntity<ActorMessageSenderComponent>, IAwake, IDestroy
+    public class ActorMessageSenderComponent: Entity, IAwake, IDestroy
     {
         public const long TIMEOUT_TIME = 40 * 1000;
 

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

@@ -15,7 +15,7 @@ namespace ET
     }
 
     [ComponentOf(typeof(Fiber))]
-    public class ConsoleComponent: SingletonEntity<ConsoleComponent>, IAwake, ILoad
+    public class ConsoleComponent: Entity, IAwake, ILoad
     {
         public CancellationTokenSource CancellationTokenSource;
         public Dictionary<string, IConsoleHandler> Handlers = new Dictionary<string, IConsoleHandler>();

+ 1 - 1
Unity/Assets/Scripts/Model/Share/Module/Console/IConsoleHandler.cs

@@ -2,6 +2,6 @@ namespace ET
 {
     public interface IConsoleHandler
     {
-        ETTask Run(ModeContex contex, string content);
+        ETTask Run(Fiber fiber, ModeContex contex, string content);
     }
 }

+ 2 - 2
Unity/Assets/Scripts/Model/Share/Module/Message/Session.cs

@@ -36,7 +36,7 @@ namespace ET
         [EntitySystem]
         private static void Destroy(this Session self)
         {
-            NetServices.Instance.RemoveChannel(self.ServiceId, self.Id, self.Error);
+            self.Fiber().GetComponent<NetServices>().RemoveChannel(self.ServiceId, self.Id, self.Error);
             
             foreach (RpcInfo responseCallback in self.requestCallbacks.Values.ToArray())
             {
@@ -119,7 +119,7 @@ namespace ET
         {
             self.LastSendTime = TimeHelper.ClientNow();
             Log.Debug(message.ToString());
-            NetServices.Instance.SendMessage(self.ServiceId, self.Id, actorId, message as MessageObject);
+            self.Fiber().GetComponent<NetServices>().SendMessage(self.ServiceId, self.Id, actorId, message as MessageObject);
         }
     }
 

+ 1 - 1
Unity/Assets/Scripts/Model/Share/Module/ObjectWait/ObjectWait.cs

@@ -107,7 +107,7 @@ namespace ET
             ResultCallback<T> tcs = new ResultCallback<T>();
             async ETTask WaitTimeout()
             {
-                await TimerComponent.Instance.WaitAsync(timeout, cancellationToken);
+                await self.Fiber().GetComponent<TimerComponent>().WaitAsync(timeout, cancellationToken);
                 if (cancellationToken.IsCancel())
                 {
                     return;

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

@@ -4,7 +4,7 @@ using System.Collections.Generic;
 namespace ET
 {
     [ComponentOf(typeof(Fiber))]
-    public class NavmeshComponent: SingletonEntity<NavmeshComponent>, IAwake
+    public class NavmeshComponent: Entity, IAwake
     {
         public struct RecastFileLoader
         {

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

@@ -3,7 +3,7 @@ using System;
 namespace ET
 {
     [ComponentOf(typeof(Fiber))]
-    public class ClientSceneManagerComponent: SingletonEntity<ClientSceneManagerComponent>, IAwake
+    public class ClientSceneManagerComponent: Entity, IAwake
     {
     }
 }

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

@@ -3,7 +3,7 @@ using System;
 namespace ET
 {
     [ComponentOf(typeof(Fiber))]
-    public class ServerSceneManagerComponent: SingletonEntity<ServerSceneManagerComponent>, IAwake, IDestroy
+    public class ServerSceneManagerComponent: Entity, IAwake, IDestroy
     {
     }
 }

+ 6 - 5
Unity/Assets/Scripts/ModelView/Client/Module/Resource/ResourcesComponent.cs

@@ -228,12 +228,13 @@ namespace ET.Client
             string[] dependencies = self.GetSortedDependencies(assetBundleName);
 
             //Log.Debug($"-----------dep unload start {assetBundleName} dep: {dependencies.ToList().ListToString()}");
+            TimerComponent timerComponent = self.Fiber().GetComponent<TimerComponent>();
             foreach (string dependency in dependencies)
             {
-                using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.Resources, assetBundleName.GetHashCode()))
+                using (await self.Fiber().GetComponent<CoroutineLockComponent>().Wait(CoroutineLockType.Resources, assetBundleName.GetHashCode()))
                 {
                     self.UnloadOneBundle(dependency, unload);
-                    await TimerComponent.Instance.WaitFrameAsync();
+                    await timerComponent.WaitFrameAsync();
                 }
             }
             //Log.Debug($"-----------dep unload finish {assetBundleName} dep: {dependencies.ToList().ListToString()}");
@@ -406,7 +407,7 @@ namespace ET.Client
                 async ETTask LoadDependency(string dependency, List<ABInfo> abInfosList)
                 {
                     using CoroutineLock coroutineLock =
-                            await CoroutineLockComponent.Instance.Wait(CoroutineLockType.Resources, dependency.GetHashCode());
+                            await self.Fiber().GetComponent<CoroutineLockComponent>().Wait(CoroutineLockType.Resources, dependency.GetHashCode());
 
                     ABInfo abInfo = await self.LoadOneBundleAsync(dependency);
                     if (abInfo == null || abInfo.RefCount > 1)
@@ -477,7 +478,7 @@ namespace ET.Client
                     }
 
                     // 编辑器模式也不能同步加载
-                    await TimerComponent.Instance.WaitAsync(100);
+                    await self.Fiber().GetComponent<TimerComponent>().WaitAsync(100);
 
                     return abInfo;
                 }
@@ -515,7 +516,7 @@ namespace ET.Client
         // 加载ab包中的all assets
         private static async ETTask LoadOneBundleAllAssets(this ResourcesComponent self, ABInfo abInfo)
         {
-            using CoroutineLock coroutineLock = await CoroutineLockComponent.Instance.Wait(CoroutineLockType.Resources, abInfo.Name.GetHashCode());
+            using CoroutineLock coroutineLock = await self.Fiber().GetComponent<CoroutineLockComponent>().Wait(CoroutineLockType.Resources, abInfo.Name.GetHashCode());
 
             if (abInfo.IsDisposed || abInfo.AlreadyLoadAssets)
             {

+ 21 - 20
Unity/Assets/Scripts/ModelView/Client/Module/Resource/ResourcesLoaderComponent.cs

@@ -10,31 +10,32 @@ namespace ET.Client
         {
             async ETTask UnLoadAsync()
             {
-                using (ListComponent<string> list = ListComponent<string>.Create())
-                {
-                    list.AddRange(self.LoadedResource);
-                    self.LoadedResource = null;
+                using ListComponent<string> list = ListComponent<string>.Create();
+                
+                TimerComponent timerComponent = self.Fiber().GetComponent<TimerComponent>();
+                list.AddRange(self.LoadedResource);
+                self.LoadedResource = null;
 
-                    if (TimerComponent.Instance == null)
-                    {
-                        return;
-                    }
+                if (timerComponent == null)
+                {
+                    return;
+                }
 
-                    // 延迟5秒卸载包,因为包卸载是引用计数,5秒之内假如重新有逻辑加载了这个包,那么可以避免一次卸载跟加载
-                    await TimerComponent.Instance.WaitAsync(5000);
+                // 延迟5秒卸载包,因为包卸载是引用计数,5秒之内假如重新有逻辑加载了这个包,那么可以避免一次卸载跟加载
+                await timerComponent.WaitAsync(5000);
 
-                    foreach (string abName in list)
+                CoroutineLockComponent coroutineLockComponent = self.Fiber().GetComponent<CoroutineLockComponent>();
+                foreach (string abName in list)
+                {
+                    using CoroutineLock coroutineLock =
+                            await coroutineLockComponent.Wait(CoroutineLockType.ResourcesLoader, abName.GetHashCode(), 0);
                     {
-                        using CoroutineLock coroutineLock =
-                                await CoroutineLockComponent.Instance.Wait(CoroutineLockType.ResourcesLoader, abName.GetHashCode(), 0);
+                        if (ResourcesComponent.Instance == null)
                         {
-                            if (ResourcesComponent.Instance == null)
-                            {
-                                return;
-                            }
-
-                            await ResourcesComponent.Instance.UnloadBundleAsync(abName);
+                            return;
                         }
+
+                        await ResourcesComponent.Instance.UnloadBundleAsync(abName);
                     }
                 }
             }
@@ -44,7 +45,7 @@ namespace ET.Client
 
         public static async ETTask LoadAsync(this ResourcesLoaderComponent self, string ab)
         {
-            using CoroutineLock coroutineLock = await CoroutineLockComponent.Instance.Wait(CoroutineLockType.ResourcesLoader, ab.GetHashCode(), 0);
+            using CoroutineLock coroutineLock = await self.Fiber().GetComponent<CoroutineLockComponent>().Wait(CoroutineLockType.ResourcesLoader, ab.GetHashCode(), 0);
 
             if (self.IsDisposed)
             {