mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 10:46:17 +00:00
提交Unity 联机Pro
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 248fceb6707f455e85a5c9e3994518af
|
||||
timeCreated: 1722334056
|
@@ -0,0 +1,29 @@
|
||||
using JNGame.Sync.Entity.Component;
|
||||
using NotImplementedException = System.NotImplementedException;
|
||||
|
||||
namespace JNGame.Sync.State.Tile.Entity.Component
|
||||
{
|
||||
/// <summary>
|
||||
/// 拥有区块的组件
|
||||
/// </summary>
|
||||
public class JNTileComponent : JNComponent,IJNTileCycle
|
||||
{
|
||||
|
||||
public bool IsHost {
|
||||
get
|
||||
{
|
||||
if (Entity is IJNTileEntity entity)
|
||||
{
|
||||
return entity.IsHost;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void OnTileEnter(){}
|
||||
|
||||
public virtual void OnTileExit(){}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ca6de04e46e04e6ebb4f4bb7de345e66
|
||||
timeCreated: 1722334062
|
79
JNFrame2/Assets/JNGame/Sync/App/Tile/Entity/JNTileContext.cs
Normal file
79
JNFrame2/Assets/JNGame/Sync/App/Tile/Entity/JNTileContext.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using JNGame.Sync.Entity;
|
||||
using JNGame.Sync.Frame.Entity;
|
||||
using JNGame.Sync.Frame.Entity.Components;
|
||||
|
||||
namespace JNGame.Sync.State.Tile.Entity
|
||||
{
|
||||
|
||||
public class JNTileContext<T> : JNContext<T> where T : JNTileEntity, new()
|
||||
{
|
||||
|
||||
private JNSSTileServerService SyncTile => base.Sync as JNSSTileServerService;
|
||||
|
||||
public override void OnSyncUpdate()
|
||||
{
|
||||
foreach (var entity in base.GetEntities())
|
||||
{
|
||||
|
||||
//生命周期
|
||||
bool isContains = SyncTile.IsContains(entity.Position);
|
||||
bool isHost = entity.IsHost;
|
||||
entity.IsHost = isContains;
|
||||
|
||||
//区块进入生命周期
|
||||
if (!isHost && isContains)
|
||||
{
|
||||
entity.OnTileEnter();
|
||||
}
|
||||
//区块移出生命周期
|
||||
if (isHost && !isContains)
|
||||
{
|
||||
entity.OnTileExit();
|
||||
}
|
||||
|
||||
//判断实体是否在所属区块 在则 更新
|
||||
if (entity.IsHost)
|
||||
{
|
||||
entity.OnSyncUpdate();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public T TileSyncCreate(long id)
|
||||
{
|
||||
var entity = NewEntity();
|
||||
entity.OnInit(this,id);
|
||||
entity.IsHost = false;
|
||||
BindComponent(entity);
|
||||
BindLifeCycle(entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取 有权限的实体
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public T[] GetHostEntities()
|
||||
{
|
||||
if (_entitiesCache is null) return Array.Empty<T>();
|
||||
var items = new List<T>();
|
||||
foreach (var item in _entitiesCache)
|
||||
{
|
||||
if (item.IsHost)
|
||||
{
|
||||
items.Add(item);
|
||||
}
|
||||
}
|
||||
return items.ToArray();
|
||||
}
|
||||
|
||||
protected override T BindInitialize(T entity)
|
||||
{
|
||||
entity.IsHost = true;
|
||||
return base.BindInitialize(entity);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3a7efa2f5ec14741bf38d07ca72008fc
|
||||
timeCreated: 1722325979
|
@@ -0,0 +1,15 @@
|
||||
using Entitas;
|
||||
using JNGame.Sync.Entity;
|
||||
|
||||
namespace JNGame.Sync.State.Tile.Entity
|
||||
{
|
||||
/// <summary>
|
||||
/// 区块实体容器集合
|
||||
/// </summary>
|
||||
public class JNTileContexts : JNContexts
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 469128164a4343638bbf231f78a97ea0
|
||||
timeCreated: 1722325937
|
55
JNFrame2/Assets/JNGame/Sync/App/Tile/Entity/JNTileEntity.cs
Normal file
55
JNFrame2/Assets/JNGame/Sync/App/Tile/Entity/JNTileEntity.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using JNGame.Sync.Entity;
|
||||
using JNGame.Sync.Frame.Entity.Components;
|
||||
using JNGame.Sync.State.Tile.Entity.Component;
|
||||
using JNGame.Sync.System.Data;
|
||||
using NotImplementedException = System.NotImplementedException;
|
||||
|
||||
namespace JNGame.Sync.State.Tile.Entity
|
||||
{
|
||||
|
||||
public interface IJNTileEntity
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 是否所属当前区块
|
||||
/// </summary>
|
||||
public bool IsHost { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 区块同步属性(通过网络同步过来的实体数据)
|
||||
/// </summary>
|
||||
public void TileSyncData(ISTileData data);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 支持区块的实体类 拥有区块生命周期
|
||||
/// </summary>
|
||||
public abstract class JNTileEntity : JNEntity,IJNTileCycle,IJNTileEntity
|
||||
{
|
||||
|
||||
public bool IsHost { get; set; } = false;
|
||||
|
||||
public abstract void TileSyncData(ISTileData data);
|
||||
|
||||
//区块生命周期
|
||||
public virtual void OnTileEnter()
|
||||
{
|
||||
//给组件生命周期
|
||||
foreach (var component in GetComponents())
|
||||
{
|
||||
(component as JNTileComponent)?.OnTileEnter();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void OnTileExit()
|
||||
{
|
||||
//给组件生命周期
|
||||
foreach (var component in GetComponents())
|
||||
{
|
||||
(component as JNTileComponent)?.OnTileExit();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 18ef2e720b964a5a89d45a4ee27ef234
|
||||
timeCreated: 1722324716
|
Reference in New Issue
Block a user