mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-06-26 03:14:47 +00:00
77 lines
2.0 KiB
C#
77 lines
2.0 KiB
C#
|
using System.Collections.Generic;
|
|||
|
using DotRecast.Core.Collections;
|
|||
|
using JNGame.Sync.Entity;
|
|||
|
using JNGame.Sync.Frame.Entity.Components;
|
|||
|
using JNGame.Sync.State.Tile;
|
|||
|
using JNGame.Sync.State.Tile.Entity;
|
|||
|
|
|||
|
namespace JNGame.Sync.System.Data
|
|||
|
{
|
|||
|
|
|||
|
public abstract class ISTileData : ISStateData
|
|||
|
{
|
|||
|
public abstract bool IsHost { get; }
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 支持区块的数据类
|
|||
|
/// </summary>
|
|||
|
public abstract class STileDataSystem<T,E> : SStateDataSystem<T> where T : ISTileData,new() where E : JNTileEntity, new()
|
|||
|
{
|
|||
|
|
|||
|
public abstract JNTileContext<E> NodeContext { get; }
|
|||
|
|
|||
|
protected STileDataSystem(SStateDataEnum type) : base(type)
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
public override void OnUByteUpdate(Dictionary<long, byte[]> bytes)
|
|||
|
{
|
|||
|
base.OnUByteUpdate(bytes);
|
|||
|
if (isServer)
|
|||
|
{
|
|||
|
OnDataSyncContext();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 将数据Data同步到Context
|
|||
|
/// </summary>
|
|||
|
protected virtual void OnDataSyncContext()
|
|||
|
{
|
|||
|
|
|||
|
var lIsTileData = new Dictionary<long, T>(Data);
|
|||
|
|
|||
|
NodeContext.GetEntities().ForEach(child =>
|
|||
|
{
|
|||
|
//如果有则删除
|
|||
|
if (lIsTileData.Remove(child.Id,out var data))
|
|||
|
{
|
|||
|
//并且同步属性到实体中
|
|||
|
child.TileSyncData(data);
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
//将数据同步到实体中
|
|||
|
foreach (var keyValue in lIsTileData)
|
|||
|
{
|
|||
|
var entity = NodeContext.TileSyncCreate(keyValue.Key);
|
|||
|
entity.TileSyncData(keyValue.Value);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
//只更新有权限的实体
|
|||
|
public override void Update(T data)
|
|||
|
{
|
|||
|
if (!data.IsHost) return;
|
|||
|
base.Update(data);
|
|||
|
}
|
|||
|
public override void Add(T data)
|
|||
|
{
|
|||
|
if (!data.IsHost) return;
|
|||
|
base.Add(data);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|