修复主从交互bug

This commit is contained in:
DESKTOP-5RP3AKU\Jisol
2024-09-23 03:50:27 +08:00
parent ca64b708ac
commit b65b860b98
55 changed files with 233 additions and 119 deletions

View File

@@ -8,6 +8,8 @@ namespace Game.JNGFrame.Logic.Entity
{
public override IContext[] allContexts { get; } = { new EDNodeContext(),new EDPlayerContext(),new EDBossContext(), };
}
}

View File

@@ -2,6 +2,8 @@
using JNGame.Sync.Frame.Service;
using JNGame.Sync.State.Tile;
using JNGame.Sync.State.Tile.Entity;
using JNGame.Sync.System.Data;
using NotImplementedException = System.NotImplementedException;
namespace Game.Logic.Entity
{
@@ -24,7 +26,17 @@ namespace Game.Logic.Entity
}
return LVector3.Down;
}
public override void TileSyncData(ISTileData data)
{
Transform.Position = data.GetDataPosition();
}
public override void OnTileSlaveExit()
{
base.OnTileSlaveExit();
//从服务器 - 实体移出后立即删除
Destroy();
}
}
}

View File

@@ -34,6 +34,10 @@ namespace Game.JNGFrame.Logic.Entity.Controller
public override void OnSyncStart()
{
//Player 同步到从服务器
TileEntity.IsSyncSlave = true;
base.OnSyncStart();
Move.Speed = LFloat.L10;
}

View File

@@ -1,4 +1,5 @@
using Game.JNGFrame.Logic.Entity.Controller;
using Entitas;
using Game.JNGFrame.Logic.Entity.Controller;
using Game.Logic.Entity.Nodes;
using Game.Logic.Entity.Nodes.Component.Components;
using JNGame.Sync.State.Tile.Entity;
@@ -7,6 +8,7 @@ namespace Game.JNGFrame.Logic.Entity.Contexts
{
public sealed partial class EDPlayerContext : JNTileContext<EDPlayer>
{
protected override EDPlayer BindComponent(EDPlayer entity)
{
base.BindComponent(entity);
@@ -14,5 +16,6 @@ namespace Game.JNGFrame.Logic.Entity.Contexts
entity.AddComponent<EDPlayerController>();
return entity;
}
}
}

View File

@@ -13,12 +13,6 @@ namespace Game.Logic.Entity.Nodes
public EDMoveComponent Move => CLookup.Query<EDMoveComponent>(this);
public EDBossController Controller => CLookup.Query<EDBossController>(this);
public override void TileSyncData(ISTileData data)
{
var nodeData = data as EDBossData;
Transform.Position = nodeData.Value.Position.ToLVector3();
}
public override JNEntityLookup NewCLookup()
{
return new EDBoosLookup();

View File

@@ -12,13 +12,6 @@ namespace Game.Logic.Entity.Nodes
public EDMoveComponent Move => CLookup.Query<EDMoveComponent>(this);
public override void TileSyncData(ISTileData data)
{
var nodeData = data as EDNodeData;
Transform.Position = nodeData.Value.Position.ToLVector3();
}
public override JNEntityLookup NewCLookup()
{
return new EDNodeLookup();

View File

@@ -16,9 +16,9 @@ namespace Game.Logic.Entity.Nodes
public override void TileSyncData(ISTileData data)
{
base.TileSyncData(data);
var nodeData = data as EDPlayerData;
Controller.AuthBind(nodeData.Value.Auth.Value);
Transform.Position = nodeData.Value.Position.ToLVector3();
}
public override JNEntityLookup NewCLookup()

View File

@@ -30,5 +30,11 @@ namespace Game.Logic.System
return LVector3.Down;
}
/// <summary>
/// [状态同步生命周期] 玩家离开服务器 不在游戏线程中执行
/// </summary>
public virtual void OnPlayerExitServer(int auth){}
}
}

View File

@@ -1,6 +1,5 @@
using DotRecast.Core.Collections;
using Game.Input;
using Game.JNGFrame.Logic.Entity;
using Game.JNGFrame.Logic.Entity.Contexts;
using Game.Logic.Entity.Nodes;
using JNGame.Math;
@@ -40,5 +39,20 @@ namespace Game.Logic.System.Logic
});
}
public override void OnPlayerExitServer(int auth)
{
base.OnPlayerExitServer(auth);
NodeContext.GetHostEntities().ForEach(child =>
{
if (child.Controller.Auth == auth)
{
child.DelayDestroy();
}
});
}
}
}

View File

@@ -14,6 +14,9 @@ namespace Game.JNGFrame.View.Entity
public GameObject VWorld => App.Resource.VWorld;
public GameObject Player => App.Resource.Player;
public CinemachineFreeLook FreeLook => App.Resource.FreeLook;
//本地玩家 视图
private GameObject LocalView;
public VDPlayers(SViewSystem root) : base(root)
{
@@ -67,9 +70,20 @@ namespace Game.JNGFrame.View.Entity
public override GameObject NewView(EDPlayerData data)
{
var gameObject = Object.Instantiate(Player, VWorld.transform);
gameObject.name = $"Player_{data.Id}";
return gameObject;
GameObject view;
//如果这个角色是自己 则 直接拿自己的 View
if (App.IsClient() && data.Value.Auth == App.ClientID)
{
if (LocalView is null) LocalView = Object.Instantiate(Player, VWorld.transform);
view = LocalView;
}
else
{
view = Object.Instantiate(Player, VWorld.transform);
}
view.name = $"Player_{data.Id}";
return view;
}
public override EDPlayerData[] GetData()
@@ -80,7 +94,10 @@ namespace Game.JNGFrame.View.Entity
public override void ViewRemove(GameObject view)
{
view.transform.DOKill();
Object.Destroy(view);
if (LocalView != view)
{
Object.Destroy(view);
}
}
}
}