From b57cf055c5e111c1ba06c820f872e874014e1a1f Mon Sep 17 00:00:00 2001 From: BobSong <605277374@qq.com> Date: Wed, 10 Sep 2025 10:01:05 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=9B=E5=85=A5=E7=A6=BB=E5=BC=80=E5=9C=B0?= =?UTF-8?q?=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/Fishing2/Helper/MapHelper.cs | 14 ++++++++---- .../Map/Handler/Map2C_ChangeMapHandler.cs | 2 +- .../Map2C_RoleEnterMapNotifyHandler.cs | 17 +++++++++++++- .../Handler/Map2C_RoleExitMapNotifyHandler.cs | 12 +++++++++- Assets/Scripts/Fishing2/Map/Map.cs | 5 +++-- Assets/Scripts/Fishing2/Unit/MapUnit.cs | 19 ++++++++++++++-- .../Fishing2/Unit/Unity/UnitUnityComponent.cs | 5 +++++ UserSettings/EditorUserSettings.asset | 22 +++++++++---------- 8 files changed, 74 insertions(+), 22 deletions(-) diff --git a/Assets/Scripts/Fishing2/Helper/MapHelper.cs b/Assets/Scripts/Fishing2/Helper/MapHelper.cs index bb93a0b90..d2296b684 100644 --- a/Assets/Scripts/Fishing2/Helper/MapHelper.cs +++ b/Assets/Scripts/Fishing2/Helper/MapHelper.cs @@ -97,12 +97,18 @@ namespace NBF.Fishing2 MapUnit mapUnit = null; foreach (var (_, unit) in self.Units) { - var unitUnity = unit.AddComponent(); - await unitUnity.InitUnityObject(); - mapUnit = unit; + await unit.CreateView(); + if (unit.IsSelf()) + { + mapUnit = unit; + } } - self.Scene.EventComponent.Publish(new CameraChangeMode() { Mode = CameraShowMode.Player, Unit = mapUnit }); + if (mapUnit != null) + { + self.Scene.EventComponent.Publish(new CameraChangeMode() + { Mode = CameraShowMode.Player, Unit = mapUnit }); + } } #endregion diff --git a/Assets/Scripts/Fishing2/Map/Handler/Map2C_ChangeMapHandler.cs b/Assets/Scripts/Fishing2/Map/Handler/Map2C_ChangeMapHandler.cs index 4ab4f0c9c..b84c701f5 100644 --- a/Assets/Scripts/Fishing2/Map/Handler/Map2C_ChangeMapHandler.cs +++ b/Assets/Scripts/Fishing2/Map/Handler/Map2C_ChangeMapHandler.cs @@ -3,7 +3,7 @@ using NBC.Network; using NBC.Network.Interface; using NBF.Fishing2; -namespace NBF +namespace NBF.Fishing2 { public class Map2C_ChangeMapHandler : Message { diff --git a/Assets/Scripts/Fishing2/Map/Handler/Map2C_RoleEnterMapNotifyHandler.cs b/Assets/Scripts/Fishing2/Map/Handler/Map2C_RoleEnterMapNotifyHandler.cs index 8529d960b..92e362bd5 100644 --- a/Assets/Scripts/Fishing2/Map/Handler/Map2C_RoleEnterMapNotifyHandler.cs +++ b/Assets/Scripts/Fishing2/Map/Handler/Map2C_RoleEnterMapNotifyHandler.cs @@ -2,13 +2,28 @@ using NBC.Network; using NBC.Network.Interface; -namespace Fishing2.Map +namespace NBF.Fishing2 { public class Map2C_RoleEnterMapNotifyHandler : Message { protected override async FTask Run(Session session, Map2C_RoleEnterRoomNotify message) { Log.Info($"收到进入房间推送 id={message.Info.Id} "); + var map = App.Main.GetComponent(); + if (map == null || !map.IsRoomMap) + { + Log.Info("房间不是好友房间,不处理进入请求"); + return; + } + + var info = message.Info; + var unit = map.GetUnit(info.Id); + if (unit == null) + { + unit = map.CreateMapUnit(info); + } + + await unit.CreateView(); } } } \ No newline at end of file diff --git a/Assets/Scripts/Fishing2/Map/Handler/Map2C_RoleExitMapNotifyHandler.cs b/Assets/Scripts/Fishing2/Map/Handler/Map2C_RoleExitMapNotifyHandler.cs index 71cffe6dc..4c099e0d7 100644 --- a/Assets/Scripts/Fishing2/Map/Handler/Map2C_RoleExitMapNotifyHandler.cs +++ b/Assets/Scripts/Fishing2/Map/Handler/Map2C_RoleExitMapNotifyHandler.cs @@ -2,13 +2,23 @@ using NBC.Network; using NBC.Network.Interface; -namespace Fishing2.Map.Handler +namespace NBF.Fishing2 { public class Map2C_RoleExitMapNotifyHandler : Message { protected override async FTask Run(Session session, Map2C_RoleExitRoomNotify message) { Log.Info($"收到离开房间推送 id={message.Id} "); + var map = App.Main.GetComponent(); + if (map == null) + { + Log.Info("地图不存在,不处理退出请求"); + return; + } + if (map.Units.Remove(message.Id, out var unit)) + { + unit.Dispose(); + } } } } \ No newline at end of file diff --git a/Assets/Scripts/Fishing2/Map/Map.cs b/Assets/Scripts/Fishing2/Map/Map.cs index 7ec8df4fb..df8624ea3 100644 --- a/Assets/Scripts/Fishing2/Map/Map.cs +++ b/Assets/Scripts/Fishing2/Map/Map.cs @@ -35,12 +35,13 @@ namespace NBF.Fishing2 // //创建其他玩家 } - - public void CreateMapUnit(MapUnitInfo unitInfo) + + public MapUnit CreateMapUnit(MapUnitInfo unitInfo) { var mapUnit = Entity.Create(Scene, unitInfo.Id, true, true); mapUnit.SetUnitInfo(unitInfo); Add(mapUnit); + return mapUnit; } /// diff --git a/Assets/Scripts/Fishing2/Unit/MapUnit.cs b/Assets/Scripts/Fishing2/Unit/MapUnit.cs index 6e820fbdb..bceca1dd0 100644 --- a/Assets/Scripts/Fishing2/Unit/MapUnit.cs +++ b/Assets/Scripts/Fishing2/Unit/MapUnit.cs @@ -1,5 +1,4 @@ - -using NBC; +using NBC; using NBC.Entitas; using Unity.Mathematics; using UnityEngine; @@ -77,5 +76,21 @@ namespace NBF.Fishing2 { return Config().Type; } + + #region View + + public async FTask CreateView() + { + var unitUnity = GetComponent(); + if (unitUnity != null) + { + unitUnity.Dispose(); + } + + unitUnity = AddComponent(); + await unitUnity.InitUnityObject(); + } + + #endregion } } \ No newline at end of file diff --git a/Assets/Scripts/Fishing2/Unit/Unity/UnitUnityComponent.cs b/Assets/Scripts/Fishing2/Unit/Unity/UnitUnityComponent.cs index 6e505bce8..2413a0fd3 100644 --- a/Assets/Scripts/Fishing2/Unit/Unity/UnitUnityComponent.cs +++ b/Assets/Scripts/Fishing2/Unit/Unity/UnitUnityComponent.cs @@ -30,6 +30,11 @@ namespace NBF.Fishing2 { protected override void Destroy(UnitUnityComponent self) { + if (self.GameObject != null) + { + Object.Destroy(self.GameObject); + } + self.Animator = null; self.GameObject = null; self.Transform = null; diff --git a/UserSettings/EditorUserSettings.asset b/UserSettings/EditorUserSettings.asset index 9bf89ec73..74460d758 100644 --- a/UserSettings/EditorUserSettings.asset +++ b/UserSettings/EditorUserSettings.asset @@ -9,35 +9,35 @@ EditorUserSettings: value: 18134705175a055722080a3115371d4a0d55006876786860616b0471b8b07a68ffab74f9ee2a3a30300cea1a11320d0beb1a0c25f7060f494b4cc80018eb09361fc211cb1f862d19c51d19dcc413d6ade0d8ddfcddf9f4d9d29195fcfde6ebeae6f0a9c9afa6f8c5b89ff7a1aacececac4eba4d7c9d28bda flags: 0 RecentlyUsedSceneGuid-0: - value: 0704555600540b5d58575c73427b59444515407879792766752b4c66e1b9613e - flags: 0 - RecentlyUsedSceneGuid-1: value: 020056535456585e0f0d0a7541210d441215482c2d297f36752c1b65b3b0376e flags: 0 - RecentlyUsedSceneGuid-2: + RecentlyUsedSceneGuid-1: value: 5607575f01045803555a5b74167b0c4414164e737a2c7060297b4862bbb1636e flags: 0 - RecentlyUsedSceneGuid-3: + RecentlyUsedSceneGuid-2: value: 5b0206565505590b545d5e7240730f4014444a7a7c7876602e7a4f63b2b06468 flags: 0 - RecentlyUsedSceneGuid-4: + RecentlyUsedSceneGuid-3: value: 025005075d000f0c095c0f7145730b4447161e2c787923327a7c4965e0b66669 flags: 0 - RecentlyUsedSceneGuid-5: + RecentlyUsedSceneGuid-4: value: 5703055552020f5a595608704870594445151d7e29292233782f1b36e0e6366c flags: 0 - RecentlyUsedSceneGuid-6: + RecentlyUsedSceneGuid-5: value: 5309035757065a0a54575f7216265c4444151d28792e72627d2f1935bbb8673a flags: 0 - RecentlyUsedSceneGuid-7: + RecentlyUsedSceneGuid-6: value: 5a04020456005d5f5f565b7747720a44474f1e7f7b7c20332b7c4d62b1b6673d flags: 0 - RecentlyUsedSceneGuid-8: + RecentlyUsedSceneGuid-7: value: 5505015f5c515a085f5b092149760f441716407a787d7564287b1b36e7e1366e flags: 0 - RecentlyUsedSceneGuid-9: + RecentlyUsedSceneGuid-8: value: 5254555355510f0b095b557b157108444f164d7e2d707363287b1c65b7b4673c flags: 0 + RecentlyUsedSceneGuid-9: + value: 5a00525654510d0a5b5f5f76497b5e44474f1e7a287875697c7b4967b0b2316f + flags: 0 UnityEditor.ShaderGraph.Blackboard: value: 18135939215a0a5004000b0e15254b524c030a3f2964643d120d1230e9e93a3fd6e826abbd2e2d293c4ead313b08042de6030a0afa240c0d020be94c4ba75e435d8715fa32c70d15d11612dacc11fee5d3c5d1fe9ab1bf968e93e2ffcbc3e7e2f0b3ffe0e8b0be9afeffa9ffff8e85dd8390e2969e8899daa7 flags: 0