mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-12-09 14:29:42 +00:00
提交Unity 联机Pro
This commit is contained in:
106
JNFrame2/Assets/JNGame/Sync/Entity/JNContext.cs
Normal file
106
JNFrame2/Assets/JNGame/Sync/Entity/JNContext.cs
Normal file
@@ -0,0 +1,106 @@
|
||||
using System;
|
||||
using Entitas;
|
||||
using JNGame.Sync.Entity;
|
||||
using JNGame.Sync.Frame.Entity.Component.Components;
|
||||
using JNGame.Sync.Frame.Entity.Components;
|
||||
using JNGame.Sync.System;
|
||||
|
||||
namespace JNGame.Sync.Frame.Entity
|
||||
{
|
||||
public abstract class JNContext<T> : Entitas.Context<T>,IJNContext where T : JNEntity, new()
|
||||
{
|
||||
|
||||
public JNSyncService Sync { get; private set; }
|
||||
|
||||
public JNEntityLookup CLookup;
|
||||
|
||||
public JNContext(): base((new T()).NewCLookup().Count, () => new T())
|
||||
{
|
||||
CLookup = (new T()).NewCLookup();
|
||||
}
|
||||
|
||||
public JNContext(int totalComponents, Func<T> entityFactory) : base(totalComponents, entityFactory)
|
||||
{
|
||||
}
|
||||
|
||||
public JNContext(int totalComponents, int startCreationIndex, ContextInfo contextInfo, Func<IEntity, IAERC> aercFactory, Func<T> entityFactory) : base(totalComponents, startCreationIndex, contextInfo, aercFactory, entityFactory)
|
||||
{
|
||||
}
|
||||
|
||||
public JNSyncService GetSync()
|
||||
{
|
||||
return Sync;
|
||||
}
|
||||
|
||||
public void InitReference(JNSyncService data)
|
||||
{
|
||||
Sync = data;
|
||||
}
|
||||
|
||||
public T GetService<T>() where T : SLogicSystem
|
||||
{
|
||||
return Sync.GetSystem<T>();
|
||||
}
|
||||
|
||||
protected T NewEntity()
|
||||
{
|
||||
|
||||
T entity = base.CreateEntity();
|
||||
//绑定组件查询器
|
||||
entity.CLookup = CLookup;
|
||||
return entity;
|
||||
|
||||
}
|
||||
|
||||
protected virtual T BindInitialize(T entity)
|
||||
{
|
||||
entity.OnInit(this);
|
||||
return entity;
|
||||
}
|
||||
protected virtual T BindComponent(T entity)
|
||||
{
|
||||
entity.AddComponent<JNTransformComponent>();
|
||||
return entity;
|
||||
}
|
||||
protected virtual T BindLifeCycle(T entity)
|
||||
{
|
||||
entity.OnSyncStart();
|
||||
return entity;
|
||||
}
|
||||
|
||||
public sealed override T CreateEntity()
|
||||
{
|
||||
var entity = NewEntity();
|
||||
BindInitialize(entity);
|
||||
BindComponent(entity);
|
||||
BindLifeCycle(entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
//帧同步 生命周期
|
||||
public virtual void OnSyncStart(){}
|
||||
|
||||
public virtual void OnSyncUpdate()
|
||||
{
|
||||
//给实体推帧
|
||||
foreach (var entity in GetEntities())
|
||||
{
|
||||
if (entity.isEnabled)
|
||||
{
|
||||
entity.OnSyncUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void OnSyncDestroy()
|
||||
{}
|
||||
}
|
||||
|
||||
public interface IJNContext : IJNSyncCycle
|
||||
{
|
||||
public abstract JNSyncService GetSync();
|
||||
public abstract void InitReference(JNSyncService data);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user