mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-06-26 19:34:47 +00:00
59 lines
1.5 KiB
C#
59 lines
1.5 KiB
C#
using System;
|
|
using Entitas;
|
|
using JNGame.Sync.Frame.Entity;
|
|
|
|
namespace JNGame.Sync.Entity
|
|
{
|
|
public class JNContexts : Entitas.IContexts
|
|
{
|
|
public virtual IContext[] allContexts => Array.Empty<IContext>();
|
|
|
|
public JNSyncService Sync;
|
|
|
|
public JNContexts()
|
|
{
|
|
for (var i = 0; i < allContexts.Length; i++)
|
|
{
|
|
(allContexts[i] as IJNContext)?.OnSyncStart();
|
|
}
|
|
}
|
|
|
|
//给所有实体推帧
|
|
public virtual void Simulate()
|
|
{
|
|
for (var i = 0; i < allContexts.Length; i++)
|
|
{
|
|
(allContexts[i] as IJNContext)?.OnSyncUpdate(Sync.DeltaTime);
|
|
}
|
|
|
|
//延迟销毁
|
|
for (var i = 0; i < allContexts.Length; i++)
|
|
{
|
|
(allContexts[i] as IJNContext)?.DelayDestroy();
|
|
}
|
|
}
|
|
|
|
public T GetContext<T>() where T : IContext
|
|
{
|
|
|
|
for (int i = 0; i < allContexts.Length; i++)
|
|
{
|
|
if (allContexts[i] is T) return (T)allContexts[i];
|
|
}
|
|
|
|
throw new InvalidOperationException($"No context of type {typeof(T).Name} was found.");
|
|
|
|
}
|
|
|
|
//注入 JNSyncFrameService
|
|
public void InitReference(JNSyncService data)
|
|
{
|
|
Sync = data;
|
|
foreach (var context in allContexts)
|
|
{
|
|
(context as IJNContext)?.InitReference(data);
|
|
}
|
|
}
|
|
|
|
}
|
|
} |