mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-06-26 11:24:46 +00:00
53 lines
1.3 KiB
C#
53 lines
1.3 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 void Simulate()
|
|||
|
{
|
|||
|
for (var i = 0; i < allContexts.Length; i++)
|
|||
|
{
|
|||
|
(allContexts[i] as IJNContext)?.OnSyncUpdate();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
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);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|