100 lines
4.5 KiB
C#
100 lines
4.5 KiB
C#
using System.Collections.Generic;
|
|
using CustomDebugger;
|
|
using UnityEngine;
|
|
using UnityGameFramework.Runtime;
|
|
|
|
namespace Simulation
|
|
{
|
|
public sealed partial class SimulationWorld : GameFrameworkComponent
|
|
{
|
|
// Partial layout:
|
|
// - SimulationWorld.cs: 核心状态、常量和 Unity 生命周期入口点。
|
|
// - SimulationWorld.RuntimeModules.cs: 运行时域对象、配置和状态代理。
|
|
// - SimulationWorld.SimEntityState.cs: 模拟状态的增删改查和生命周期注册。
|
|
// - SimulationWorld.EntityToSimData.cs: Unity 实体到 sim data 的初始化适配。
|
|
// - SimulationWorld.EntitySync.cs: GameFramework 实体 show/hide 事件桥。
|
|
// - SimulationWorld.TargetSelectionSpatialIndex.cs: 最近敌空间索引查询。
|
|
// - Presentation/SimulationWorld.TransformSync.cs: late-update transform 同步桥。
|
|
// - Presentation/SimulationWorld.HitPresentation.cs: 投射物命中事件表现桥。
|
|
// - DataChannel/SimulationWorld.JobDataChannel.cs: Job 通道共享字段、常量和运行时状态。
|
|
// - DataChannel/SimulationWorld.JobDataLifecycle.cs: Native 通道初始化、清理和 clear。
|
|
// - DataChannel/SimulationWorld.JobDataConversion.cs: sim/job 数据转换与输入输出缓冲准备。
|
|
// - DataChannel/SimulationWorld.CollisionTransient.cs: 碰撞临时通道和运行时统计。
|
|
// - DataChannel/SimulationWorld.EnemySeparationTemporal.cs: 敌人分离的帧间临时状态。
|
|
// - DataChannel/SimulationWorld.JobOutputCommit.cs: Job 输出回写主容器。
|
|
// - Jobs/SimulationWorld.EnemyJobs.cs: 模拟通道 编排 + 敌人移动/分离 顺序执行
|
|
// - Jobs/SimulationWorld.ProjectileJobs.cs: 投射物移动与回收
|
|
// - Jobs/SimulationWorld.CollisionPipeline.cs: 碰撞管线共享配置和状态
|
|
// - Jobs/SimulationWorld.CollisionRequests.cs: area/sector 请求缓冲
|
|
// - Jobs/SimulationWorld.CollisionBroadPhase.cs: broad-phase 候选构建和 Job 调度
|
|
// - Jobs/SimulationWorld.CollisionResolve.cs: 主线程命中结算与 area settle
|
|
// - Jobs/SimulationWorld.CollisionPresentation.cs: 命中表现事件和实体/impact 解析
|
|
// - JobStruct/*.cs: burst job 内核和面向 job 的数据结构
|
|
private const float DefaultAttackRange = 1f;
|
|
private const int EnemyStateIdle = 0;
|
|
private const int EnemyStateChasing = 1;
|
|
private const int EnemyStateInAttackRange = 2;
|
|
private const int ProjectileStateActive = 0;
|
|
private const int ProjectileStateExpired = 1;
|
|
|
|
[Header("模拟世界全局设置")] [Tooltip("是否启用世界模拟")] [SerializeField]
|
|
private bool _useSimulationMovement = true;
|
|
|
|
private EntitySync _entitySync;
|
|
private TransformSync _transformSync;
|
|
private HitPresentation _hitPresentation;
|
|
|
|
public IReadOnlyList<EnemySimData> Enemies => _enemies;
|
|
public IReadOnlyList<ProjectileSimData> Projectiles => _projectiles;
|
|
public IReadOnlyList<PickupSimData> Pickups => _pickups;
|
|
public bool UseSimulationMovement => _useSimulationMovement;
|
|
|
|
#region Lifecycle
|
|
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
_entitySync = new EntitySync(this);
|
|
_transformSync = new TransformSync(this);
|
|
_hitPresentation = new HitPresentation(this);
|
|
InitializeJobDataChannels();
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
_entitySync?.OnStart();
|
|
_hitPresentation?.OnStart();
|
|
}
|
|
|
|
public void Tick(in SimulationTickContext context)
|
|
{
|
|
if (!_useSimulationMovement)
|
|
{
|
|
return;
|
|
}
|
|
|
|
using (CustomProfilerMarker.TickEnemies.Auto())
|
|
{
|
|
TickSimulationPipeline(in context);
|
|
}
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
_hitPresentation?.OnDestroy();
|
|
_entitySync?.OnDestroy();
|
|
_entitySync = null;
|
|
_transformSync = null;
|
|
_hitPresentation = null;
|
|
DisposeJobDataChannels();
|
|
}
|
|
|
|
private void LateUpdate()
|
|
{
|
|
_transformSync?.OnLateUpdate();
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|