JisolGame/JNFrame2/Assets/JNGame/Sync/App/State/JNSStateServerService.cs
PC-20230316NUNE\Administrator bf7b5b1160 添加线程逻辑执行
2024-09-12 18:06:22 +08:00

59 lines
1.4 KiB
C#

using System;
using JNGame.Sync.Frame;
using UnityEngine;
namespace JNGame.Sync.State
{
/// <summary>
/// 状态同步 [服务器]
/// 服务器负责逻辑层执行并且推送信息到数据层
/// 注:服务器可以有视图层 一般用于debug 发布后没必要有视图层
/// </summary>
public class JNSStateServerService : JNSyncDefaultService
{
//累计待处理时间
protected int dtTime;
//服务器每帧时间
public override int DeltaTime => 1000 / 15;
//是否开始
private bool _isStart = false;
public bool IsStart => _isStart;
public override bool IsStartGame => _isStart;
public override void Initialize()
{
base.Initialize();
_isStart = true;
}
public override void Execute()
{
#if (!ENTITAS_DISABLE_VISUAL_DEBUGGING && UNITY_EDITOR)
if (paused) return;
#endif
if (!IsStart) return;
base.Execute();
dtTime += TickTime;
if (DeltaTime <= dtTime)
{
dtTime -= DeltaTime;
//执行逻辑
OnRunSimulate();
}
}
/// <summary>
/// 运行逻辑
/// </summary>
protected virtual void OnRunSimulate()
{
Simulate();
}
}
}