提交进入地图和创建房间相关逻辑和协议
This commit is contained in:
61
Hotfix/Map/System/MapManageComponentSystem.cs
Normal file
61
Hotfix/Map/System/MapManageComponentSystem.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using Fantasy.Entitas;
|
||||
using Fantasy.Entitas.Interface;
|
||||
|
||||
namespace NB.Map;
|
||||
|
||||
public class MapManageComponentDestroySystem : DestroySystem<MapManageComponent>
|
||||
{
|
||||
protected override void Destroy(MapManageComponent self)
|
||||
{
|
||||
foreach (var (_, map) in self.Maps)
|
||||
{
|
||||
map.Dispose();
|
||||
}
|
||||
|
||||
self.Maps.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public class MapManageComponentAwakeSystem : AwakeSystem<MapManageComponent>
|
||||
{
|
||||
protected override void Awake(MapManageComponent self)
|
||||
{
|
||||
//初始化所有地图
|
||||
for (int i = 1; i < 100; i++)
|
||||
{
|
||||
//初始化100个地图
|
||||
var map = MapFactory.Create(self.Scene, i);
|
||||
if (map != null)
|
||||
{
|
||||
self.Add(map);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class MapManageComponentSystem
|
||||
{
|
||||
#region 增删
|
||||
|
||||
public static void Add(this MapManageComponent self, Map map)
|
||||
{
|
||||
self.Maps[map.MapId] = map;
|
||||
}
|
||||
|
||||
public static bool Remove(this MapManageComponent self, int mapId)
|
||||
{
|
||||
if (self.Maps.TryGetValue(mapId, out var map))
|
||||
{
|
||||
map.Dispose();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static Map? Get(this MapManageComponent self, int mapId)
|
||||
{
|
||||
return self.Maps.GetValueOrDefault(mapId);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user