Kaynağa Gözat

demo运行成功

tanghai 2 yıl önce
ebeveyn
işleme
33e09df563
23 değiştirilmiş dosya ile 129 ekleme ve 135 silme
  1. 1 1
      DotNet/Loader/RecastFileReader.cs
  2. 1 0
      Unity/Assets/Scripts/Core/World/Module/EventSystem/EventSystem.cs
  3. 8 0
      Unity/Assets/Scripts/Core/World/Module/Navmesh.meta
  4. 42 0
      Unity/Assets/Scripts/Core/World/Module/Navmesh/NavmeshComponent.cs
  5. 1 1
      Unity/Assets/Scripts/Core/World/Module/Navmesh/NavmeshComponent.cs.meta
  6. 9 7
      Unity/Assets/Scripts/Core/World/Module/Scheduler/ThreadScheduler.cs
  7. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Demo/Gate/C2G_EnterMapHandler.cs
  8. 28 0
      Unity/Assets/Scripts/Hotfix/Server/Demo/Map/SceneFactory.cs
  9. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Demo/Map/SceneFactory.cs.meta
  10. 0 2
      Unity/Assets/Scripts/Hotfix/Server/Demo/Realm/C2R_LoginHandler.cs
  11. 0 61
      Unity/Assets/Scripts/Hotfix/Server/Demo/SceneFactory.cs
  12. 0 2
      Unity/Assets/Scripts/Hotfix/Server/Module/Message/NetServerComponentSystem.cs
  13. 0 1
      Unity/Assets/Scripts/Hotfix/Server/Module/Router/RouterComponentSystem.cs
  14. 1 0
      Unity/Assets/Scripts/Hotfix/Share/Demo/EntryEvent1_InitShare.cs
  15. 0 28
      Unity/Assets/Scripts/Hotfix/Share/Module/Recast/NavmeshComponentSystem.cs
  16. 0 11
      Unity/Assets/Scripts/Hotfix/Share/Module/Recast/NavmeshComponentSystem.cs.meta
  17. 1 1
      Unity/Assets/Scripts/Hotfix/Share/Module/Recast/PathfindingComponentSystem.cs
  18. 1 0
      Unity/Assets/Scripts/HotfixView/Client/Demo/EntryEvent3_InitClient.cs
  19. 19 0
      Unity/Assets/Scripts/Loader/RecastFileReader.cs
  20. 1 1
      Unity/Assets/Scripts/Loader/RecastFileReader.cs.meta
  21. 13 1
      Unity/Assets/Scripts/Model/Server/Demo/Gate/GateMapComponent.cs
  22. 1 0
      Unity/Assets/Scripts/Model/Share/Entry.cs
  23. 0 16
      Unity/Assets/Scripts/Model/Share/Module/Recast/NavmeshComponent.cs

+ 1 - 1
Unity/Assets/Scripts/Model/Server/Demo/Map/Recast/RecastFileReader.cs → DotNet/Loader/RecastFileReader.cs

@@ -1,6 +1,6 @@
 using System.IO;
 
-namespace ET.Server
+namespace ET
 {
     [Invoke]
     public class RecastFileReader: AInvokeHandler<NavmeshComponent.RecastFileLoader, byte[]>

+ 1 - 0
Unity/Assets/Scripts/Core/World/Module/EventSystem/EventSystem.cs

@@ -222,6 +222,7 @@ namespace ET
             {
                 throw new Exception($"Invoke error: {typeof(A).Name}");
             }
+            
             if (!invokeHandlers.TryGetValue(type, out var invokeHandler))
             {
                 throw new Exception($"Invoke error: {typeof(A).Name} {type}");

+ 8 - 0
Unity/Assets/Scripts/Core/World/Module/Navmesh.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 7a2d4985eaa40ee49b853ff594ffe06d
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 42 - 0
Unity/Assets/Scripts/Core/World/Module/Navmesh/NavmeshComponent.cs

@@ -0,0 +1,42 @@
+using System;
+using System.Collections.Generic;
+
+namespace ET
+{
+    public class NavmeshComponent: Singleton<NavmeshComponent>, ISingletonAwake
+    {
+        public struct RecastFileLoader
+        {
+            public string Name { get; set; }
+        }
+
+        private readonly Dictionary<string, long> navmeshs = new();
+        
+        public void Awake()
+        {
+        }
+        
+        public long Get(string name)
+        {
+            lock (this)
+            {
+                long ptr;
+                if (this.navmeshs.TryGetValue(name, out ptr))
+                {
+                    return ptr;
+                }
+
+                byte[] buffer = EventSystem.Instance.Invoke<RecastFileLoader, byte[]>(new RecastFileLoader() {Name = name});
+                if (buffer.Length == 0)
+                {
+                    throw new Exception($"no nav data: {name}");
+                }
+
+                ptr = Recast.RecastLoadLong(name.GetHashCode(), buffer, buffer.Length);
+                this.navmeshs[name] = ptr;
+
+                return ptr;
+            }
+        }
+    }
+}

+ 1 - 1
Unity/Assets/Scripts/Model/Share/Module/Recast/NavmeshComponent.cs.meta → Unity/Assets/Scripts/Core/World/Module/Navmesh/NavmeshComponent.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: 3dd047748246dfe448acc5f4ed780928
+guid: f5bfbd4a24f65d34c9fa77337601c17d
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

+ 9 - 7
Unity/Assets/Scripts/Core/World/Module/Scheduler/ThreadScheduler.cs

@@ -8,13 +8,10 @@ namespace ET
     // 一个Process一个固定的线程
     public class ThreadScheduler: Singleton<ThreadScheduler>, IScheduler
     {
-        private bool isStart;
-
         private readonly ConcurrentDictionary<int, Thread> dictionary = new();
 
         public void Awake()
         {
-            this.isStart = true;
         }
 
         private void Loop(int fiberId)
@@ -25,11 +22,11 @@ namespace ET
                 return;
             }
 
-            while (this.isStart)
+            while (true)
             {
                 try
                 {
-                    if (fiber.IsDisposed)
+                    if (this.IsDisposed())
                     {
                         this.dictionary.Remove(fiberId, out _);
                         return;
@@ -49,8 +46,7 @@ namespace ET
 
         protected override void Destroy()
         {
-            this.isStart = false;
-            foreach (var kv in this.dictionary)
+            foreach (var kv in this.dictionary.ToArray())
             {
                 kv.Value.Join();
             }
@@ -58,7 +54,13 @@ namespace ET
 
         public void Add(int fiberId)
         {
+            if (this.IsDisposed())
+            {
+                return;
+            }
+            
             Thread thread = new(() => this.Loop(fiberId));
+            this.dictionary.TryAdd(fiberId, thread);
             thread.Start();
         }
     }

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Demo/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, session.Fiber().IdGenerater.GenerateInstanceId(), SceneType.Map, "GateMap");
+			gateMapComponent.Scene = await SceneFactory.CreateMapScene(gateMapComponent, player.Id, session.Fiber().IdGenerater.GenerateInstanceId(), SceneType.Map, "GateMap");
 
 			Scene scene = gateMapComponent.Scene;
 			

+ 28 - 0
Unity/Assets/Scripts/Hotfix/Server/Demo/Map/SceneFactory.cs

@@ -0,0 +1,28 @@
+using System.Net;
+using System.Net.Sockets;
+
+namespace ET.Server
+{
+    public static partial class SceneFactory
+    {
+        public static async ETTask<Scene> CreateMapScene(Entity parent, long id, long instanceId, SceneType sceneType, string name, StartSceneConfig startSceneConfig = null)
+        {
+            await ETTask.CompletedTask;
+            Scene scene = EntitySceneFactory.CreateScene(parent, id, instanceId, sceneType, name);
+
+            scene.AddComponent<MailBoxComponent, MailBoxType>(MailBoxType.UnOrderedMessage);
+
+            switch (scene.SceneType)
+            {
+                case SceneType.Map:
+                    scene.AddComponent<UnitComponent>();
+                    scene.AddComponent<AOIManagerComponent>();
+                    scene.AddComponent<RoomManagerComponent>();
+                    break;
+            }
+
+            return scene;
+        }
+        
+    }
+}

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Demo/SceneFactory.cs.meta → Unity/Assets/Scripts/Hotfix/Server/Demo/Map/SceneFactory.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: 96900745def5894458850ee0a0da48b5
+guid: c25b0dbf4c6fc204689e2a0b75543509
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

+ 0 - 2
Unity/Assets/Scripts/Hotfix/Server/Demo/Realm/C2R_LoginHandler.cs

@@ -13,11 +13,9 @@ namespace ET.Server
 			StartSceneConfig config = RealmGateAddressHelper.GetGate(session.Zone(), request.Account);
 			Log.Debug($"gate address: {config}");
 			
-			Log.Debug($"1111111111111111111111111111111111111 R2G_GetLoginKey");
 			// 向gate请求一个key,客户端可以拿着这个key连接gate
 			G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey) await session.Fiber().Root.GetComponent<ActorSenderComponent>().Call(
 				config.ActorId, new R2G_GetLoginKey() {Account = request.Account});
-			Log.Debug($"1111111111111111111111111111111111111 G2R_GetLoginKey: {g2RGetLoginKey}");
 
 			response.Address = config.InnerIPOutPort.ToString();
 			response.Key = g2RGetLoginKey.Key;

+ 0 - 61
Unity/Assets/Scripts/Hotfix/Server/Demo/SceneFactory.cs

@@ -1,61 +0,0 @@
-using System.Net;
-using System.Net.Sockets;
-
-namespace ET.Server
-{
-    public static partial class SceneFactory
-    {
-        public static async ETTask<Scene> CreateServerScene(Entity parent, long id, long instanceId, SceneType sceneType, string name, StartSceneConfig startSceneConfig = null)
-        {
-            await ETTask.CompletedTask;
-            Scene scene = EntitySceneFactory.CreateScene(parent, id, instanceId, sceneType, name);
-
-            scene.AddComponent<MailBoxComponent, MailBoxType>(MailBoxType.UnOrderedMessage);
-
-            switch (scene.SceneType)
-            {
-                case SceneType.Router:
-                    scene.AddComponent<RouterComponent, IPEndPoint, string>(startSceneConfig.OuterIPPort,
-                        startSceneConfig.StartProcessConfig.InnerIP
-                    );
-                    break;
-                case SceneType.RouterManager: // 正式发布请用CDN代替RouterManager
-                    // 云服务器在防火墙那里做端口映射
-                    scene.AddComponent<HttpComponent, string>($"http://*:{startSceneConfig.OuterPort}/");
-                    break;
-                case SceneType.Realm:
-                    //scene.AddComponent<NetServerComponent, IPEndPoint>(startSceneConfig.InnerIPOutPort);
-                    break;
-                case SceneType.Gate:
-                    //scene.AddComponent<NetServerComponent, IPEndPoint>(startSceneConfig.InnerIPOutPort);
-                    //scene.AddComponent<PlayerComponent>();
-                    //scene.AddComponent<GateSessionKeyComponent>();
-                    break;
-                case SceneType.Map:
-                    scene.AddComponent<UnitComponent>();
-                    scene.AddComponent<AOIManagerComponent>();
-                    scene.AddComponent<RoomManagerComponent>();
-                    break;
-                case SceneType.Location:
-                    scene.AddComponent<LocationManagerComoponent>();
-                    break;
-                case SceneType.Robot:
-                    //scene.AddComponent<RobotManagerComponent>();
-                    break;
-                case SceneType.BenchmarkServer:
-                    scene.AddComponent<BenchmarkServerComponent>();
-                    //scene.AddComponent<NetServerComponent, IPEndPoint>(startSceneConfig.OuterIPPort);
-                    break;
-                case SceneType.BenchmarkClient:
-                    scene.AddComponent<BenchmarkClientComponent>();
-                    break;
-                case SceneType.Match:
-                    scene.AddComponent<MatchComponent>();
-                    break;
-            }
-
-            return scene;
-        }
-        
-    }
-}

+ 0 - 2
Unity/Assets/Scripts/Hotfix/Server/Module/Message/NetServerComponentSystem.cs

@@ -56,8 +56,6 @@ namespace ET.Server
         
         private static void OnRead(this NetServerComponent self, long channelId, ActorId actorId, object message)
         {
-            Log.Debug($"111111111111111111111111111111111111111 onread");
-            
             Session session = self.GetChild<Session>(channelId);
             if (session == null)
             {

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

@@ -71,7 +71,6 @@ namespace ET.Server
                 try
                 {
                     int messageLength = self.OuterSocket.ReceiveFrom(self.Cache, ref self.IPEndPoint);
-                    Log.Debug($"11111111111111111111111111111111111: router recv: {messageLength}");
                     self.RecvOuterHandler(messageLength, timeNow);
                 }
                 catch (Exception e)

+ 1 - 0
Unity/Assets/Scripts/Hotfix/Share/Demo/EntryEvent1_InitShare.cs

@@ -5,6 +5,7 @@ namespace ET
     {
         protected override async ETTask Run(Scene scene, EventType.EntryEvent1 args)
         {
+            scene.AddComponent<ObjectWait>();
             await ETTask.CompletedTask;
         }
     }

+ 0 - 28
Unity/Assets/Scripts/Hotfix/Share/Module/Recast/NavmeshComponentSystem.cs

@@ -1,28 +0,0 @@
-using System;
-
-namespace ET
-{
-    [FriendOf(typeof(NavmeshComponent))]
-    public static partial class NavmeshComponentSystem
-    {
-        public static long Get(this NavmeshComponent self, string name)
-        {
-            long ptr;
-            if (self.Navmeshs.TryGetValue(name, out ptr))
-            {
-                return ptr;
-            }
-
-            byte[] buffer = EventSystem.Instance.Invoke<NavmeshComponent.RecastFileLoader, byte[]>(new NavmeshComponent.RecastFileLoader() {Name = name});
-            if (buffer.Length == 0)
-            {
-                throw new Exception($"no nav data: {name}");
-            }
-
-            ptr = Recast.RecastLoadLong(name.GetHashCode(), buffer, buffer.Length);
-            self.Navmeshs[name] = ptr;
-
-            return ptr;
-        }
-    }
-}

+ 0 - 11
Unity/Assets/Scripts/Hotfix/Share/Module/Recast/NavmeshComponentSystem.cs.meta

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

+ 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 = self.Root().GetComponent<NavmeshComponent>().Get(name);
+            self.NavMesh = NavmeshComponent.Instance.Get(name);
 
             if (self.NavMesh == 0)
             {

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

@@ -16,6 +16,7 @@ namespace ET.Client
             ResourcesComponent resourcesComponent = root.AddComponent<ResourcesComponent>();
             root.AddComponent<ResourcesLoaderComponent>();
             root.AddComponent<PlayerComponent>();
+            root.AddComponent<CurrentScenesComponent>();
             
             await resourcesComponent.LoadBundleAsync("unit.unity3d");
             

+ 19 - 0
Unity/Assets/Scripts/Loader/RecastFileReader.cs

@@ -0,0 +1,19 @@
+using System;
+using System.IO;
+
+namespace ET
+{
+    [Invoke]
+    public class RecastFileReader: AInvokeHandler<NavmeshComponent.RecastFileLoader, byte[]>
+    {
+        public override byte[] Handle(NavmeshComponent.RecastFileLoader args)
+        {
+            if (Define.IsEditor)
+            {
+                return File.ReadAllBytes(Path.Combine("../Config/Recast", args.Name));
+            }
+
+            throw new Exception("not load");
+        }
+    }
+}

+ 1 - 1
Unity/Assets/Scripts/Model/Server/Demo/Map/Recast/RecastFileReader.cs.meta → Unity/Assets/Scripts/Loader/RecastFileReader.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: 94ac67c4a52bf1e429b8f90205af60d9
+guid: a9ea9883e4f51274c8199ea66cd35c03
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

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

@@ -3,6 +3,18 @@
     [ComponentOf(typeof(Player))]
     public class GateMapComponent: Entity, IAwake
     {
-        public Scene Scene { get; set; }
+        private EntityRef<Scene> scene;
+
+        public Scene Scene
+        {
+            get
+            {
+                return this.scene;
+            }
+            set
+            {
+                this.scene = value;
+            }
+        }
     }
 }

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

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

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

@@ -1,16 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace ET
-{
-    [ComponentOf(typeof(Scene))]
-    public class NavmeshComponent: Entity, IAwake
-    {
-        public struct RecastFileLoader
-        {
-            public string Name { get; set; }
-        }
-        
-        public Dictionary<string, long> Navmeshs = new Dictionary<string, long>();
-    }
-}