地图相关脚本

This commit is contained in:
2025-09-01 23:57:00 +08:00
parent 1c0b272a6f
commit 48f608e534
26 changed files with 201 additions and 151 deletions

View File

@@ -72,7 +72,7 @@ namespace NBF
/// </summary>
public bool IsMainPlayer;
public Unit Unit;
public MapUnit MapUnit;
// public UnitInfo UnitInfo;
}
}

View File

@@ -6,6 +6,7 @@ namespace NBF.Fishing2
{
public class Map : Entity
{
public int MapId;
/// <summary>
/// 好友房地图
/// </summary>
@@ -14,8 +15,7 @@ namespace NBF.Fishing2
/// <summary>
/// 地图中的单位
/// </summary>
public Dictionary<long, Unit> Units = new Dictionary<long, Unit>();
public Dictionary<long, MapUnit> Units = new Dictionary<long, MapUnit>();
}
}

View File

@@ -10,7 +10,7 @@ namespace NBF
protected override async FTask Run(Session session, Map2C_ChangeMap message)
{
Log.Info($"收到地图切换消息=={message.MapId}");
await MapHelper.LoadMap(message.MapId);
await MapHelper.ChangeMap(message.MapId);
// await MapHelper.CreateRoomTest(message.MapId);
}

View File

@@ -1,9 +0,0 @@
using NBC.Entitas;
namespace NBF.Fishing2
{
public class MapScene : Entity
{
}
}

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: f4087371950b45cb8eaa0933cfbd9bee
timeCreated: 1756365024

View File

@@ -9,24 +9,4 @@ namespace NBF.Fishing2
public long RoomId { get; set; }
public RoleInfo Info { get; set; }
}
public static class RoleSystem
{
public class RoleDestroySystem : DestroySystem<Role>
{
protected override void Destroy(Role self)
{
self.RoomId = 0;
self.Info = null;
}
}
public static async FTask GetRoleInfo(this Role self)
{
var response = (Game2C_GetRoleInfoResponse)await Net.Call(new C2Game_GetRoleInfoRequest());
self.RoomId = response.RoomId;
self.Info = response.RoleInfo;
}
}
}

View File

@@ -1,17 +1,36 @@
using System.Collections.Generic;
using NBC;
using NBC.Entitas;
namespace NBF.Fishing2
{
public static class MapSystem
{
/// <summary>
/// 创建地图单位
/// </summary>
/// <param name="map"></param>
public static void CreteSelfMapUnit(this Map map)
{
//创建自己
var role = map.Scene.GetComponent<Role>();
var mapUnitInfo = role.GetMapUnitInfo();
map.CreteMapUnit(mapUnitInfo);
}
public static void CreteMapUnit(this Map map, MapUnitInfo unitInfo)
{
var mapUnit = Entity.Create<MapUnit>(map.Scene, unitInfo.RoleInfo.RoleId, true, true);
map.Add(mapUnit);
}
/// <summary>
/// 获取一个单位
/// </summary>
/// <param name="self"></param>
/// <param name="id"></param>
/// <returns></returns>
public static Unit GetUnit(this Map self, long id)
public static MapUnit GetUnit(this Map self, long id)
{
return self.Units.GetValueOrDefault(id);
}
@@ -22,9 +41,9 @@ namespace NBF.Fishing2
/// <param name="map"></param>
/// <param name="unit"></param>
/// <returns></returns>
public static async FTask<bool> Enter(this Map map, Unit unit)
public static bool Add(this Map map, MapUnit unit)
{
await FTask.CompletedTask;
map.Units.Add(unit.Id, unit);
return true;
}
@@ -34,10 +53,9 @@ namespace NBF.Fishing2
/// <param name="self"></param>
/// <param name="id"></param>
/// <returns></returns>
public static async FTask<bool> Exit(this Map self, long id)
public static bool Remove(this Map self, long id)
{
await FTask.CompletedTask;
return true;
return self.Units.Remove(id);
}
}
}

View File

@@ -0,0 +1,36 @@
using NBC;
using NBC.Entitas.Interface;
namespace NBF.Fishing2
{
public static class RoleSystem
{
public class RoleDestroySystem : DestroySystem<Role>
{
protected override void Destroy(Role self)
{
self.RoomId = 0;
self.Info = null;
}
}
public static async FTask GetRoleInfo(this Role self)
{
var response = (Game2C_GetRoleInfoResponse)await Net.Call(new C2Game_GetRoleInfoRequest());
self.RoomId = response.RoomId;
self.Info = response.RoleInfo;
}
public static MapUnitInfo GetMapUnitInfo(this Role self)
{
MapUnitInfo mapUnit = new MapUnitInfo();
mapUnit.Id = self.Id;
mapUnit.RoleInfo = new RoleSimpleInfo()
{
};
return mapUnit;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 56a84b9175e14d59ad68a999f549a821
timeCreated: 1756738863

View File

@@ -4,7 +4,7 @@ namespace NBF.Fishing2
{
public static class UnitSystem
{
public static void SetUnitInfo(this Unit self, MapUnitInfo unitInfo)
public static void SetUnitInfo(this MapUnit self, MapUnitInfo unitInfo)
{
NumericComponent numericComponent = self.AddComponent<NumericComponent>();
foreach (var kv in unitInfo.KV)
@@ -13,12 +13,12 @@ namespace NBF.Fishing2
}
}
public static UnitConfig Config(this Unit self)
public static UnitConfig Config(this MapUnit self)
{
return UnitConfig.Get(self.ConfigId);
}
public static UnitType Type(this Unit self)
public static UnitType Type(this MapUnit self)
{
return self.Config().Type;
}

View File

@@ -7,7 +7,7 @@ namespace NBF.Fishing2
/// <summary>
/// 单位
/// </summary>
public class Unit : Entity
public class MapUnit : Entity
{
public int ConfigId { get; set; } //配置表id
@@ -20,7 +20,7 @@ namespace NBF.Fishing2
{
float3 oldPos = position;
position = value;
Scene.EventComponent.Publish(new ChangePosition() { Unit = this, OldPos = oldPos });
Scene.EventComponent.Publish(new ChangePosition() { MapUnit = this, OldPos = oldPos });
}
}
@@ -38,7 +38,7 @@ namespace NBF.Fishing2
set
{
rotation = value;
Scene.EventComponent.Publish(new ChangeRotation() { Unit = this });
Scene.EventComponent.Publish(new ChangeRotation() { MapUnit = this });
}
}
@@ -47,15 +47,15 @@ namespace NBF.Fishing2
public void ChangeState(uint state, string args)
{
Scene.EventComponent.Publish(new ChangeState() { Unit = this, State = state, Args = args });
Scene.EventComponent.Publish(new ChangeState() { MapUnit = this, State = state, Args = args });
}
#region
public static Unit Create(Map map, MapUnitInfo unitInfo, bool isMainPlayer = false)
public static MapUnit Create(Map map, MapUnitInfo unitInfo, bool isMainPlayer = false)
{
var unit = Entity.Create<Unit>(map.Scene, true, true);
var unit = Entity.Create<MapUnit>(map.Scene, true, true);
unit.SetUnitInfo(unitInfo);
return null;
}

View File

@@ -1,9 +0,0 @@
using NBC.Entitas;
namespace NBF.Fishing2
{
public class UnitBasic : Entity
{
}
}

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 19299372f58c4c1db612f36ce60ee238
timeCreated: 1756116063

View File

@@ -4,18 +4,18 @@ namespace NBF.Fishing2
{
public struct ChangePosition
{
public Unit Unit;
public MapUnit MapUnit;
public float3 OldPos;
}
public struct ChangeRotation
{
public Unit Unit;
public MapUnit MapUnit;
}
public struct ChangeState
{
public Unit Unit;
public MapUnit MapUnit;
public uint State;
public string Args;
}

View File

@@ -2,7 +2,7 @@
{
public class UnitStateArgsFactory
{
public static UnitStateArgs Create(Unit unit, string[] args)
public static UnitStateArgs Create(MapUnit mapUnit, string[] args)
{
UnitStateArgs ret = null;
// return new UnitStateArgs()

View File

@@ -1,10 +1,13 @@
using System;
using NBC;
using NBC.Entitas;
namespace NBF.Fishing2
{
public static class MapHelper
{
#region Map
/// <summary>
/// 开始进入地图
/// </summary>
@@ -22,9 +25,9 @@ namespace NBF.Fishing2
//如果有房间
if (roomId > 0)
{
//请求获取房间数据
//加入房间并请求获取房间数据
}
// 等待场景切换完成
await root.GetComponent<ObjectWait>().Wait<Wait_SceneChangeFinish>();
Log.Info($"等待场景切换结束");
@@ -40,19 +43,16 @@ namespace NBF.Fishing2
}
public static async FTask LoadMap(int mapId)
public static async FTask ChangeMap(int mapId)
{
LoadingPanel.Show();
var sceneName = "Map99";
//加载场景==
await SceneHelper.LoadScene(sceneName);
var oldMap = App.Main.GetComponent<Map>();
await oldMap.UnLoadMap();
var map = App.Main.AddComponent<Map>();
FishingPanel.Show();
// 通知等待场景切换的协程
App.Main.GetComponent<ObjectWait>().Notify(new Wait_SceneChangeFinish());
map.MapId = mapId;
await map.LoadMap();
}
public static async FTask CreateRoomTest(int mapId)
@@ -70,5 +70,40 @@ namespace NBF.Fishing2
// });
// Log.Info($"进入房间返回 Code={roomResponse2.RoomCode} 房间玩家数量={roomResponse2.Units.Count}");
}
/// <summary>
/// 卸载旧场景
/// </summary>
/// <param name="self"></param>
public static async FTask UnLoadMap(this Map self)
{
await FTask.CompletedTask;
}
public static async FTask LoadMap(this Map self)
{
var sceneName = "Map99";
//加载场景==
await SceneHelper.LoadScene(sceneName);
self.CreteSelfMapUnit();
await self.LoadAllUnit();
FishingPanel.Show();
// 通知等待场景切换的协程
App.Main.GetComponent<ObjectWait>().Notify(new Wait_SceneChangeFinish());
}
#endregion
#region Unit
/// <summary>
/// 加载所有unit单位
/// </summary>
/// <param name="self"></param>
public static async FTask LoadAllUnit(this Map self)
{
}
#endregion
}
}

View File

@@ -0,0 +1,34 @@
using System.Linq;
using NBC;
namespace NBF.Fishing2
{
public static class ProtoHelper
{
public static MapUnitInfo ToMapUnitInfo(this RoleInfo self)
{
MapUnitInfo mapUnit = new MapUnitInfo();
mapUnit.Id = self.RoleId;
mapUnit.RoleInfo = self.ToSimpleInfo();
mapUnit.Location = new MapUnitPositionInfo();
mapUnit.Gears = self.Gears.First();
mapUnit.FishingInfo = new UnitFishingInfo();
return mapUnit;
}
public static RoleSimpleInfo ToSimpleInfo(this RoleInfo self)
{
var ret = new RoleSimpleInfo();
ret.NickName = self.BaseInfo.NickName;
ret.RoleId = self.RoleId;
ret.Country = self.BaseInfo.Country;
ret.Head = self.BaseInfo.Head;
ret.Level = self.BaseInfo.Level;
ret.Vip = self.BaseInfo.Vip;
return ret;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 850c683faae3419abd3693f7e87accae
timeCreated: 1756738767

View File

@@ -1,10 +1,12 @@
namespace NBF.Fishing2
using NBC;
namespace NBF.Fishing2
{
public static class UnitHelper
{
public static void InitUnit(this Unit self)
public static async FTask InitMapUnit(this MapUnit self)
{
await FTask.CompletedTask;
}
}
}

View File

@@ -28,7 +28,7 @@ namespace NBF.Fishing2
public static void InitGameObject(this UnitUnityComponent self)
{
var unit = self.Parent as Unit;
var unit = self.Parent as MapUnit;
var prefab = PrefabsHelper.CreatePlayer(SceneSettings.Instance.Node);
self.GameObject = prefab;

View File

@@ -147,6 +147,7 @@ namespace NBC
Currency.Clear();
Slots.Clear();
Skills.Clear();
Gears.Clear();
MapId = default;
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<RoleInfo>(this);
@@ -169,6 +170,8 @@ namespace NBC
[ProtoMember(8)]
public List<SkillInfo> Skills = new List<SkillInfo>();
[ProtoMember(9)]
public List<GearInfo> Gears = new List<GearInfo>();
[ProtoMember(10)]
public int MapId { get; set; }
}
/// <summary>
@@ -374,4 +377,27 @@ namespace NBC
[ProtoMember(3)]
public int Exp { get; set; }
}
/// <summary>
/// 玩家当前使用钓组信息
/// </summary>
[ProtoContract]
public partial class GearInfo : AMessage, IProto
{
public static GearInfo Create(Scene scene)
{
return scene.MessagePoolComponent.Rent<GearInfo>();
}
public override void Dispose()
{
Rod = default;
Rigs.Clear();
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<GearInfo>(this);
#endif
}
[ProtoMember(1)]
public long Rod { get; set; }
[ProtoMember(2)]
public List<long> Rigs = new List<long>();
}
}

View File

@@ -9,70 +9,6 @@ using NBC.Serialize;
namespace NBC
{
[ProtoContract]
public partial class UnitGearItemInfo : AMessage, IProto
{
public static UnitGearItemInfo Create(Scene scene)
{
return scene.MessagePoolComponent.Rent<UnitGearItemInfo>();
}
public override void Dispose()
{
Id = default;
ConfigId = default;
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<UnitGearItemInfo>(this);
#endif
}
[ProtoMember(1)]
public long Id { get; set; }
[ProtoMember(2)]
public int ConfigId { get; set; }
}
[ProtoContract]
public partial class UnitGearInfo : AMessage, IProto
{
public static UnitGearInfo Create(Scene scene)
{
return scene.MessagePoolComponent.Rent<UnitGearInfo>();
}
public override void Dispose()
{
Rod = default;
Reel = default;
Bobber = default;
Hook = default;
Bait = default;
Lure = default;
Weight = default;
Line = default;
Leader = default;
Feeder = default;
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<UnitGearInfo>(this);
#endif
}
[ProtoMember(1)]
public UnitGearItemInfo Rod { get; set; }
[ProtoMember(2)]
public UnitGearItemInfo Reel { get; set; }
[ProtoMember(3)]
public UnitGearItemInfo Bobber { get; set; }
[ProtoMember(4)]
public UnitGearItemInfo Hook { get; set; }
[ProtoMember(5)]
public UnitGearItemInfo Bait { get; set; }
[ProtoMember(6)]
public UnitGearItemInfo Lure { get; set; }
[ProtoMember(7)]
public UnitGearItemInfo Weight { get; set; }
[ProtoMember(8)]
public UnitGearItemInfo Line { get; set; }
[ProtoMember(9)]
public UnitGearItemInfo Leader { get; set; }
[ProtoMember(10)]
public UnitGearItemInfo Feeder { get; set; }
}
[ProtoContract]
public partial class Vector3Info : AMessage, IProto
{
@@ -197,7 +133,7 @@ namespace NBC
[ProtoMember(4)]
public UnitStateInfo State { get; set; }
[ProtoMember(5)]
public UnitGearInfo Gears { get; set; }
public GearInfo Gears { get; set; }
[ProtoMember(6)]
public UnitFishingInfo FishingInfo { get; set; }
[ProtoMember(7)]

View File

@@ -203,7 +203,7 @@ namespace NBC
[ProtoMember(1)]
public long Id { get; set; }
[ProtoMember(2)]
public UnitGearInfo Gears { get; set; }
public GearInfo Gears { get; set; }
}
/// <summary>
/// 玩家位置变化

View File

@@ -20,7 +20,7 @@ namespace NBF.Fishing2
public struct NumericChange
{
public Unit Unit;
public MapUnit MapUnit;
public int NumericType;
public long Old;
public long New;
@@ -97,7 +97,7 @@ namespace NBF.Fishing2
if (isPublicEvent)
{
App.Main.EventComponent.Publish(new NumericChange()
{ Unit = self.GetParent<Unit>(), New = value, Old = oldValue, NumericType = numericType });
{ MapUnit = self.GetParent<MapUnit>(), New = value, Old = oldValue, NumericType = numericType });
}
}

View File

@@ -6,6 +6,7 @@
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ABindingFlags_002Ecs_002Fl_003AC_0021_003FUsers_003Fbob_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F9c2967a135e648bdb993c5397a44991b573620_003F94_003F16186629_003FBindingFlags_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACollider_002Ecs_002Fl_003AC_0021_003FUsers_003F60527_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F03ef825315384b1cab81c4b53eb03d922ac00_003Fd1_003Fa6f13559_003FCollider_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACursor_002Ecs_002Fl_003AC_0021_003FUsers_003F60527_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F021f30a9a92b48ce98ae6b39956dd76a1df600_003Fd0_003F709b15ec_003FCursor_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ADictionary_00602_002Ecs_002Fl_003AC_0021_003FUsers_003F60527_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F3789ee403a53437cbb6b5d9ab6311f51573620_003Fe4_003F91da590a_003FDictionary_00602_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AExceptionDispatchInfo_002Ecs_002Fl_003AC_0021_003FUsers_003F60527_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F314938d17f3848e8ac683e11b27f62ee46ae00_003F70_003F17d560d4_003FExceptionDispatchInfo_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AFullScreenMode_002Ecs_002Fl_003AC_0021_003FUsers_003Fbob_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F021f30a9a92b48ce98ae6b39956dd76a1df600_003F7c_003F0044d980_003FFullScreenMode_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AGameObject_002Ecs_002Fl_003AC_0021_003FUsers_003F60527_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F021f30a9a92b48ce98ae6b39956dd76a1df600_003F28_003F384825fa_003FGameObject_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>