mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-12-09 14:29:42 +00:00
提交Unity 联机Pro
This commit is contained in:
77
JNFrame2/Assets/JNGame/Sync/System/Data/STileDataSystem.cs
Normal file
77
JNFrame2/Assets/JNGame/Sync/System/Data/STileDataSystem.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user