进入离开地图
This commit is contained in:
@@ -97,12 +97,18 @@ namespace NBF.Fishing2
|
||||
MapUnit mapUnit = null;
|
||||
foreach (var (_, unit) in self.Units)
|
||||
{
|
||||
var unitUnity = unit.AddComponent<UnitUnityComponent>();
|
||||
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
|
||||
|
||||
@@ -3,7 +3,7 @@ using NBC.Network;
|
||||
using NBC.Network.Interface;
|
||||
using NBF.Fishing2;
|
||||
|
||||
namespace NBF
|
||||
namespace NBF.Fishing2
|
||||
{
|
||||
public class Map2C_ChangeMapHandler : Message<Map2C_ChangeMap>
|
||||
{
|
||||
|
||||
@@ -2,13 +2,28 @@
|
||||
using NBC.Network;
|
||||
using NBC.Network.Interface;
|
||||
|
||||
namespace Fishing2.Map
|
||||
namespace NBF.Fishing2
|
||||
{
|
||||
public class Map2C_RoleEnterMapNotifyHandler : Message<Map2C_RoleEnterRoomNotify>
|
||||
{
|
||||
protected override async FTask Run(Session session, Map2C_RoleEnterRoomNotify message)
|
||||
{
|
||||
Log.Info($"收到进入房间推送 id={message.Info.Id} ");
|
||||
var map = App.Main.GetComponent<Map>();
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,23 @@
|
||||
using NBC.Network;
|
||||
using NBC.Network.Interface;
|
||||
|
||||
namespace Fishing2.Map.Handler
|
||||
namespace NBF.Fishing2
|
||||
{
|
||||
public class Map2C_RoleExitMapNotifyHandler : Message<Map2C_RoleExitRoomNotify>
|
||||
{
|
||||
protected override async FTask Run(Session session, Map2C_RoleExitRoomNotify message)
|
||||
{
|
||||
Log.Info($"收到离开房间推送 id={message.Id} ");
|
||||
var map = App.Main.GetComponent<Map>();
|
||||
if (map == null)
|
||||
{
|
||||
Log.Info("地图不存在,不处理退出请求");
|
||||
return;
|
||||
}
|
||||
if (map.Units.Remove(message.Id, out var unit))
|
||||
{
|
||||
unit.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,12 +35,13 @@ namespace NBF.Fishing2
|
||||
// //创建其他玩家
|
||||
}
|
||||
|
||||
|
||||
public void CreateMapUnit(MapUnitInfo unitInfo)
|
||||
|
||||
public MapUnit CreateMapUnit(MapUnitInfo unitInfo)
|
||||
{
|
||||
var mapUnit = Entity.Create<MapUnit>(Scene, unitInfo.Id, true, true);
|
||||
mapUnit.SetUnitInfo(unitInfo);
|
||||
Add(mapUnit);
|
||||
return mapUnit;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -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<UnitUnityComponent>();
|
||||
if (unitUnity != null)
|
||||
{
|
||||
unitUnity.Dispose();
|
||||
}
|
||||
|
||||
unitUnity = AddComponent<UnitUnityComponent>();
|
||||
await unitUnity.InitUnityObject();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user