feat: 补全实体属性暴露,让 Unity 前端可直接访问所有运行时数据

引擎层:
- 新增 Platforms 列表 (SimulationEngine.Platforms)
- EntitySnapshot 新增 VelX/VelY/VelZ 速度字段
- CollectSnapshots 收集所有实体类型(含 Munition/Detection)

CloudEntity: Pos/Radius/Density/Phase/Elapsed 便捷属性
MunitionEntity: Start/LaunchTime/ElapsedTime + Velocity 瞬时速度
DroneEntity: TraveledArc/TotalArc/Progress 航程进度
PlatformEntity: Target/FlightDistance/FlownDistance 飞行目标
DetectionEntity: PosX/Y/Z 位置(从 Source.Position)
This commit is contained in:
tian 2026-06-17 12:16:37 +08:00
parent ff830c1221
commit 3bb6e7a091
7 changed files with 60 additions and 4 deletions

View File

@ -12,6 +12,14 @@ namespace CounterDrone.Core.Simulation
public float CreatedAt { get; }
public bool IsDissipated => Dispersion.IsDissipated;
public float PosX => Dispersion.Center.X;
public float PosY => Dispersion.Center.Y;
public float PosZ => Dispersion.Center.Z;
public float Radius => Dispersion.Radius;
public float Density => Dispersion.CoreDensity;
public int Phase => Dispersion.Phase;
public float Elapsed => Dispersion.Elapsed;
public CloudEntity(string id, AerosolType aerosolType, ICloudDispersionModel dispersion, float createdAt)
{
Id = id;

View File

@ -12,6 +12,9 @@ namespace CounterDrone.Core.Simulation
{
public string Id { get; }
public DetectionSource Source { get; }
public float PosX => Source.Position.X;
public float PosY => Source.Position.Y;
public float PosZ => Source.Position.Z;
/// <summary>每无人机 Id → 探测状态true=Detected, false=Undetected</summary>
private readonly Dictionary<string, bool> _droneStates = new();

View File

@ -24,6 +24,10 @@ namespace CounterDrone.Core.Simulation
public float PrevX { get; private set; }
public float PrevY { get; private set; }
public float PrevZ { get; private set; }
public float TraveledArc => _traveledArc;
public float TotalArc => _totalArc;
public float Progress => _totalArc > 0 ? _traveledArc / _totalArc : 0f;
/// <summary>沿航路已飞行弧长(米),由 RouteGeometry 驱动</summary>
private float _traveledArc;
/// <summary>航路总弧长(米),构造时一次性算好(航路静态,无需每帧重算)</summary>

View File

@ -24,6 +24,26 @@ namespace CounterDrone.Core.Simulation
public float Azimuth { get; }
public float MuzzleVelocity { get; }
public float FlightDuration { get; private set; }
public float StartX => _startX;
public float StartY => _startY;
public float StartZ => _startZ;
public float LaunchTime => _launchTime;
public float ElapsedTime => _time;
public (float Vx, float Vy, float Vz) Velocity
{
get
{
float cosA = (float)System.Math.Cos(LaunchAngle);
float sinA = (float)System.Math.Sin(LaunchAngle);
float sinAz = (float)System.Math.Sin(Azimuth);
float cosAz = (float)System.Math.Cos(Azimuth);
float vx = MuzzleVelocity * cosA * sinAz;
float vy = MuzzleVelocity * sinA - 9.81f * _time;
float vz = MuzzleVelocity * cosA * cosAz;
return (vx, vy, vz);
}
}
private readonly float _startX, _startY, _startZ;
private readonly float _launchTime;

View File

@ -34,6 +34,12 @@ namespace CounterDrone.Core.Simulation
public float ExactReleaseTime => _exactReleaseTime;
private float _exactReleaseTime;
public float TargetX => _targetX;
public float TargetY => _targetY;
public float TargetZ => _targetZ;
public float FlightDistance => _flightDistance;
public float FlownDistance => _flownDistance;
// 地基平台
public float MuzzleVelocity { get; }

View File

@ -38,6 +38,8 @@ namespace CounterDrone.Core.Simulation
public int CloudPhase;
public float CloudElapsed;
public float VelX, VelY, VelZ;
/// <summary>仅 Flush 入库时使用,仿真期间保持 null</summary>
public string? StateData;
}

View File

@ -26,6 +26,7 @@ namespace CounterDrone.Core.Simulation
public IReadOnlyList<DroneEntity> Drones => _drones;
public IReadOnlyList<CloudEntity> Clouds => _clouds;
public IReadOnlyList<PlatformEntity> Platforms => _platforms;
public IReadOnlyList<MunitionEntity> Munitions => _munitions;
public IReadOnlyList<DetectionEntity> DetectionEntities => _detectionEntities;
public IReadOnlyList<SimEvent> Events => _allEvents;
@ -503,18 +504,30 @@ namespace CounterDrone.Core.Simulation
for (int i = 0; i < _drones.Count; i++)
{
var d = _drones[i];
_snapshotPool.Add(new EntitySnapshot { EntityId = d.Id, EntityType = Models.EntityType.Drone, PosX = d.PosX, PosY = d.PosY, PosZ = d.PosZ, DamageStage = (int)_damageModel.GetDamageStage(1 - d.Hp), Hp = d.Hp });
float vx = d.PosX - d.PrevX, vy = d.PosY - d.PrevY, vz = d.PosZ - d.PrevZ;
_snapshotPool.Add(new EntitySnapshot { EntityId = d.Id, EntityType = Models.EntityType.Drone, PosX = d.PosX, PosY = d.PosY, PosZ = d.PosZ, VelX = vx, VelY = vy, VelZ = vz, DamageStage = (int)_damageModel.GetDamageStage(1 - d.Hp), Hp = d.Hp });
}
for (int i = 0; i < _munitions.Count; i++)
{
var m = _munitions[i];
var (vx, vy, vz) = m.Velocity;
_snapshotPool.Add(new EntitySnapshot { EntityId = m.Id, EntityType = Models.EntityType.Munition, PosX = m.PosX, PosY = m.PosY, PosZ = m.PosZ, VelX = vx, VelY = vy, VelZ = vz });
}
for (int i = 0; i < _platforms.Count; i++)
{
var p = _platforms[i];
if (p.PlatformType != Models.PlatformType.AirBased) continue;
_snapshotPool.Add(new EntitySnapshot { EntityId = p.Id, EntityType = Models.EntityType.Platform, PosX = p.PosX, PosY = p.PosY, PosZ = p.PosZ, PlatformStateStr = p.State.ToString() });
var (vx, vy, vz) = p.CurrentVelocity;
_snapshotPool.Add(new EntitySnapshot { EntityId = p.Id, EntityType = Models.EntityType.Platform, PosX = p.PosX, PosY = p.PosY, PosZ = p.PosZ, VelX = vx, VelY = vy, VelZ = vz, PlatformStateStr = p.State.ToString() });
}
for (int i = 0; i < _detectionEntities.Count; i++)
{
var d = _detectionEntities[i];
_snapshotPool.Add(new EntitySnapshot { EntityId = d.Id, EntityType = Models.EntityType.DetectionEquip, PosX = d.PosX, PosY = d.PosY, PosZ = d.PosZ });
}
for (int i = 0; i < _clouds.Count; i++)
{
var c = _clouds[i];
_snapshotPool.Add(new EntitySnapshot { EntityId = c.Id, EntityType = Models.EntityType.Cloud, PosX = c.Dispersion.Center.X, PosY = c.Dispersion.Center.Y, PosZ = c.Dispersion.Center.Z, CloudRadius = c.Dispersion.Radius, CloudOpacity = c.Dispersion.Particles.Opacity, CloudPhase = c.Dispersion.Phase, CloudElapsed = c.Dispersion.Elapsed });
_snapshotPool.Add(new EntitySnapshot { EntityId = c.Id, EntityType = Models.EntityType.Cloud, PosX = c.PosX, PosY = c.PosY, PosZ = c.PosZ, CloudRadius = c.Radius, CloudOpacity = c.Dispersion.Particles.Opacity, CloudPhase = c.Phase, CloudElapsed = c.Elapsed });
}
return _snapshotPool;
}