Răsfoiți Sursa

调通登录界面

tanghai 2 ani în urmă
părinte
comite
67b59ef98e
21 a modificat fișierele cu 293 adăugiri și 307 ștergeri
  1. 1 1
      DotNet/App/Program.cs
  2. 1 1
      Unity/Assets/Resources/GlobalConfig.asset
  3. 6 0
      Unity/Assets/Scripts/Core/Entity/EntityRef.cs
  4. 21 17
      Unity/Assets/Scripts/Core/Fiber/Module/CoroutineLock/CoroutineLockComponent.cs
  5. 87 83
      Unity/Assets/Scripts/Core/Fiber/Module/Timer/TimerComponent.cs
  6. 1 1
      Unity/Assets/Scripts/Core/Network/AService.cs
  7. 4 4
      Unity/Assets/Scripts/Core/World/Module/Fiber/FiberManager.cs
  8. 41 44
      Unity/Assets/Scripts/Core/World/Module/Scheduler/MainThreadScheduler.cs
  9. 50 53
      Unity/Assets/Scripts/Core/World/Module/Scheduler/ThreadPoolScheduler.cs
  10. 33 36
      Unity/Assets/Scripts/Core/World/Module/Scheduler/ThreadScheduler.cs
  11. 3 6
      Unity/Assets/Scripts/Hotfix/Server/Demo/EntryEvent2_InitServer.cs
  12. 0 1
      Unity/Assets/Scripts/Hotfix/Share/Module/Actor/ActorMessageHandler.cs
  13. 1 3
      Unity/Assets/Scripts/Hotfix/Share/Module/Actor/ActorRecverComponentSystem.cs
  14. 10 10
      Unity/Assets/Scripts/HotfixView/Client/Demo/EntryEvent3_InitClient.cs
  15. 0 16
      Unity/Assets/Scripts/HotfixView/Client/Demo/Scene/FiberInit_DemoView.cs
  16. 0 11
      Unity/Assets/Scripts/HotfixView/Client/Demo/Scene/FiberInit_DemoView.cs.meta
  17. 16 7
      Unity/Assets/Scripts/HotfixView/Client/Demo/Scene/SceneChangeStart_AddComponent.cs
  18. 14 9
      Unity/Assets/Scripts/Loader/GlobalComponent.cs
  19. 2 2
      Unity/Assets/Scripts/Loader/MonoBehaviour/Init.cs
  20. 1 1
      Unity/Assets/Scripts/Model/Share/Entry.cs
  21. 1 1
      Unity/ProjectSettings/ProjectSettings.asset

+ 1 - 1
DotNet/App/Program.cs

@@ -17,7 +17,7 @@ namespace ET
             Entry.Init();
             Init.Start();
             
-            FiberManager.MainThreadScheduler mainThreadScheduler = FiberManager.MainThreadScheduler.Instance;
+            MainThreadScheduler mainThreadScheduler = MainThreadScheduler.Instance;
             
             while (true)
             {

+ 1 - 1
Unity/Assets/Resources/GlobalConfig.asset

@@ -14,4 +14,4 @@ MonoBehaviour:
   m_EditorClassIdentifier: 
   CodeMode: 3
   BuildType: 1
-  AppType: 8
+  AppType: 7

+ 6 - 0
Unity/Assets/Scripts/Core/Entity/EntityRef.cs

@@ -9,6 +9,12 @@ namespace ET
 
         private EntityRef(T t)
         {
+            if (t == null)
+            {
+                this.instanceId = 0;
+                this.entity = null;
+                return;
+            }
             this.instanceId = t.InstanceId;
             this.entity = t;
         }

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

@@ -3,25 +3,20 @@ using System.Collections.Generic;
 
 namespace ET
 {
-    [ComponentOf(typeof(Scene))]
-    public class CoroutineLockComponent: Entity, IAwake, IScene
+    public static partial class CoroutineLockComponentSystem
     {
-        public Fiber Fiber { get; set; }
-        public SceneType SceneType { get; set; }
-        
-        private readonly Queue<(int, long, int)> nextFrameRun = new();
-
-        public void Update()
+        [EntitySystem]
+        public static void Update(this CoroutineLockComponent self)
         {
             // 循环过程中会有对象继续加入队列
-            while (this.nextFrameRun.Count > 0)
+            while (self.nextFrameRun.Count > 0)
             {
-                (int coroutineLockType, long key, int count) = this.nextFrameRun.Dequeue();
-                this.Notify(coroutineLockType, key, count);
+                (int coroutineLockType, long key, int count) = self.nextFrameRun.Dequeue();
+                self.Notify(coroutineLockType, key, count);
             }
         }
 
-        public void RunNextCoroutine(int coroutineLockType, long key, int level)
+        public static void RunNextCoroutine(this CoroutineLockComponent self, int coroutineLockType, long key, int level)
         {
             // 一个协程队列一帧处理超过100个,说明比较多了,打个warning,检查一下是否够正常
             if (level == 100)
@@ -29,18 +24,18 @@ namespace ET
                 Log.Warning($"too much coroutine level: {coroutineLockType} {key}");
             }
 
-            this.nextFrameRun.Enqueue((coroutineLockType, key, level));
+            self.nextFrameRun.Enqueue((coroutineLockType, key, level));
         }
 
-        public async ETTask<CoroutineLock> Wait(int coroutineLockType, long key, int time = 60000)
+        public static async ETTask<CoroutineLock> Wait(this CoroutineLockComponent self, int coroutineLockType, long key, int time = 60000)
         {
-            CoroutineLockQueueType coroutineLockQueueType = this.GetChild<CoroutineLockQueueType>(coroutineLockType) ?? this.AddChildWithId<CoroutineLockQueueType>(coroutineLockType);
+            CoroutineLockQueueType coroutineLockQueueType = self.GetChild<CoroutineLockQueueType>(coroutineLockType) ?? self.AddChildWithId<CoroutineLockQueueType>(coroutineLockType);
             return await coroutineLockQueueType.Wait(key, time);
         }
 
-        private void Notify(int coroutineLockType, long key, int level)
+        private static void Notify(this CoroutineLockComponent self, int coroutineLockType, long key, int level)
         {
-            CoroutineLockQueueType coroutineLockQueueType = this.GetChild<CoroutineLockQueueType>(coroutineLockType);
+            CoroutineLockQueueType coroutineLockQueueType = self.GetChild<CoroutineLockQueueType>(coroutineLockType);
             if (coroutineLockQueueType == null)
             {
                 return;
@@ -48,4 +43,13 @@ namespace ET
             coroutineLockQueueType.Notify(key, level);
         }
     }
+    
+    [ComponentOf(typeof(Scene))]
+    public class CoroutineLockComponent: Entity, IAwake, IScene, IUpdate
+    {
+        public Fiber Fiber { get; set; }
+        public SceneType SceneType { get; set; }
+        
+        public readonly Queue<(int, long, int)> nextFrameRun = new();
+    }
 }

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

@@ -53,50 +53,24 @@ namespace ET
         public object Args;
     }
 
-    [ComponentOf(typeof(Scene))]
-    public class TimerComponent: Entity, IAwake
+    public static partial class TimerComponentSystem
     {
-        /// <summary>
-        /// key: time, value: timer id
-        /// </summary>
-        private readonly MultiMap<long, long> TimeId = new(1000);
-
-        private readonly Queue<long> timeOutTime = new();
-
-        private readonly Queue<long> timeOutTimerIds = new();
-
-        private readonly Dictionary<long, TimerAction> timerActions = new();
-
-        private long idGenerator;
-
-        // 记录最小时间,不用每次都去MultiMap取第一个值
-        private long minTime = long.MaxValue;
-
-        private long GetId()
-        {
-            return ++this.idGenerator;
-        }
-
-        private long GetNow()
+        [EntitySystem]
+        private static void Update(this TimerComponent self)
         {
-            return this.Fiber().TimeInfo.ClientFrameTime();
-        }
-
-        public void Update()
-        {
-            if (this.TimeId.Count == 0)
+            if (self.timeId.Count == 0)
             {
                 return;
             }
 
-            long timeNow = GetNow();
+            long timeNow = self.GetNow();
 
-            if (timeNow < this.minTime)
+            if (timeNow < self.minTime)
             {
                 return;
             }
 
-            using (var enumerator = this.TimeId.GetEnumerator())
+            using (var enumerator = self.timeId.GetEnumerator())
             {
                 while (enumerator.MoveNext())
                 {
@@ -104,45 +78,55 @@ namespace ET
                     long k = kv.Key;
                     if (k > timeNow)
                     {
-                        this.minTime = k;
+                        self.minTime = k;
                         break;
                     }
 
-                    this.timeOutTime.Enqueue(k);
+                    self.timeOutTime.Enqueue(k);
                 }
             }
 
-            while (this.timeOutTime.Count > 0)
+            while (self.timeOutTime.Count > 0)
             {
-                long time = this.timeOutTime.Dequeue();
-                var list = this.TimeId[time];
+                long time = self.timeOutTime.Dequeue();
+                var list = self.timeId[time];
                 for (int i = 0; i < list.Count; ++i)
                 {
                     long timerId = list[i];
-                    this.timeOutTimerIds.Enqueue(timerId);
+                    self.timeOutTimerIds.Enqueue(timerId);
                 }
-                this.TimeId.Remove(time);
+                self.timeId.Remove(time);
             }
 
-            if (this.TimeId.Count == 0)
+            if (self.timeId.Count == 0)
             {
-                this.minTime = long.MaxValue;
+                self.minTime = long.MaxValue;
             }
 
-            while (this.timeOutTimerIds.Count > 0)
+            while (self.timeOutTimerIds.Count > 0)
             {
-                long timerId = this.timeOutTimerIds.Dequeue();
+                long timerId = self.timeOutTimerIds.Dequeue();
 
-                if (!this.timerActions.Remove(timerId, out TimerAction timerAction))
+                if (!self.timerActions.Remove(timerId, out TimerAction timerAction))
                 {
                     continue;
                 }
                 
-                this.Run(timerAction);
+                self.Run(timerAction);
             }
         }
+        
+        private static long GetId(this TimerComponent self)
+        {
+            return ++self.idGenerator;
+        }
+
+        private static long GetNow(this TimerComponent self)
+        {
+            return self.Fiber().TimeInfo.ClientFrameTime();
+        }
 
-        private void Run(TimerAction timerAction)
+        private static void Run(this TimerComponent self, TimerAction timerAction)
         {
             switch (timerAction.TimerClass)
             {
@@ -161,41 +145,41 @@ namespace ET
                 }
                 case TimerClass.RepeatedTimer:
                 {                    
-                    long timeNow = GetNow();
+                    long timeNow = self.GetNow();
                     timerAction.StartTime = timeNow;
-                    this.AddTimer(timerAction);
+                    self.AddTimer(timerAction);
                     EventSystem.Instance.Invoke(timerAction.Type, new TimerCallback() { Args = timerAction.Object });
                     break;
                 }
             }
         }
 
-        private void AddTimer(TimerAction timer)
+        private static void AddTimer(this TimerComponent self, TimerAction timer)
         {
             long tillTime = timer.StartTime + timer.Time;
-            this.TimeId.Add(tillTime, timer.Id);
-            this.timerActions.Add(timer.Id, timer);
-            if (tillTime < this.minTime)
+            self.timeId.Add(tillTime, timer.Id);
+            self.timerActions.Add(timer.Id, timer);
+            if (tillTime < self.minTime)
             {
-                this.minTime = tillTime;
+                self.minTime = tillTime;
             }
         }
 
-        public bool Remove(ref long id)
+        public static bool Remove(this TimerComponent self, ref long id)
         {
             long i = id;
             id = 0;
-            return this.Remove(i);
+            return self.Remove(i);
         }
 
-        private bool Remove(long id)
+        private static bool Remove(this TimerComponent self, long id)
         {
             if (id == 0)
             {
                 return false;
             }
 
-            if (!this.timerActions.Remove(id, out TimerAction timerAction))
+            if (!self.timerActions.Remove(id, out TimerAction timerAction))
             {
                 return false;
             }
@@ -203,22 +187,22 @@ namespace ET
             return true;
         }
 
-        public async ETTask WaitTillAsync(long tillTime, ETCancellationToken cancellationToken = null)
+        public static async ETTask WaitTillAsync(this TimerComponent self, long tillTime, ETCancellationToken cancellationToken = null)
         {
-            long timeNow = GetNow();
+            long timeNow = self.GetNow();
             if (timeNow >= tillTime)
             {
                 return;
             }
 
             ETTask tcs = ETTask.Create(true);
-            TimerAction timer = TimerAction.Create(this.GetId(), TimerClass.OnceWaitTimer, timeNow, tillTime - timeNow, 0, tcs);
-            this.AddTimer(timer);
+            TimerAction timer = TimerAction.Create(self.GetId(), TimerClass.OnceWaitTimer, timeNow, tillTime - timeNow, 0, tcs);
+            self.AddTimer(timer);
             long timerId = timer.Id;
 
             void CancelAction()
             {
-                if (this.Remove(timerId))
+                if (self.Remove(timerId))
                 {
                     tcs.SetResult();
                 }
@@ -235,28 +219,28 @@ namespace ET
             }
         }
 
-        public async ETTask WaitFrameAsync(ETCancellationToken cancellationToken = null)
+        public static async ETTask WaitFrameAsync(this TimerComponent self, ETCancellationToken cancellationToken = null)
         {
-            await this.WaitAsync(1, cancellationToken);
+            await self.WaitAsync(1, cancellationToken);
         }
 
-        public async ETTask WaitAsync(long time, ETCancellationToken cancellationToken = null)
+        public static async ETTask WaitAsync(this TimerComponent self, long time, ETCancellationToken cancellationToken = null)
         {
             if (time == 0)
             {
                 return;
             }
 
-            long timeNow = GetNow();
+            long timeNow = self.GetNow();
 
             ETTask tcs = ETTask.Create(true);
-            TimerAction timer = TimerAction.Create(this.GetId(), TimerClass.OnceWaitTimer, timeNow, time, 0, tcs);
-            this.AddTimer(timer);
+            TimerAction timer = TimerAction.Create(self.GetId(), TimerClass.OnceWaitTimer, timeNow, time, 0, tcs);
+            self.AddTimer(timer);
             long timerId = timer.Id;
 
             void CancelAction()
             {
-                if (this.Remove(timerId))
+                if (self.Remove(timerId))
                 {
                     tcs.SetResult();
                 }
@@ -276,32 +260,32 @@ namespace ET
         // 用这个优点是可以热更,缺点是回调式的写法,逻辑不连贯。WaitTillAsync不能热更,优点是逻辑连贯。
         // wait时间短并且逻辑需要连贯的建议WaitTillAsync
         // wait时间长不需要逻辑连贯的建议用NewOnceTimer
-        public long NewOnceTimer(long tillTime, int type, object args)
+        public static long NewOnceTimer(this TimerComponent self, long tillTime, int type, object args)
         {
-            long timeNow = GetNow();
+            long timeNow = self.GetNow();
             if (tillTime < timeNow)
             {
                 Log.Error($"new once time too small: {tillTime}");
             }
 
-            TimerAction timer = TimerAction.Create(this.GetId(), TimerClass.OnceTimer, timeNow, tillTime - timeNow, type, args);
-            this.AddTimer(timer);
+            TimerAction timer = TimerAction.Create(self.GetId(), TimerClass.OnceTimer, timeNow, tillTime - timeNow, type, args);
+            self.AddTimer(timer);
             return timer.Id;
         }
 
-        public long NewFrameTimer(int type, object args)
+        public static long NewFrameTimer(this TimerComponent self, int type, object args)
         {
 #if DOTNET
-            return this.NewRepeatedTimerInner(100, type, args);
+            return self.NewRepeatedTimerInner(100, type, args);
 #else
-            return this.NewRepeatedTimerInner(0, type, args);
+            return self.NewRepeatedTimerInner(0, type, args);
 #endif
         }
 
         /// <summary>
         /// 创建一个RepeatedTimer
         /// </summary>
-        private long NewRepeatedTimerInner(long time, int type, object args)
+        private static long NewRepeatedTimerInner(this TimerComponent self, long time, int type, object args)
         {
 #if DOTNET
             if (time < 100)
@@ -310,15 +294,15 @@ namespace ET
             }
 #endif
             
-            long timeNow = GetNow();
-            TimerAction timer = TimerAction.Create(this.GetId(), TimerClass.RepeatedTimer, timeNow, time, type, args);
+            long timeNow = self.GetNow();
+            TimerAction timer = TimerAction.Create(self.GetId(), TimerClass.RepeatedTimer, timeNow, time, type, args);
 
             // 每帧执行的不用加到timerId中,防止遍历
-            this.AddTimer(timer);
+            self.AddTimer(timer);
             return timer.Id;
         }
 
-        public long NewRepeatedTimer(long time, int type, object args)
+        public static long NewRepeatedTimer(this TimerComponent self, long time, int type, object args)
         {
             if (time < 100)
             {
@@ -326,7 +310,27 @@ namespace ET
                 return 0;
             }
 
-            return this.NewRepeatedTimerInner(time, type, args);
+            return self.NewRepeatedTimerInner(time, type, args);
         }
     }
+
+    [ComponentOf(typeof(Scene))]
+    public class TimerComponent: Entity, IAwake, IUpdate
+    {
+        /// <summary>
+        /// key: time, value: timer id
+        /// </summary>
+        public readonly MultiMap<long, long> timeId = new(1000);
+
+        public readonly Queue<long> timeOutTime = new();
+
+        public readonly Queue<long> timeOutTimerIds = new();
+
+        public readonly Dictionary<long, TimerAction> timerActions = new();
+
+        public long idGenerator;
+
+        // 记录最小时间,不用每次都去MultiMap取第一个值
+        public long minTime = long.MaxValue;
+    }
 }

+ 1 - 1
Unity/Assets/Scripts/Core/Network/AService.cs

@@ -64,7 +64,7 @@ namespace ET
         
         public virtual void Dispose()
         {
-            NetServices.Instance.Remove(this.Id);
+            NetServices.Instance?.Remove(this.Id);
         }
 
         public abstract void Update();

+ 4 - 4
Unity/Assets/Scripts/Core/World/Module/Fiber/FiberManager.cs

@@ -5,7 +5,7 @@ using System.Threading;
 
 namespace ET
 {
-    public partial class FiberManager: Singleton<FiberManager>, ISingletonAwake
+    public class FiberManager: Singleton<FiberManager>, ISingletonAwake
     {
         private int idGenerator = 10000000; // 10000000以下为保留的用于StartSceneConfig的fiber id, 1个区配置1000个纤程,可以配置10000个区
         private readonly ConcurrentDictionary<int, Fiber> fibers = new();
@@ -45,7 +45,7 @@ namespace ET
         }
         
         // 不允许外部调用,只能由Schecher执行完成一帧调用,否则容易出现多线程问题
-        private void Remove(int id)
+        internal void Remove(int id)
         {
             if (this.fibers.Remove(id, out Fiber fiber))
             {
@@ -53,8 +53,8 @@ namespace ET
             }
         }
 
-        // 不允许外部调用,容易出现多线程问题
-        private Fiber Get(int id)
+        // 不允许外部调用,容易出现多线程问题, 只能通过消息通信,不允许直接获取其它Fiber引用
+        internal Fiber Get(int id)
         {
             this.fibers.TryGetValue(id, out Fiber fiber);
             return fiber;

+ 41 - 44
Unity/Assets/Scripts/Core/World/Module/Scheduler/MainThreadScheduler.cs

@@ -2,70 +2,67 @@
 
 namespace ET
 {
-    public partial class FiberManager: Singleton<FiberManager>
+    public class MainThreadScheduler: Singleton<MainThreadScheduler>, IScheduler, ISingletonAwake
     {
-        public class MainThreadScheduler: Singleton<MainThreadScheduler>, IScheduler, ISingletonAwake
-        {
-            private readonly Queue<int> idQueue = new();
-            private readonly Queue<int> addIds = new();
+        private readonly Queue<int> idQueue = new();
+        private readonly Queue<int> addIds = new();
 
-            public void Awake()
-            {
-            }
+        public void Awake()
+        {
+        }
 
-            public void Update()
+        public void Update()
+        {
+            int count = this.idQueue.Count;
+            while (count-- > 0)
             {
-                int count = this.idQueue.Count;
-                while (count-- == 0)
+                if (!this.idQueue.TryDequeue(out int id))
                 {
-                    if (!this.idQueue.TryDequeue(out int id))
-                    {
-                        continue;
-                    }
+                    continue;
+                }
 
-                    Fiber fiber = FiberManager.Instance.Get(id);
-                    if (fiber == null)
-                    {
-                        continue;
-                    }
+                Fiber fiber = FiberManager.Instance.Get(id);
+                if (fiber == null)
+                {
+                    continue;
+                }
 
-                    this.idQueue.Enqueue(id);
+                this.idQueue.Enqueue(id);
 
-                    fiber.Update();
-                }
+                fiber.Update();
             }
+        }
 
-            public void LateUpdate()
+        public void LateUpdate()
+        {
+            int count = this.idQueue.Count;
+            while (count-- > 0)
             {
-                int count = this.idQueue.Count;
-                while (count-- == 0)
+                if (!this.idQueue.TryDequeue(out int id))
                 {
-                    if (!this.idQueue.TryDequeue(out int id))
-                    {
-                        continue;
-                    }
-
-                    Fiber fiber = FiberManager.Instance.Get(id);
-                    if (fiber == null)
-                    {
-                        continue;
-                    }
-
-                    this.idQueue.Enqueue(id);
-
-                    fiber.LateUpdate();
+                    continue;
                 }
 
-                while (this.addIds.Count > 0)
+                Fiber fiber = FiberManager.Instance.Get(id);
+                if (fiber == null)
                 {
-                    this.idQueue.Enqueue(this.addIds.Dequeue());
+                    continue;
                 }
+
+                this.idQueue.Enqueue(id);
+
+                fiber.LateUpdate();
             }
 
-            public void Add(int fiberId = 0)
+            while (this.addIds.Count > 0)
             {
-                this.addIds.Enqueue(fiberId);
+                this.idQueue.Enqueue(this.addIds.Dequeue());
             }
         }
+
+        public void Add(int fiberId = 0)
+        {
+            this.addIds.Enqueue(fiberId);
+        }
     }
 }

+ 50 - 53
Unity/Assets/Scripts/Core/World/Module/Scheduler/ThreadPoolScheduler.cs

@@ -5,83 +5,80 @@ using System.Threading;
 
 namespace ET
 {
-    public partial class FiberManager: Singleton<FiberManager>
+    public class ThreadPoolScheduler: Singleton<ThreadPoolScheduler>, IScheduler, ISingletonAwake<int>
     {
-        public class ThreadPoolScheduler: Singleton<ThreadPoolScheduler>, IScheduler, ISingletonAwake<int>
-        {
-            private bool isStart;
+        private bool isStart;
 
-            private readonly HashSet<Thread> threads = new();
+        private readonly HashSet<Thread> threads = new();
 
-            private int ThreadCount { get; set; }
+        private int ThreadCount { get; set; }
 
-            private readonly ConcurrentQueue<int> idQueue = new();
+        private readonly ConcurrentQueue<int> idQueue = new();
 
-            public void Awake(int count)
+        public void Awake(int count)
+        {
+            this.isStart = true;
+            this.ThreadCount = count;
+            for (int i = 0; i < this.ThreadCount; ++i)
             {
-                this.isStart = true;
-                this.ThreadCount = count;
-                for (int i = 0; i < this.ThreadCount; ++i)
-                {
-                    this.threads.Add(new Thread(this.Loop));
-                }
+                this.threads.Add(new Thread(this.Loop));
+            }
 
-                foreach (Thread thread in this.threads)
-                {
-                    thread.Start();
-                }
+            foreach (Thread thread in this.threads)
+            {
+                thread.Start();
             }
+        }
 
-            private void Loop()
+        private void Loop()
+        {
+            while (this.isStart)
             {
-                while (this.isStart)
+                try
                 {
-                    try
+                    if (!this.idQueue.TryDequeue(out int id))
                     {
-                        if (!this.idQueue.TryDequeue(out int id))
-                        {
-                            Thread.Sleep(1);
-                            continue;
-                        }
-
-                        Fiber fiber = FiberManager.Instance.Get(id);
-                        if (fiber == null)
-                        {
-                            Thread.Sleep(1);
-                            continue;
-                        }
-
-                        // 执行过的或者正在执行的进程放到队尾
-                        if (fiber.IsRuning)
-                        {
-                            fiber.Update();
-                            fiber.LateUpdate();
-                        }
-
-                        this.idQueue.Enqueue(id);
+                        Thread.Sleep(1);
+                        continue;
+                    }
 
+                    Fiber fiber = FiberManager.Instance.Get(id);
+                    if (fiber == null)
+                    {
                         Thread.Sleep(1);
+                        continue;
                     }
-                    catch (Exception e)
+
+                    // 执行过的或者正在执行的进程放到队尾
+                    if (fiber.IsRuning)
                     {
-                        Log.Error(e);
+                        fiber.Update();
+                        fiber.LateUpdate();
                     }
-                }
-            }
 
-            public override void Destroy()
-            {
-                this.isStart = false;
-                foreach (Thread thread in this.threads)
+                    this.idQueue.Enqueue(id);
+
+                    Thread.Sleep(1);
+                }
+                catch (Exception e)
                 {
-                    thread.Join();
+                    Log.Error(e);
                 }
             }
+        }
 
-            public void Add(int fiberId)
+        public override void Destroy()
+        {
+            this.isStart = false;
+            foreach (Thread thread in this.threads)
             {
-                this.idQueue.Enqueue(fiberId);
+                thread.Join();
             }
         }
+
+        public void Add(int fiberId)
+        {
+            this.idQueue.Enqueue(fiberId);
+        }
     }
 }

+ 33 - 36
Unity/Assets/Scripts/Core/World/Module/Scheduler/ThreadScheduler.cs

@@ -5,58 +5,55 @@ using System.Threading;
 
 namespace ET
 {
-    public partial class FiberManager: Singleton<FiberManager>
+    // 一个Process一个固定的线程
+    public class ThreadScheduler: Singleton<ThreadScheduler>, IScheduler
     {
-        // 一个Process一个固定的线程
-        public class ThreadScheduler: Singleton<ThreadScheduler>, IScheduler
-        {
-            private bool isStart;
+        private bool isStart;
+
+        private readonly ConcurrentDictionary<Fiber, Thread> dictionary = new();
 
-            private readonly ConcurrentDictionary<Fiber, Thread> dictionary = new();
+        public void Awake()
+        {
+            this.isStart = true;
+        }
 
-            public void Awake()
+        private void Loop(int fiberId)
+        {
+            Fiber fiber = FiberManager.Instance.Get(fiberId);
+            if (fiber == null)
             {
-                this.isStart = true;
+                return;
             }
 
-            private void Loop(int fiberId)
+            while (this.isStart)
             {
-                Fiber fiber = FiberManager.Instance.Get(fiberId);
-                if (fiber == null)
+                try
                 {
-                    return;
-                }
+                    fiber.Update();
+                    fiber.LateUpdate();
 
-                while (this.isStart)
-                {
-                    try
-                    {
-                        fiber.Update();
-                        fiber.LateUpdate();
-
-                        Thread.Sleep(1);
-                    }
-                    catch (Exception e)
-                    {
-                        Log.Error(e);
-                    }
+                    Thread.Sleep(1);
                 }
-            }
-
-            public override void Destroy()
-            {
-                this.isStart = false;
-                foreach (var kv in this.dictionary)
+                catch (Exception e)
                 {
-                    kv.Value.Join();
+                    Log.Error(e);
                 }
             }
+        }
 
-            public void Add(int fiberId)
+        public override void Destroy()
+        {
+            this.isStart = false;
+            foreach (var kv in this.dictionary)
             {
-                Thread thread = new(() => this.Loop(fiberId));
-                thread.Start();
+                kv.Value.Join();
             }
         }
+
+        public void Add(int fiberId)
+        {
+            Thread thread = new(() => this.Loop(fiberId));
+            thread.Start();
+        }
     }
 }

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

@@ -23,21 +23,18 @@ namespace ET.Server
             {
                 case AppType.Server:
                 {
-                    FiberManager.ThreadPoolScheduler threadPoolScheduler = World.Instance.AddSingleton<FiberManager.ThreadPoolScheduler, int>(10);
+                    //ThreadPoolScheduler threadPoolScheduler = World.Instance.AddSingleton<ThreadPoolScheduler, int>(10);
                     
                     // 创建进程通信纤程
                     int fiberId = FiberManager.Instance.Create(ConstFiberId.NetInner, SceneType.NetInner);
-                    threadPoolScheduler.Add(fiberId);
+                    MainThreadScheduler.Instance.Add(fiberId);
                     
                     // 根据配置创建纤程
                     var processScenes = StartSceneConfigCategory.Instance.GetByProcess(root.Fiber().Process);
                     foreach (StartSceneConfig startConfig in processScenes)
                     {
                         fiberId = FiberManager.Instance.Create(startConfig.Id, startConfig.Type);
-                        threadPoolScheduler.Add(fiberId);
-
-                        //await SceneFactory.CreateServerScene(serverSceneManagerComponent, startConfig.Id, startConfig.ActorId.InstanceId, startConfig.Zone, startConfig.Name,
-                        //    startConfig.Type, startConfig);
+                        MainThreadScheduler.Instance.Add(fiberId);
                     }
 
                     break;

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

@@ -1,5 +1,4 @@
 using System;
-using ET.Server;
 
 namespace ET
 {

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

@@ -1,6 +1,4 @@
-using ET.Server;
-
-namespace ET
+namespace ET
 {
     [FriendOf(typeof(ActorRecverComponent))]
     public static partial class ActorRecverComponentSystem

+ 10 - 10
Unity/Assets/Scripts/HotfixView/Client/Demo/EntryEvent3_InitClient.cs

@@ -4,22 +4,22 @@ using System.IO;
 namespace ET.Client
 {
     [Event(SceneType.Main)]
-    public class EntryEvent3_InitClient: AEvent<Scene, ET.EventType.EntryEvent3>
+    public class EntryEvent3_InitClient: AEvent<Scene, EventType.EntryEvent3>
     {
-        protected override async ETTask Run(Scene root, ET.EventType.EntryEvent3 args)
+        protected override async ETTask Run(Scene root, EventType.EntryEvent3 args)
         {
             World.Instance.AddSingleton<UIEventComponent>();
-            
-            // 加载配置
-            ResourcesComponent resourcesComponent = root.AddComponent<ResourcesComponent>();
 
+            GlobalComponent globalComponent = root.AddComponent<GlobalComponent>();
+            root.AddComponent<UIGlobalComponent>();
+            root.AddComponent<UIComponent>();
+            ResourcesComponent resourcesComponent = root.AddComponent<ResourcesComponent>();
+            root.AddComponent<ResourcesLoaderComponent>();
+            
             await resourcesComponent.LoadBundleAsync("unit.unity3d");
-
-            GlobalComponent globalComponent = root.GetComponent<GlobalComponent>();
-
-            SceneType sceneType = EnumHelper.FromString<SceneType>(globalComponent.GlobalConfig.AppType.ToString());
-
+            
             // 根据配置修改掉Main Fiber的SceneType
+            SceneType sceneType = EnumHelper.FromString<SceneType>(globalComponent.GlobalConfig.AppType.ToString());
             root.SceneType = sceneType;
             
             await EventSystem.Instance.PublishAsync(root, new EventType.AppStartInitFinish());

+ 0 - 16
Unity/Assets/Scripts/HotfixView/Client/Demo/Scene/FiberInit_DemoView.cs

@@ -1,16 +0,0 @@
-using System.Net;
-
-namespace ET.Server
-{
-    [Invoke((long)SceneType.DemoView)]
-    public class FiberInit_DemoView: AInvokeHandler<FiberInit>
-    {
-        public override void Handle(FiberInit fiberInit)
-        {
-            Scene root = fiberInit.Fiber.Root;
-            
-            StartSceneConfig startSceneConfig = StartSceneConfigCategory.Instance.Get((int)root.Id);
-            root.AddComponent<NetServerComponent, IPEndPoint>(startSceneConfig.InnerIPOutPort);
-        }
-    }
-}

+ 0 - 11
Unity/Assets/Scripts/HotfixView/Client/Demo/Scene/FiberInit_DemoView.cs.meta

@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: 1cde869ba84194644bd0236870eeae1e
-MonoImporter:
-  externalObjects: {}
-  serializedVersion: 2
-  defaultReferences: []
-  executionOrder: 0
-  icon: {instanceID: 0}
-  userData: 
-  assetBundleName: 
-  assetBundleVariant: 

+ 16 - 7
Unity/Assets/Scripts/HotfixView/Client/Demo/Scene/SceneChangeStart_AddComponent.cs

@@ -1,3 +1,4 @@
+using System;
 using UnityEngine.SceneManagement;
 
 namespace ET.Client
@@ -7,18 +8,26 @@ namespace ET.Client
     {
         protected override async ETTask Run(Scene root, EventType.SceneChangeStart args)
         {
-            Scene currentScene = root.CurrentScene();
+            try
+            {
+                Scene currentScene = root.CurrentScene();
 
-            ResourcesComponent resourcesComponent = root.GetComponent<ResourcesComponent>();
+                ResourcesComponent resourcesComponent = root.GetComponent<ResourcesComponent>();
             
-            // 加载场景资源
-            await resourcesComponent.LoadBundleAsync($"{currentScene.Name}.unity3d");
-            // 切换到map场景
+                // 加载场景资源
+                await resourcesComponent.LoadBundleAsync($"{currentScene.Name}.unity3d");
+                // 切换到map场景
 
-            await SceneManager.LoadSceneAsync(currentScene.Name);
+                await SceneManager.LoadSceneAsync(currentScene.Name);
 			
 
-            currentScene.AddComponent<OperaComponent>();
+                currentScene.AddComponent<OperaComponent>();
+            }
+            catch (Exception e)
+            {
+                Log.Error(e);
+            }
+
         }
     }
 }

+ 14 - 9
Unity/Assets/Scripts/Loader/GlobalComponent.cs

@@ -2,20 +2,25 @@ using UnityEngine;
 
 namespace ET
 {
-    public class GlobalComponent: Entity, ISingletonAwake
+    [FriendOf(typeof(GlobalComponent))]
+    public static partial class GlobalComponentSystem
+    {
+        [EntitySystem]
+        public static void Awake(this GlobalComponent self)
+        {
+            self.Global = GameObject.Find("/Global").transform;
+            self.Unit = GameObject.Find("/Global/Unit").transform;
+            self.UI = GameObject.Find("/Global/UI").transform;
+            self.GlobalConfig = Resources.Load<GlobalConfig>("GlobalConfig");
+        }
+    }
+    
+    public class GlobalComponent: Entity, IAwake
     {
         public Transform Global;
         public Transform Unit { get; set; }
         public Transform UI;
 
         public GlobalConfig GlobalConfig { get; set; }
-        
-        public void Awake()
-        {
-            this.Global = GameObject.Find("/Global").transform;
-            this.Unit = GameObject.Find("/Global/Unit").transform;
-            this.UI = GameObject.Find("/Global/UI").transform;
-            this.GlobalConfig = Resources.Load<GlobalConfig>("GlobalConfig");
-        }
     }
 }

+ 2 - 2
Unity/Assets/Scripts/Loader/MonoBehaviour/Init.cs

@@ -29,12 +29,12 @@ namespace ET
 
 		private void Update()
 		{
-			FiberManager.MainThreadScheduler.Instance.Update();
+			MainThreadScheduler.Instance.Update();
 		}
 
 		private void LateUpdate()
 		{
-			FiberManager.MainThreadScheduler.Instance.LateUpdate();
+			MainThreadScheduler.Instance.LateUpdate();
 		}
 
 		private void OnApplicationQuit()

+ 1 - 1
Unity/Assets/Scripts/Model/Share/Entry.cs

@@ -49,7 +49,7 @@ namespace ET
             World.Instance.AddSingleton<ActorMessageDispatcherComponent>();
             World.Instance.AddSingleton<FiberManager>();
             World.Instance.AddSingleton<NetServices>();
-            FiberManager.MainThreadScheduler mainThreadScheduler = World.Instance.AddSingleton<FiberManager.MainThreadScheduler>();
+            MainThreadScheduler mainThreadScheduler = World.Instance.AddSingleton<MainThreadScheduler>();
             
             await World.Instance.AddSingleton<ConfigComponent>().LoadAsync();
             

+ 1 - 1
Unity/ProjectSettings/ProjectSettings.asset

@@ -839,7 +839,7 @@ PlayerSettings:
   webGLDecompressionFallback: 0
   webGLPowerPreference: 2
   scriptingDefineSymbols:
-    Android: UNITY;SINGLE_THREAD
+    Android: UNITY;SINGLE_THREAD;ENABLE_DLL
     Server: UNITY
     Standalone: UNITY;SINGLE_THREAD;ENABLE_VIEW;ENABLE_CODES
     WebGL: UNITY;ENABLE_CODES