更新使用说明、文档、示例
This commit is contained in:
parent
699edfdf83
commit
7c973dbe8f
@ -14,7 +14,6 @@
|
||||
- 处理不同时间步长的协调
|
||||
- dll 库的接口有效性验证
|
||||
- 所有威胁源的参数规范化,增加默认参数配置
|
||||
- 同步 dll 库的文档,api 文档、使用说明、工作原理
|
||||
- 规范第三方仿真环境使用 dll 库的场景和事件类型
|
||||
|
||||
## [1.1.22] - 2025-05-26
|
||||
@ -24,7 +23,9 @@
|
||||
- 完善了导引头的朝向控制逻辑和导弹的朝向控制逻辑
|
||||
- 给装备增加了可选参数
|
||||
- 完善了末敏弹子弹的朝向和传感器运动状态
|
||||
- 增加了命中概率的计算和实现
|
||||
- 增加了导弹运动状态的随机噪声,并根据飞行阶段设置不同的噪声系数
|
||||
- 同步 dll 库的文档,api 文档、使用说明、工作原理
|
||||
|
||||
## [1.1.21] - 2025-05-24
|
||||
- 增加了升力加速度的计算
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
using Tomlyn;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
|
||||
namespace ThreatSource.Data
|
||||
{
|
||||
@ -16,9 +17,15 @@ namespace ThreatSource.Data
|
||||
public class ThreatSourceDataManager
|
||||
{
|
||||
/// <summary>
|
||||
/// 默认数据目录路径
|
||||
/// 默认数据目录名称
|
||||
/// </summary>
|
||||
private static readonly string DATA_PATH = "../data";
|
||||
private static readonly string DEFAULT_DATA_FOLDER = "data";
|
||||
|
||||
/// <summary>
|
||||
/// 回退数据目录路径(向后兼容)
|
||||
/// </summary>
|
||||
private static readonly string FALLBACK_DATA_PATH = "data";
|
||||
|
||||
private static readonly TomlModelOptions _tomlOptions = new()
|
||||
{
|
||||
ConvertPropertyName = name => name
|
||||
@ -30,16 +37,71 @@ namespace ThreatSource.Data
|
||||
private readonly Dictionary<string, EquipmentData> _equipments = [];
|
||||
private readonly Dictionary<string, WeatherData> _weathers = [];
|
||||
private readonly Dictionary<string, JammerData> _jammers = [];
|
||||
|
||||
/// <summary>
|
||||
/// 获取数据目录路径
|
||||
/// 优先使用DLL上级目录的data文件夹,如果不存在则回退到相对路径
|
||||
/// </summary>
|
||||
/// <returns>数据目录的绝对路径</returns>
|
||||
private static string GetDataPath()
|
||||
{
|
||||
try
|
||||
{
|
||||
// 获取当前程序集(DLL)的位置
|
||||
var assemblyLocation = Assembly.GetExecutingAssembly().Location;
|
||||
if (!string.IsNullOrEmpty(assemblyLocation))
|
||||
{
|
||||
// 获取DLL所在目录的父目录
|
||||
var dllDirectory = Path.GetDirectoryName(assemblyLocation);
|
||||
if (!string.IsNullOrEmpty(dllDirectory))
|
||||
{
|
||||
var parentDirectory = Directory.GetParent(dllDirectory)?.FullName;
|
||||
if (!string.IsNullOrEmpty(parentDirectory))
|
||||
{
|
||||
var dataPath = Path.Combine(parentDirectory, DEFAULT_DATA_FOLDER);
|
||||
|
||||
Debug.WriteLine($"[ThreatSourceDataManager] DLL位置: {assemblyLocation}");
|
||||
Debug.WriteLine($"[ThreatSourceDataManager] 解析的data目录: {dataPath}");
|
||||
|
||||
if (Directory.Exists(dataPath))
|
||||
{
|
||||
Debug.WriteLine($"[ThreatSourceDataManager] 使用自动解析的data目录: {dataPath}");
|
||||
return dataPath;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.WriteLine($"[ThreatSourceDataManager] 自动解析的data目录不存在: {dataPath}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine($"[ThreatSourceDataManager] 自动路径解析失败: {ex.Message}");
|
||||
}
|
||||
|
||||
// 回退到原始的相对路径(向后兼容)
|
||||
Debug.WriteLine($"[ThreatSourceDataManager] 回退使用相对路径: {FALLBACK_DATA_PATH}");
|
||||
return FALLBACK_DATA_PATH;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化威胁源数据管理器
|
||||
/// </summary>
|
||||
/// <param name="dataPath">可选的数据目录路径</param>
|
||||
/// <param name="dataPath">可选的数据目录路径,如果为null则使用智能路径解析</param>
|
||||
public ThreatSourceDataManager(string? dataPath = null)
|
||||
{
|
||||
if (dataPath != null)
|
||||
{
|
||||
Debug.WriteLine($"[ThreatSourceDataManager] 使用用户指定的data路径: {dataPath}");
|
||||
LoadData(dataPath);
|
||||
}
|
||||
else
|
||||
LoadData(DATA_PATH);
|
||||
{
|
||||
var resolvedPath = GetDataPath();
|
||||
LoadData(resolvedPath);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -48,6 +110,8 @@ namespace ThreatSource.Data
|
||||
/// <param name="path">数据目录路径</param>
|
||||
private void LoadData(string path)
|
||||
{
|
||||
Debug.WriteLine($"[ThreatSourceDataManager] 开始从路径加载数据: {Path.GetFullPath(path)}");
|
||||
|
||||
LoadMissiles(Path.Combine(path, "missiles"));
|
||||
LoadIndicators(Path.Combine(path, "indicators"));
|
||||
LoadWarners(Path.Combine(path, "warners"));
|
||||
|
||||
@ -1,23 +1,66 @@
|
||||
# 入门指南
|
||||
# 使用说明
|
||||
|
||||
**版本:1.1.22**
|
||||
|
||||
## 安装和使用
|
||||
|
||||
### C#/.NET 版本
|
||||
|
||||
#### 1. 下载和部署
|
||||
|
||||
1. 下载 ThreatSourceLibrary 包并解压
|
||||
2. 将以下文件复制到你的项目目录(建议放在 lib 文件夹下):
|
||||
- ThreatSource.dll - 主要的库文件
|
||||
- ThreatSource.deps.json - 依赖配置文件
|
||||
- ThreatSource.xml - API 文档文件
|
||||
2. 按照以下标准结构部署文件:
|
||||
|
||||
```
|
||||
MyApplication/
|
||||
├── MyApp.exe # 您的应用程序
|
||||
├── lib/ # DLL库目录
|
||||
│ ├── ThreatSource.dll # 主要的库文件
|
||||
│ ├── ThreatSource.deps.json # 依赖配置文件
|
||||
│ ├── ThreatSource.xml # API 文档文件
|
||||
│ └── AirTransmission.dll # 依赖库
|
||||
└── data/ # 配置数据目录
|
||||
├── missiles/ # 导弹配置文件
|
||||
│ ├── laser_semi_active/
|
||||
│ ├── laser_beam_rider/
|
||||
│ ├── ir_command/
|
||||
│ ├── ir_imaging/
|
||||
│ ├── mmw/
|
||||
│ ├── terminal_sensitive/
|
||||
│ └── composite/
|
||||
├── indicators/ # 指示器配置文件
|
||||
│ ├── laser_designators/
|
||||
│ ├── laser_beam_riders/
|
||||
│ └── ir_trackers/
|
||||
├── equipments/ # 目标设备配置文件
|
||||
├── jammers/ # 干扰机配置文件
|
||||
├── weathers/ # 天气配置文件
|
||||
└── warners/ # 告警器配置文件
|
||||
```
|
||||
|
||||
3. 在 Visual Studio 中添加引用:
|
||||
- 右键项目 -> 添加 -> 引用
|
||||
- 浏览 -> 选择 ThreatSource.dll
|
||||
- 浏览 -> 选择 lib/ThreatSource.dll
|
||||
|
||||
4. 在代码中使用:
|
||||
#### 2. 数据配置管理
|
||||
|
||||
威胁源库使用智能路径解析系统,会自动在DLL上级目录查找 `data` 文件夹。您也可以手动指定数据路径:
|
||||
|
||||
```csharp
|
||||
// 使用自动路径解析(推荐)
|
||||
var dataManager = new ThreatSourceDataManager();
|
||||
|
||||
// 或手动指定数据路径
|
||||
var dataManager = new ThreatSourceDataManager("C:/MyApp/configs");
|
||||
```
|
||||
|
||||
#### 3. 基本使用示例
|
||||
|
||||
```csharp
|
||||
using ThreatSource.Simulation;
|
||||
using ThreatSource.Data;
|
||||
using ThreatSource.Equipment;
|
||||
using ThreatSource.Utils;
|
||||
|
||||
class Program
|
||||
{
|
||||
@ -25,46 +68,76 @@ class Program
|
||||
{
|
||||
try
|
||||
{
|
||||
// 创建仿真管理器
|
||||
// 1. 创建仿真管理器
|
||||
var simulationManager = new SimulationManager();
|
||||
|
||||
// 创建导弹配置
|
||||
var missileProperties = new MissileProperties
|
||||
// 2. 创建数据管理器和工厂
|
||||
var dataManager = new ThreatSourceDataManager();
|
||||
var factory = new ThreatSourceFactory(dataManager, simulationManager);
|
||||
|
||||
// 3. 创建目标
|
||||
var targetInitialState = new KinematicState
|
||||
{
|
||||
Id = "missile1",
|
||||
InitialPosition = new Vector3D(0, 0, 0),
|
||||
InitialVelocity = new Vector3D(0, 0, 0),
|
||||
MaxSpeed = 1000,
|
||||
MaxAcceleration = 10,
|
||||
MaxFlightTime = 30,
|
||||
MaxFlightDistance = 5000,
|
||||
Mass = 50
|
||||
Position = new Vector3D(1000, 0, 100),
|
||||
Orientation = new Orientation(0, 0, 0),
|
||||
Speed = 0
|
||||
};
|
||||
|
||||
// 创建导弹实例
|
||||
var missile = new TerminalSensitiveMissile(
|
||||
"target1",
|
||||
missileProperties,
|
||||
simulationManager
|
||||
);
|
||||
var targetProperties = new EquipmentProperties
|
||||
{
|
||||
InfraredRadiationIntensity = 100.0,
|
||||
MillimeterWaveRadiationIntensity = 50.0
|
||||
};
|
||||
|
||||
// 注册实体
|
||||
var target = new Tank("target1", targetProperties, targetInitialState, simulationManager);
|
||||
|
||||
// 4. 创建导弹(使用工厂模式)
|
||||
var launchParams = new KinematicState
|
||||
{
|
||||
Position = new Vector3D(0, 0, 0),
|
||||
Orientation = new Orientation(0, 0, 0),
|
||||
Speed = 100
|
||||
};
|
||||
|
||||
// 使用配置文件中的导弹型号
|
||||
var missile = factory.CreateMissile("missile1", "lsgm_001", "target1", launchParams);
|
||||
|
||||
// 5. 注册实体到仿真管理器
|
||||
simulationManager.RegisterEntity(target.Id, target);
|
||||
simulationManager.RegisterEntity(missile.Id, missile);
|
||||
|
||||
// 激活并发射导弹
|
||||
// 6. 激活实体
|
||||
target.Activate();
|
||||
missile.Activate();
|
||||
|
||||
// 7. 发射导弹
|
||||
missile.Fire();
|
||||
|
||||
// 仿真主循环
|
||||
double deltaTime = 0.01;
|
||||
while (missile.IsActive)
|
||||
// 8. 启动仿真
|
||||
simulationManager.StartSimulation(0.01); // 10ms时间步长
|
||||
|
||||
// 9. 仿真主循环
|
||||
double totalTime = 0;
|
||||
double maxTime = 60; // 最大仿真时间60秒
|
||||
|
||||
while (missile.IsActive && totalTime < maxTime)
|
||||
{
|
||||
missile.Update(deltaTime);
|
||||
simulationManager.Update(0.01);
|
||||
totalTime += 0.01;
|
||||
|
||||
// 可选:输出状态信息
|
||||
if ((int)(totalTime * 100) % 100 == 0) // 每秒输出一次
|
||||
{
|
||||
Console.WriteLine($"时间: {totalTime:F1}s, 导弹位置: {missile.KState.Position}");
|
||||
}
|
||||
}
|
||||
|
||||
// 10. 停止仿真
|
||||
simulationManager.StopSimulation();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Trace.TraceError($"Error: {ex.Message}");
|
||||
Console.WriteLine($"错误: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -81,7 +154,7 @@ C++项目有两种使用方式:
|
||||
1. 下载 ThreatSourceNative 包并解压
|
||||
2. 将 bin 目录下的所有 DLL 文件复制到程序目录
|
||||
3. 将 include/threat_source.h 添加到项目中
|
||||
4. 使用 C 风格接口调用库功能
|
||||
4. 按照标准结构部署数据文件
|
||||
|
||||
示例代码:
|
||||
|
||||
@ -96,17 +169,17 @@ int main() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// 创建导弹
|
||||
// 创建导弹(使用配置文件)
|
||||
const char* missile_id = "missile1";
|
||||
int result = TS_CreateMissile(
|
||||
const char* missile_model = "lsgm_001"; // 激光半主动制导导弹
|
||||
const char* target_id = "target1";
|
||||
|
||||
int result = TS_CreateMissileFromConfig(
|
||||
missile_id,
|
||||
missile_model,
|
||||
target_id,
|
||||
0, 0, 0, // 初始位置
|
||||
0, 0, 0, // 初始速度
|
||||
1000, // 最大速度
|
||||
10, // 最大加速度
|
||||
30, // 最大飞行时间
|
||||
5000, // 最大飞行距离
|
||||
50 // 质量
|
||||
0, 0, 0 // 初始朝向
|
||||
);
|
||||
|
||||
if (result != THREATSOURCE_SUCCESS) {
|
||||
@ -151,25 +224,23 @@ int main() {
|
||||
```cpp
|
||||
using namespace System;
|
||||
using namespace ThreatSource::Simulation;
|
||||
using namespace ThreatSource::Data;
|
||||
|
||||
int main() {
|
||||
try {
|
||||
// 创建仿真管理器
|
||||
// 创建仿真管理器和数据管理器
|
||||
auto manager = gcnew SimulationManager();
|
||||
auto dataManager = gcnew ThreatSourceDataManager();
|
||||
auto factory = gcnew ThreatSourceFactory(dataManager, manager);
|
||||
|
||||
// 创建导弹配置
|
||||
auto properties = gcnew MissileProperties();
|
||||
properties->Id = "missile1";
|
||||
properties->InitialPosition = Vector3D(0, 0, 0);
|
||||
properties->InitialVelocity = Vector3D(0, 0, 0);
|
||||
properties->MaxSpeed = 1000;
|
||||
properties->MaxAcceleration = 10;
|
||||
properties->MaxFlightTime = 30;
|
||||
properties->MaxFlightDistance = 5000;
|
||||
properties->Mass = 50;
|
||||
// 创建发射参数
|
||||
auto launchParams = gcnew KinematicState();
|
||||
launchParams->Position = Vector3D(0, 0, 0);
|
||||
launchParams->Orientation = Orientation(0, 0, 0);
|
||||
launchParams->Speed = 100;
|
||||
|
||||
// 创建导弹
|
||||
auto missile = gcnew TerminalSensitiveMissile("target1", properties, manager);
|
||||
// 使用工厂创建导弹
|
||||
auto missile = factory->CreateMissile("missile1", "lsgm_001", "target1", launchParams);
|
||||
manager->RegisterEntity(missile->Id, missile);
|
||||
|
||||
// 激活并发射导弹
|
||||
@ -179,180 +250,251 @@ int main() {
|
||||
// 仿真主循环
|
||||
double deltaTime = 0.01;
|
||||
while (missile->IsActive) {
|
||||
missile->Update(deltaTime);
|
||||
manager->Update(deltaTime);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
catch (Exception^ e) {
|
||||
Trace::TraceError("Error: {0}", e->Message);
|
||||
Console::WriteLine("错误: {0}", e->Message);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 支持的导弹类型
|
||||
|
||||
威胁源库支持以下导弹类型:
|
||||
|
||||
### 1. 激光半主动制导导弹 (LaserSemiActiveGuidance)
|
||||
- **工作原理**:利用目标反射的激光能量进行制导
|
||||
- **配置文件**:`data/missiles/laser_semi_active/`
|
||||
- **制导特点**:需要激光目标指示器持续照射目标
|
||||
|
||||
### 2. 激光驾束制导导弹 (LaserBeamRiderGuidance)
|
||||
- **工作原理**:沿着激光束路径飞行
|
||||
- **配置文件**:`data/missiles/laser_beam_rider/`
|
||||
- **制导特点**:跟踪激光束中心线,使用PID控制
|
||||
|
||||
### 3. 红外指令制导导弹 (InfraredCommandGuidance)
|
||||
- **工作原理**:通过红外信号接收指令进行制导
|
||||
- **配置文件**:`data/missiles/ir_command/`
|
||||
- **制导特点**:导弹发射红外信号,地面测角仪跟踪并发送指令
|
||||
|
||||
### 4. 红外成像末制导导弹 (InfraredImagingTerminalGuidance)
|
||||
- **工作原理**:末段使用红外成像进行自主制导
|
||||
- **配置文件**:`data/missiles/ir_imaging/`
|
||||
- **制导特点**:自主目标识别和跟踪
|
||||
|
||||
### 5. 毫米波末制导导弹 (MillimeterWaveTerminalGuidance)
|
||||
- **工作原理**:末段使用毫米波雷达进行自主制导
|
||||
- **配置文件**:`data/missiles/mmw/`
|
||||
- **制导特点**:全天候作战能力,抗干扰性强
|
||||
|
||||
### 6. 末敏弹 (TerminalSensitiveMissile)
|
||||
- **工作原理**:母弹释放子弹,子弹螺旋扫描攻击目标
|
||||
- **配置文件**:`data/missiles/terminal_sensitive/`
|
||||
- **制导特点**:多传感器融合,智能目标识别
|
||||
|
||||
### 7. 复合制导导弹 (CompositeGuidance)
|
||||
- **工作原理**:集成多种制导方式,可串行或并行工作
|
||||
- **配置文件**:`data/missiles/composite/`
|
||||
- **制导特点**:高可靠性,多重制导保障
|
||||
|
||||
## 配置文件格式
|
||||
|
||||
威胁源库使用TOML格式的配置文件。以下是激光半主动制导导弹的配置示例:
|
||||
|
||||
```toml
|
||||
# 激光半主动制导导弹配置示例
|
||||
Type = "LaserSemiActiveGuidance"
|
||||
|
||||
[Name]
|
||||
zh = "激光半主动制导导弹-001"
|
||||
en = "Laser Semi-Active Guidance Missile-001"
|
||||
|
||||
[Properties]
|
||||
Type = "LaserSemiActiveGuidance"
|
||||
MaxSpeed = 800.0 # 最大速度 (m/s)
|
||||
MaxFlightTime = 60.0 # 最大飞行时间 (秒)
|
||||
MaxFlightDistance = 4000.0 # 最大飞行距离 (米)
|
||||
MaxAcceleration = 50.0 # 最大加速度 (m/s²)
|
||||
ProportionalNavigationCoefficient = 3.0 # 比例导引系数
|
||||
LaunchAcceleration = 100.0 # 发射加速度 (m/s²)
|
||||
MaxEngineBurnTime = 0.1 # 发动机燃烧时间 (秒)
|
||||
CruiseTime = 5.0 # 巡航时间 (秒)
|
||||
Mass = 22.0 # 质量 (kg)
|
||||
ExplosionRadius = 5.0 # 爆炸半径 (米)
|
||||
HitProbability = 0.9 # 命中概率
|
||||
SelfDestructHeight = 0.0 # 自毁高度 (米)
|
||||
|
||||
[LaserSemiActiveGuidanceConfig]
|
||||
MaxDetectionRange = 5000.0 # 最大探测距离 (米)
|
||||
FieldOfViewAngle = 30.0 # 视场角 (度)
|
||||
LockThreshold = 1.0e-12 # 锁定阈值 (瓦特)
|
||||
ReflectionCoefficient = 0.2 # 反射系数
|
||||
TargetReflectiveArea = 1.0 # 目标反射面积 (平方米)
|
||||
```
|
||||
|
||||
## 基本用法
|
||||
|
||||
### 初始化仿真管理器
|
||||
### 初始化仿真系统
|
||||
|
||||
```csharp
|
||||
// 创建仿真管理器
|
||||
var simulationManager = new SimulationManager();
|
||||
|
||||
// 创建数据管理器(自动路径解析)
|
||||
var dataManager = new ThreatSourceDataManager();
|
||||
|
||||
// 创建工厂
|
||||
var factory = new ThreatSourceFactory(dataManager, simulationManager);
|
||||
```
|
||||
|
||||
### 创建导弹
|
||||
|
||||
```csharp
|
||||
// 创建导弹配置
|
||||
var missileProperties = new MissileProperties
|
||||
{
|
||||
Id = "missile1",
|
||||
InitialPosition = new Vector3D(0, 0, 0),
|
||||
InitialOrientation = new Orientation(0, 0, 0),
|
||||
InitialSpeed = 800,
|
||||
MaxSpeed = 1000,
|
||||
MaxFlightTime = 30,
|
||||
MaxFlightDistance = 5000,
|
||||
MaxAcceleration = 10,
|
||||
Mass = 50
|
||||
};
|
||||
|
||||
// 创建导弹实例
|
||||
var missile = new TerminalSensitiveMissile("target1", missileProperties, simulationManager);
|
||||
```
|
||||
|
||||
### 创建目标
|
||||
### 创建和配置实体
|
||||
|
||||
```csharp
|
||||
// 创建目标
|
||||
var tank = new Tank(
|
||||
"target1",
|
||||
new Vector3D(1000, 0, 0),
|
||||
Math.PI/4,
|
||||
simulationManager
|
||||
);
|
||||
```
|
||||
var targetState = new KinematicState
|
||||
{
|
||||
Position = new Vector3D(1000, 0, 100),
|
||||
Orientation = new Orientation(0, 0, 0),
|
||||
Speed = 0
|
||||
};
|
||||
|
||||
### 注册实体
|
||||
var targetProperties = new EquipmentProperties
|
||||
{
|
||||
InfraredRadiationIntensity = 100.0,
|
||||
MillimeterWaveRadiationIntensity = 50.0
|
||||
};
|
||||
|
||||
```csharp
|
||||
simulationManager.RegisterEntity(missile.Id, missile);
|
||||
simulationManager.RegisterEntity(tank.Id, tank);
|
||||
var target = new Tank("target1", targetProperties, targetState, simulationManager);
|
||||
|
||||
// 创建导弹(从配置文件)
|
||||
var launchParams = new KinematicState
|
||||
{
|
||||
Position = new Vector3D(0, 0, 0),
|
||||
Orientation = new Orientation(0, 0, 0),
|
||||
Speed = 100
|
||||
};
|
||||
|
||||
var missile = factory.CreateMissile("missile1", "lsgm_001", "target1", launchParams);
|
||||
```
|
||||
|
||||
### 运行仿真
|
||||
|
||||
```csharp
|
||||
// 注册实体
|
||||
simulationManager.RegisterEntity(target.Id, target);
|
||||
simulationManager.RegisterEntity(missile.Id, missile);
|
||||
|
||||
// 激活实体
|
||||
target.Activate();
|
||||
missile.Activate();
|
||||
tank.Activate();
|
||||
|
||||
// 发射导弹
|
||||
missile.Fire();
|
||||
|
||||
// 仿真主循环
|
||||
double deltaTime = 0.01;
|
||||
// 启动仿真
|
||||
simulationManager.StartSimulation(0.01);
|
||||
|
||||
// 仿真循环
|
||||
while (missile.IsActive)
|
||||
{
|
||||
missile.Update(deltaTime);
|
||||
tank.Update(deltaTime);
|
||||
simulationManager.Update(0.01);
|
||||
}
|
||||
|
||||
// 停止仿真
|
||||
simulationManager.StopSimulation();
|
||||
```
|
||||
|
||||
## C++使用指南
|
||||
### 事件处理
|
||||
|
||||
### C++/CLI基本用法
|
||||
|
||||
#### 1. 创建包装类
|
||||
|
||||
```cpp
|
||||
using namespace System;
|
||||
using namespace ThreatSource::Simulation;
|
||||
|
||||
public ref class SimulationWrapper
|
||||
```csharp
|
||||
// 订阅导弹命中事件
|
||||
simulationManager.SubscribeToEvent<TargetHitEvent>(evt =>
|
||||
{
|
||||
private:
|
||||
SimulationManager^ manager;
|
||||
|
||||
public:
|
||||
SimulationWrapper()
|
||||
{
|
||||
manager = gcnew SimulationManager();
|
||||
}
|
||||
|
||||
void CreateAndRunSimulation()
|
||||
{
|
||||
try
|
||||
{
|
||||
// 创建导弹配置
|
||||
auto properties = gcnew MissileProperties();
|
||||
properties->Id = "missile1";
|
||||
properties->InitialPosition = Vector3D(0, 0, 0);
|
||||
properties->InitialSpeed = 800;
|
||||
properties->MaxSpeed = 1000;
|
||||
properties->MaxFlightTime = 30;
|
||||
properties->MaxFlightDistance = 5000;
|
||||
properties->MaxAcceleration = 10;
|
||||
properties->Mass = 50;
|
||||
Console.WriteLine($"目标 {evt.TargetId} 被导弹 {evt.SenderId} 命中");
|
||||
});
|
||||
|
||||
// 创建导弹
|
||||
auto missile = gcnew TerminalSensitiveMissile("target1", properties, manager);
|
||||
|
||||
// 注册和激活
|
||||
manager->RegisterEntity(missile->Id, missile);
|
||||
missile->Activate();
|
||||
missile->Fire();
|
||||
|
||||
// 仿真主循环
|
||||
double deltaTime = 0.01;
|
||||
while (missile->IsActive)
|
||||
{
|
||||
missile->Update(deltaTime);
|
||||
}
|
||||
}
|
||||
catch (Exception^ e)
|
||||
{
|
||||
Trace::TraceError("错误: {0}", e->Message);
|
||||
}
|
||||
}
|
||||
};
|
||||
// 订阅导弹爆炸事件
|
||||
simulationManager.SubscribeToEvent<MissileExplodeEvent>(evt =>
|
||||
{
|
||||
Console.WriteLine($"导弹在位置 {evt.Position} 爆炸");
|
||||
});
|
||||
```
|
||||
|
||||
#### 2. 在原生C++代码中使用
|
||||
## 数据管理
|
||||
|
||||
```cpp
|
||||
int main()
|
||||
### 获取可用配置
|
||||
|
||||
```csharp
|
||||
var dataManager = new ThreatSourceDataManager();
|
||||
|
||||
// 获取所有可用的导弹型号
|
||||
var availableMissiles = dataManager.GetAvailableMissiles();
|
||||
foreach (var missileId in availableMissiles)
|
||||
{
|
||||
try
|
||||
{
|
||||
auto simulation = gcnew SimulationWrapper();
|
||||
simulation->CreateAndRunSimulation();
|
||||
return 0;
|
||||
}
|
||||
catch (Exception^ e)
|
||||
{
|
||||
Trace::TraceError("错误: {0}", e->Message);
|
||||
return 1;
|
||||
}
|
||||
Console.WriteLine($"可用导弹: {missileId}");
|
||||
}
|
||||
|
||||
// 获取特定导弹的配置
|
||||
var missileData = dataManager.GetMissile("lsgm_001");
|
||||
Console.WriteLine($"导弹类型: {missileData.Type}");
|
||||
Console.WriteLine($"最大速度: {missileData.Properties.MaxSpeed} m/s");
|
||||
```
|
||||
|
||||
### 注意事项
|
||||
### 自定义数据路径
|
||||
|
||||
1. 内存管理
|
||||
- C++/CLI使用垃圾回收
|
||||
- 使用gcnew创建托管对象
|
||||
- 注意托管和非托管资源的混合使用
|
||||
```csharp
|
||||
// 指定自定义数据路径
|
||||
var customDataManager = new ThreatSourceDataManager("/path/to/custom/data");
|
||||
|
||||
2. 错误处理
|
||||
- 使用托管异常处理(try/catch)
|
||||
- 异常信息更详细,更容易调试
|
||||
- 可以直接使用.NET的日志机制
|
||||
// 或在运行时切换
|
||||
var dataManager = new ThreatSourceDataManager();
|
||||
// 数据会自动从 DLL上级目录/data 加载
|
||||
```
|
||||
|
||||
3. 类型系统
|
||||
- 使用托管类型(^)
|
||||
- 注意值类型和引用类型的区别
|
||||
- 使用安全的类型转换
|
||||
## 部署要求
|
||||
|
||||
### 最低系统要求
|
||||
- .NET 8.0 或更高版本
|
||||
- Windows 10 或更高版本(推荐)
|
||||
- 至少 100MB 可用磁盘空间
|
||||
|
||||
### 依赖项
|
||||
- Tomlyn (TOML解析库)
|
||||
- AirTransmission (空气传播计算库)
|
||||
|
||||
### 部署检查清单
|
||||
1. ✅ 确保DLL文件在正确位置
|
||||
2. ✅ 确保数据文件按标准结构组织
|
||||
3. ✅ 确保配置文件格式正确(TOML)
|
||||
4. ✅ 确保应用程序有读取数据目录的权限
|
||||
5. ✅ 测试自动路径解析功能
|
||||
|
||||
## 更多示例
|
||||
|
||||
更多示例请参考[示例代码](../examples/Simulation/README.md)。
|
||||
更多详细示例和高级用法请参考:
|
||||
- [仿真示例](../examples/Simulation/README.md)
|
||||
- [集成示例](../examples/Integration/)
|
||||
- [配置文件示例](../examples/Configs/)
|
||||
|
||||
## 故障排除
|
||||
|
||||
### 常见问题
|
||||
|
||||
1. **数据文件未找到**
|
||||
- 检查数据目录结构是否正确
|
||||
- 确认DLL和数据目录的相对位置
|
||||
- 查看调试输出中的路径解析信息
|
||||
|
||||
2. **配置文件解析错误**
|
||||
- 检查TOML文件语法
|
||||
- 确认必需字段是否存在
|
||||
- 查看错误日志获取详细信息
|
||||
|
||||
3. **导弹创建失败**
|
||||
- 确认导弹型号在配置文件中存在
|
||||
- 检查配置文件的完整性
|
||||
- 验证制导系统配置是否正确
|
||||
|
||||
@ -1,31 +1,346 @@
|
||||
# 导弹工作原理
|
||||
# 导弹工作原理参考手册
|
||||
|
||||
## 末敏弹工作过程
|
||||
**版本:1.1.22**
|
||||
|
||||
### 工作阶段
|
||||
本文档详细介绍威胁源库中实现的各种导弹制导系统的工作原理和技术特点。
|
||||
|
||||
1. 母弹抛撒阶段
|
||||
## 1. 激光半主动制导导弹
|
||||
|
||||
### 1.1 工作原理
|
||||
|
||||
激光半主动制导导弹通过接收目标反射的激光能量进行制导,是一种精确制导武器系统。
|
||||
|
||||
### 1.2 工作阶段
|
||||
|
||||
1. **发射阶段**
|
||||
- 导弹发射,发动机点火
|
||||
- 初始化制导系统
|
||||
- 准备接收激光照射信号
|
||||
|
||||
2. **巡航阶段**
|
||||
- 导弹按预定轨迹飞行
|
||||
- 制导系统处于待机状态
|
||||
- 等待激光指示器照射目标
|
||||
|
||||
3. **制导阶段**
|
||||
- 激光指示器开始照射目标
|
||||
- 四象限探测器接收反射激光
|
||||
- 计算光斑偏移量
|
||||
- 生成制导指令修正飞行轨迹
|
||||
|
||||
4. **攻击阶段**
|
||||
- 导弹接近目标
|
||||
- 引爆战斗部
|
||||
- 完成攻击任务
|
||||
|
||||
### 1.3 关键技术
|
||||
|
||||
1. **四象限探测器**
|
||||
- 精确测量光斑位置偏移
|
||||
- 提供水平和垂直误差信号
|
||||
- 灵敏度可调节
|
||||
|
||||
2. **激光编码识别**
|
||||
- 支持多种编码方式
|
||||
- 防止敌方激光干扰
|
||||
- 确保制导信号可靠性
|
||||
|
||||
3. **比例导引控制**
|
||||
- 使用比例导引律计算制导加速度
|
||||
- 加速度平滑处理,减少突变
|
||||
- 最大加速度限制保护
|
||||
|
||||
### 1.4 技术特点
|
||||
|
||||
- **制导精度高**:四象限探测器提供高精度角度测量
|
||||
- **抗干扰能力强**:激光编码技术防止干扰
|
||||
- **全天候作战**:不受天气影响(轻微衰减)
|
||||
- **需要持续照射**:激光指示器必须持续照射目标
|
||||
|
||||
## 2. 激光驾束制导导弹
|
||||
|
||||
### 2.1 工作原理
|
||||
|
||||
激光驾束制导导弹沿着激光束的中心线飞行,通过检测与激光束的偏差进行轨迹修正。
|
||||
|
||||
### 2.2 工作阶段
|
||||
|
||||
1. **发射阶段**
|
||||
- 导弹发射进入激光束
|
||||
- 激光束探测器开始工作
|
||||
- 建立初始制导基准
|
||||
|
||||
2. **驾束飞行阶段**
|
||||
- 持续检测与激光束中心线的偏差
|
||||
- PID控制器计算修正指令
|
||||
- 实时调整飞行轨迹
|
||||
|
||||
3. **末段制导阶段**
|
||||
- 接近目标区域
|
||||
- 提高制导精度
|
||||
- 准备攻击
|
||||
|
||||
### 2.3 关键技术
|
||||
|
||||
1. **激光束偏差检测**
|
||||
- 计算导弹与激光束中心线的距离
|
||||
- 实时监测偏差变化
|
||||
- 提供三维位置修正信号
|
||||
|
||||
2. **PID控制系统**
|
||||
- 比例控制:响应当前偏差
|
||||
- 积分控制:消除稳态误差
|
||||
- 微分控制:预测偏差变化趋势
|
||||
|
||||
3. **非线性增益控制**
|
||||
- 根据偏差大小调整控制增益
|
||||
- 大偏差时快速响应
|
||||
- 小偏差时精确控制
|
||||
|
||||
### 2.4 技术特点
|
||||
|
||||
- **轨迹可控**:严格按照激光束路径飞行
|
||||
- **精度极高**:PID控制提供精确轨迹跟踪
|
||||
- **实时响应**:快速响应轨迹偏差
|
||||
- **需要连续制导**:激光束必须持续到命中
|
||||
|
||||
## 3. 红外指令制导导弹
|
||||
|
||||
### 3.1 工作原理
|
||||
|
||||
红外指令制导系统由导弹和地面红外测角仪组成,通过红外信号建立通信链路,实现制导控制。
|
||||
|
||||
### 3.2 工作阶段
|
||||
|
||||
1. **红外信号建立阶段**
|
||||
- 导弹发射后点亮红外热源
|
||||
- 红外测角仪探测导弹红外信号
|
||||
- 建立跟踪链路
|
||||
|
||||
2. **双目标跟踪阶段**
|
||||
- 红外测角仪同时跟踪导弹和目标
|
||||
- 计算两者的相对位置关系
|
||||
- 生成制导指令
|
||||
|
||||
3. **指令传输阶段**
|
||||
- 测角仪通过事件系统发送制导指令
|
||||
- 导弹接收并解析指令
|
||||
- 更新飞行轨迹
|
||||
|
||||
4. **制导执行阶段**
|
||||
- 计算期望飞行方向
|
||||
- 应用转向速率平滑
|
||||
- 执行轨迹修正
|
||||
|
||||
### 3.3 关键技术
|
||||
|
||||
1. **红外测角仪跟踪**
|
||||
- 具备一定的最大跟踪距离
|
||||
- 具有较大的视场角
|
||||
- 高精度角度测量
|
||||
- 高频率更新
|
||||
|
||||
2. **制导指令计算**
|
||||
- 计算测角仪到导弹的向量
|
||||
- 计算测角仪到目标的向量
|
||||
- 生成三维制导指令
|
||||
|
||||
3. **导弹制导控制**
|
||||
- 转向速率平滑处理
|
||||
- 提前量计算
|
||||
- 自适应制导参数调整
|
||||
|
||||
### 3.4 技术特点
|
||||
|
||||
- **远程制导**:地面测角仪提供远程制导能力
|
||||
- **双目标跟踪**:同时跟踪导弹和目标
|
||||
- **指令制导**:实时传输制导指令
|
||||
- **需要通信链路**:依赖红外通信链路
|
||||
|
||||
## 4. 红外成像末制导导弹
|
||||
|
||||
### 4.1 工作原理
|
||||
|
||||
红外成像末制导导弹通过红外成像探测器实现目标的自动探测、识别和跟踪,具备完全自主的制导能力。
|
||||
|
||||
### 4.2 工作阶段
|
||||
|
||||
1. **搜索阶段**
|
||||
- 大视场角搜索目标
|
||||
- 红外图像生成和处理
|
||||
- 目标初步探测
|
||||
|
||||
2. **跟踪阶段**
|
||||
- 切换到小视场角
|
||||
- 精确跟踪已发现目标
|
||||
- 目标类型识别
|
||||
|
||||
3. **锁定阶段**
|
||||
- 确认目标类型
|
||||
- 持续精确跟踪
|
||||
- 执行末段制导
|
||||
|
||||
### 4.3 关键技术
|
||||
|
||||
1. **红外图像生成**
|
||||
- 高分辨率图像采集
|
||||
- 考虑目标温度、距离、大气衰减
|
||||
- 背景噪声和干扰处理
|
||||
|
||||
2. **目标识别算法**
|
||||
- 信噪比计算和阈值判断
|
||||
- 目标特征提取和匹配
|
||||
- 识别概率评估
|
||||
|
||||
3. **多模式工作**
|
||||
- Search模式:大视场搜索
|
||||
- Track模式:小视场跟踪
|
||||
- Lock模式:锁定制导
|
||||
|
||||
4. **比例导引控制**
|
||||
- 目标状态估计
|
||||
- 运动预测
|
||||
- 制导加速度计算
|
||||
|
||||
### 4.4 技术特点
|
||||
|
||||
- **完全自主**:无需外部制导信号
|
||||
- **目标识别**:具备目标类型识别能力
|
||||
- **抗干扰**:对烟幕、红外干扰有一定抗性
|
||||
- **末段精确**:末段制导精度高
|
||||
|
||||
## 5. 毫米波末制导导弹
|
||||
|
||||
### 5.1 工作原理
|
||||
|
||||
毫米波末制导导弹使用毫米波雷达进行目标探测和跟踪,具备全天候作战能力和强抗干扰性。
|
||||
|
||||
### 5.2 工作阶段
|
||||
|
||||
1. **雷达开机阶段**
|
||||
- 毫米波雷达系统启动
|
||||
- 天线开始扫描
|
||||
- 建立探测基准
|
||||
|
||||
2. **目标搜索阶段**
|
||||
- 大范围扫描搜索目标
|
||||
- 雷达回波信号处理
|
||||
- 目标初步定位
|
||||
|
||||
3. **目标跟踪阶段**
|
||||
- 锁定目标进行跟踪
|
||||
- 连续测量目标位置
|
||||
- 计算目标运动参数
|
||||
|
||||
4. **末制导阶段**
|
||||
- 精确跟踪目标
|
||||
- 实时轨迹修正
|
||||
- 引导导弹命中目标
|
||||
|
||||
### 5.3 关键技术
|
||||
|
||||
1. **毫米波雷达系统**
|
||||
- 工作在毫米波频段
|
||||
- 具备一定的探测距离
|
||||
- 高精度角度分辨率
|
||||
|
||||
2. **信号处理**
|
||||
- 雷达回波信号处理
|
||||
- 目标检测算法
|
||||
- 杂波抑制技术
|
||||
|
||||
3. **跟踪算法**
|
||||
- 目标航迹建立
|
||||
- 运动状态估计
|
||||
- 预测滤波
|
||||
|
||||
### 5.4 技术特点
|
||||
|
||||
- **全天候作战**:不受天气条件影响
|
||||
- **强抗干扰**:对光电干扰免疫
|
||||
- **穿透能力强**:可穿透烟幕、雾霾
|
||||
- **探测距离远**:毫米波传播特性好
|
||||
|
||||
## 6. 复合制导导弹
|
||||
|
||||
### 6.1 工作原理
|
||||
|
||||
复合制导导弹集成多种制导方式,可以串行或并行工作,提供高可靠性和多重制导保障。
|
||||
|
||||
### 6.2 工作模式
|
||||
|
||||
1. **串行模式**
|
||||
- 制导系统按优先级顺序激活
|
||||
- 前一个系统失效后切换到下一个
|
||||
- 提供制导冗余保障
|
||||
|
||||
2. **并行模式**
|
||||
- 多个制导系统同时工作
|
||||
- 根据融合策略选择最优制导信号
|
||||
- 提高制导精度和可靠性
|
||||
|
||||
### 6.3 制导组件管理
|
||||
|
||||
1. **激活触发器**
|
||||
- 发射时激活
|
||||
- 飞行时间触发
|
||||
- 距离触发
|
||||
- 前级完成触发
|
||||
|
||||
2. **制导切换逻辑**
|
||||
- 最大获取制导时间限制
|
||||
- 最小稳定制导时间要求
|
||||
- 失效后继续链条选项
|
||||
|
||||
### 6.4 典型配置
|
||||
|
||||
1. **激光+红外复合制导**
|
||||
- 第一阶段:激光半主动制导
|
||||
- 第二阶段:红外成像末制导
|
||||
- 提供远程精确+末段自主能力
|
||||
|
||||
2. **毫米波+红外复合制导**
|
||||
- 第一阶段:毫米波末制导
|
||||
- 第二阶段:红外成像末制导
|
||||
- 提供全天候+高精度能力
|
||||
|
||||
### 6.5 技术特点
|
||||
|
||||
- **高可靠性**:多重制导保障
|
||||
- **适应性强**:适应不同作战环境
|
||||
- **精度高**:多系统融合提高精度
|
||||
- **复杂度高**:系统复杂,成本较高
|
||||
|
||||
## 7. 末敏弹
|
||||
|
||||
### 7.1 工作原理
|
||||
|
||||
末敏弹是一种智能子母弹,母弹在目标上空抛撒子弹,子弹通过螺旋扫描方式搜索和攻击地面目标。
|
||||
|
||||
### 7.2 工作阶段
|
||||
|
||||
1. **母弹抛撒阶段**
|
||||
- 母弹飞抵目标上空后,时间引信作用
|
||||
- 启动抛射装置,将末敏子弹按一定距离抛撒出来
|
||||
|
||||
2. 子弹减速阶段
|
||||
2. **子弹减速阶段**
|
||||
- 减速减旋装置动作,对子弹起减速、减旋、定向、稳向作用
|
||||
- 启动热电池,达到规定值时开始对内部电子系统供电
|
||||
|
||||
3. 第一期测距阶段
|
||||
3. **第一期测距阶段**
|
||||
- 子弹以大着角下落
|
||||
- 在中央控制器控制下,测距雷达开始第1期测距
|
||||
- 测定子弹到地面的距离
|
||||
- 达到预定高度时,抛去减速减旋装置
|
||||
- 稳定扫描装置动作,带动子弹旋转
|
||||
|
||||
4. 第二期测距阶段
|
||||
4. **第二期测距阶段**
|
||||
- 稳定扫描装置带动末敏子弹稳态降落
|
||||
- 在中央控制器控制下,测距雷达进行第2期测距
|
||||
- 中央控制器完成对目标探测数据采集的准备工作
|
||||
- 末敏子弹进入稳态扫描
|
||||
|
||||
5. 目标探测阶段
|
||||
5. **目标探测阶段**
|
||||
- 末敏子弹进入威力有效高度
|
||||
- 敏感探测器在中央控制器指令下进行工作扫描
|
||||
- 在中央控制器控制下安保装置解除最后一道保险
|
||||
@ -33,25 +348,58 @@
|
||||
- 第1次扫过目标后,向中央控制器报告目标信息
|
||||
- 第2次扫过目标后,将目标敏感数据与特征值比较
|
||||
|
||||
6. 攻击/自毁阶段
|
||||
6. **攻击/自毁阶段**
|
||||
- 如果第2次扫描确认是目标,且目标在威力窗口内:
|
||||
- 中央控制器下达指令起爆战斗部
|
||||
- 抛射出爆炸成形弹丸(EFP)
|
||||
- EFP以大于2000m/s的高速射向目标
|
||||
- 抛射出爆炸成形弹丸
|
||||
- 高速弹丸射向目标
|
||||
- 在目标来不及运动的瞬间命中并摧毁目标
|
||||
- 如果第2次扫描判定为非目标:
|
||||
- 可以改换对象,继续探测其他潜在目标
|
||||
- 如果一直没有发现目标:
|
||||
- 末敏子弹将在距离地面一定高度时自毁
|
||||
|
||||
### 关键特性
|
||||
### 7.3 关键特性
|
||||
|
||||
1. 扫描特性
|
||||
1. **扫描特性**
|
||||
- 抛出的末敏子弹在实施扫描时相距一定距离
|
||||
- 各自的扫描区相互衔接
|
||||
- 避免击中同一目标或漏掉目标
|
||||
|
||||
2. 安全特性
|
||||
2. **安全特性**
|
||||
- 多重保险装置
|
||||
- 高度自毁保护
|
||||
- 稳定扫描控制
|
||||
|
||||
3. **智能特性**
|
||||
- 自动目标识别
|
||||
- 双次扫描确认
|
||||
- 智能目标选择
|
||||
|
||||
### 7.4 技术特点
|
||||
|
||||
- **面杀伤能力**:一发母弹可攻击多个目标
|
||||
- **智能识别**:具备目标自动识别能力
|
||||
- **高杀伤效率**:高速弹丸杀伤力强
|
||||
- **适合集群目标**:特别适合攻击装甲集群
|
||||
|
||||
## 8. 技术对比总结
|
||||
|
||||
| 制导类型 | 制导精度 | 抗干扰性 | 自主性 | 全天候 | 复杂度 | 适用场景 |
|
||||
|---------|---------|---------|--------|--------|--------|----------|
|
||||
| 激光半主动 | 极高 | 中等 | 低 | 良好 | 中等 | 精确打击 |
|
||||
| 激光驾束 | 极高 | 中等 | 低 | 良好 | 中等 | 精确制导 |
|
||||
| 红外指令 | 高 | 中等 | 低 | 中等 | 中等 | 远程制导 |
|
||||
| 红外成像 | 高 | 中等 | 高 | 中等 | 高 | 末段自主 |
|
||||
| 毫米波 | 高 | 强 | 高 | 优秀 | 高 | 全天候作战 |
|
||||
| 复合制导 | 极高 | 强 | 高 | 优秀 | 很高 | 高价值目标 |
|
||||
| 末敏弹 | 中等 | 中等 | 高 | 良好 | 高 | 面目标攻击 |
|
||||
|
||||
## 9. 应用建议
|
||||
|
||||
1. **精确点目标**:推荐激光半主动或激光驾束制导
|
||||
2. **高价值目标**:推荐复合制导系统
|
||||
3. **恶劣天气**:推荐毫米波制导
|
||||
4. **集群目标**:推荐末敏弹
|
||||
5. **远程打击**:推荐红外指令制导
|
||||
6. **自主作战**:推荐红外成像制导
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,12 @@
|
||||
# 第三方引擎集成示例
|
||||
|
||||
本目录包含了将仿真系统与第三方引擎集成的示例代码。这些示例展示了如何使用适配器模式将不同的游戏引擎与仿真系统进行集成。
|
||||
本目录包含了将ThreatSource仿真系统与第三方引擎集成的示例代码。这些示例展示了如何使用适配器模式将不同的游戏引擎与仿真系统进行集成。
|
||||
|
||||
## 系统要求
|
||||
|
||||
- .NET 8.0 或更高版本
|
||||
- ThreatSource.dll 库文件
|
||||
- 对应的第三方引擎开发环境
|
||||
|
||||
## 示例文件
|
||||
|
||||
@ -8,207 +14,380 @@
|
||||
|
||||
虚幻引擎(Unreal Engine)集成示例,展示了:
|
||||
|
||||
- 虚幻引擎与仿真系统的双向通信
|
||||
- 实体信息的同步和转换
|
||||
- 虚幻引擎与ThreatSource仿真系统的双向通信
|
||||
- Actor与仿真实体的映射和同步
|
||||
- 事件的发布和订阅
|
||||
- 数据的适配和转换
|
||||
- 坐标系转换和数据适配
|
||||
|
||||
#### 源代码
|
||||
#### 核心功能
|
||||
|
||||
```csharp
|
||||
#if NEVER // 使用编译指令确保此文件永远不会被编译
|
||||
|
||||
// 第三方系统实现适配器示例代码
|
||||
// 以虚幻引擎为例
|
||||
// 需要实现的方法: GetEntity, PublishToExternalSimulation, ReceiveFromExternalSimulation
|
||||
|
||||
using ThreatSource.Simulation;
|
||||
using ThreatSource.Data;
|
||||
using ThreatSource.Missile;
|
||||
|
||||
/// <summary>
|
||||
/// 虚幻引擎适配器类,演示如何将第三方系统集成到仿真系统中
|
||||
/// </summary>
|
||||
public class UnrealEngineAdapter : ISimulationAdapter
|
||||
public class UnrealThreatSourceAdapter
|
||||
{
|
||||
/// <summary>
|
||||
/// 虚幻引擎API接口,定义了与虚幻引擎交互的基本方法
|
||||
/// </summary>
|
||||
public interface IUnrealEngine
|
||||
{
|
||||
/// <summary>
|
||||
/// 根据ID获取虚幻引擎中的Actor对象
|
||||
/// </summary>
|
||||
object? GetActor(string id);
|
||||
private ISimulationManager _simulationManager;
|
||||
private ThreatSourceDataManager _dataManager;
|
||||
private Dictionary<string, object> _entityActors;
|
||||
|
||||
/// <summary>
|
||||
/// 在虚幻引擎中生成导弹实体
|
||||
/// </summary>
|
||||
void SpawnMissile(string senderId, string targetId);
|
||||
public void UpdateSimulation()
|
||||
{
|
||||
// 更新仿真
|
||||
_simulationManager.UpdateSimulation();
|
||||
|
||||
// 同步实体状态到虚幻引擎Actor
|
||||
SyncEntityStates();
|
||||
}
|
||||
|
||||
private readonly IUnrealEngine _unrealEngine;
|
||||
private readonly ISimulationManager _simulationManager;
|
||||
|
||||
public UnrealEngineAdapter(IUnrealEngine unrealEngine, ISimulationManager simulationManager)
|
||||
public string CreateMissile(string missileType, Vector3 location, string targetId)
|
||||
{
|
||||
_unrealEngine = unrealEngine ?? throw new ArgumentNullException(nameof(unrealEngine));
|
||||
_simulationManager = simulationManager ?? throw new ArgumentNullException(nameof(simulationManager));
|
||||
}
|
||||
|
||||
public object? GetEntity(string id)
|
||||
{
|
||||
return _unrealEngine.GetActor(id);
|
||||
}
|
||||
|
||||
public void PublishToExternalSimulation<T>(T evt)
|
||||
{
|
||||
if (evt is MissileFireEvent missileEvt)
|
||||
{
|
||||
_unrealEngine.SpawnMissile(missileEvt.SenderId, missileEvt.TargetId);
|
||||
}
|
||||
}
|
||||
|
||||
public void ReceiveFromExternalSimulation<T>(T evt)
|
||||
{
|
||||
// 处理来自虚幻引擎的事件
|
||||
// 从配置创建导弹
|
||||
var missileData = _dataManager.GetMissile(missileType);
|
||||
var missile = new InfraredImagingTerminalGuidanceMissile(missileId, missileData);
|
||||
|
||||
// 在虚幻引擎中创建Actor
|
||||
var missileActor = _unrealEngine.SpawnActor("BP_Missile", location, rotation);
|
||||
|
||||
// 建立映射关系
|
||||
_entityActors[missileId] = missileActor;
|
||||
|
||||
return missileId;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
```
|
||||
|
||||
### [UnityExample.cs](UnityExample.cs)
|
||||
|
||||
Unity引擎集成示例,展示了:
|
||||
|
||||
- Unity引擎与仿真系统的双向通信
|
||||
- GameObject与实体的映射和转换
|
||||
- Unity引擎与ThreatSource仿真系统的双向通信
|
||||
- GameObject与仿真实体的映射和转换
|
||||
- MonoBehaviour生命周期管理
|
||||
- 事件系统的使用
|
||||
- 事件系统的使用和视觉效果处理
|
||||
|
||||
#### 源代码
|
||||
#### 核心功能
|
||||
|
||||
```csharp
|
||||
#if NEVER // 使用编译指令确保此文件永远不会被编译
|
||||
|
||||
// 第三方系统实现适配器示例代码
|
||||
// 以Unity引擎为例
|
||||
// 需要实现的方法: GetEntity, PublishToExternalSimulation, ReceiveFromExternalSimulation
|
||||
|
||||
using ThreatSource.Simulation;
|
||||
using UnityEngine; // 仅用于示例,实际项目中需要引用真实的Unity命名空间
|
||||
using ThreatSource.Data;
|
||||
using ThreatSource.Missile;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Unity引擎适配器类,演示如何将Unity引擎集成到仿真系统中
|
||||
/// </summary>
|
||||
public class UnityEngineAdapter : MonoBehaviour, ISimulationAdapter
|
||||
public class UnityThreatSourceAdapter : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// Unity引擎API接口,定义了与Unity引擎交互的基本方法
|
||||
/// </summary>
|
||||
public interface IUnityEngine
|
||||
{
|
||||
/// <summary>
|
||||
/// 根据ID获取Unity场景中的GameObject对象
|
||||
/// </summary>
|
||||
GameObject GetGameObject(string id);
|
||||
|
||||
/// <summary>
|
||||
/// 在Unity场景中实例化导弹预制体
|
||||
/// </summary>
|
||||
GameObject InstantiateMissile(string prefabPath, Vector3 position, Quaternion rotation);
|
||||
}
|
||||
|
||||
private readonly IUnityEngine _unityEngine;
|
||||
private readonly ISimulationManager _simulationManager;
|
||||
private const string MissilePrefabPath = "Prefabs/Missile";
|
||||
|
||||
public UnityEngineAdapter(IUnityEngine unityEngine, ISimulationManager simulationManager)
|
||||
{
|
||||
_unityEngine = unityEngine ?? throw new ArgumentNullException(nameof(unityEngine));
|
||||
_simulationManager = simulationManager ?? throw new ArgumentNullException(nameof(simulationManager));
|
||||
}
|
||||
|
||||
public object? GetEntity(string id)
|
||||
{
|
||||
return _unityEngine.GetGameObject(id);
|
||||
}
|
||||
|
||||
public void PublishToExternalSimulation<T>(T evt)
|
||||
{
|
||||
if (evt is MissileFireEvent missileEvt)
|
||||
{
|
||||
var sender = _unityEngine.GetGameObject(missileEvt.SenderId);
|
||||
if (sender != null)
|
||||
{
|
||||
UnityMainThreadDispatcher.Instance.Enqueue(() =>
|
||||
{
|
||||
var missile = _unityEngine.InstantiateMissile(
|
||||
MissilePrefabPath,
|
||||
sender.transform.position,
|
||||
sender.transform.rotation
|
||||
);
|
||||
|
||||
var missileComponent = missile.GetComponent<MissileController>();
|
||||
if (missileComponent != null)
|
||||
{
|
||||
missileComponent.SetTarget(missileEvt.TargetId);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ReceiveFromExternalSimulation<T>(T evt)
|
||||
{
|
||||
if (evt is CollisionEvent collisionEvt)
|
||||
{
|
||||
_simulationManager.HandleCollision(collisionEvt);
|
||||
}
|
||||
}
|
||||
private ISimulationManager _simulationManager;
|
||||
private ThreatSourceDataManager _dataManager;
|
||||
private Dictionary<string, GameObject> _entityGameObjects;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
SyncSimulationState();
|
||||
// 更新仿真
|
||||
_simulationManager.UpdateSimulation();
|
||||
|
||||
// 同步实体状态到Unity GameObject
|
||||
SyncEntityStates();
|
||||
}
|
||||
|
||||
private void SyncSimulationState()
|
||||
public void CreateMissile(string missileType, Vector3 position, string targetId)
|
||||
{
|
||||
// 实现仿真状态同步逻辑
|
||||
// 从配置创建导弹
|
||||
var missileData = _dataManager.GetMissile(missileType);
|
||||
var missile = new InfraredImagingTerminalGuidanceMissile(missileId, missileData);
|
||||
|
||||
// 在Unity中创建GameObject
|
||||
var missileGameObject = Instantiate(missilePrefab, position, Quaternion.identity);
|
||||
|
||||
// 建立映射关系
|
||||
_entityGameObjects[missileId] = missileGameObject;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
```
|
||||
|
||||
## 使用说明
|
||||
|
||||
1. 这些文件仅作为参考示例,不参与实际编译(使用 `#if NEVER` 编译指令)
|
||||
2. 实际项目中需要根据具体需求修改和扩展
|
||||
3. 示例中的接口和类名仅供参考,应根据实际项目规范调整
|
||||
### 基本集成流程
|
||||
|
||||
1. **初始化仿真系统**
|
||||
```csharp
|
||||
_simulationManager = new SimulationManager();
|
||||
_dataManager = new ThreatSourceDataManager();
|
||||
_simulationManager.StartSimulation(timeStep);
|
||||
```
|
||||
|
||||
2. **订阅仿真事件**
|
||||
```csharp
|
||||
_simulationManager.Subscribe<MissileFireEvent>(OnMissileFireEvent);
|
||||
_simulationManager.Subscribe<MissileExplodeEvent>(OnMissileExplodeEvent);
|
||||
_simulationManager.Subscribe<FlightPhaseChangeEvent>(OnFlightPhaseChangeEvent);
|
||||
```
|
||||
|
||||
3. **创建实体映射**
|
||||
```csharp
|
||||
// 创建仿真实体
|
||||
var missile = new InfraredImagingTerminalGuidanceMissile(id, data);
|
||||
_simulationManager.RegisterEntity(missile);
|
||||
|
||||
// 创建引擎对象(Unity GameObject 或 Unreal Actor)
|
||||
var visualObject = CreateVisualObject(missile);
|
||||
|
||||
// 建立映射关系
|
||||
_entityMappings[id] = visualObject;
|
||||
```
|
||||
|
||||
4. **同步状态**
|
||||
```csharp
|
||||
private void SyncEntityStates()
|
||||
{
|
||||
foreach (var kvp in _entityMappings)
|
||||
{
|
||||
var entity = _simulationManager.GetEntity(kvp.Key);
|
||||
var visualObject = kvp.Value;
|
||||
|
||||
// 同步位置和朝向
|
||||
SyncTransform(entity, visualObject);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 坐标系转换
|
||||
|
||||
#### Unity集成
|
||||
```csharp
|
||||
// ThreatSource -> Unity 坐标转换
|
||||
gameObject.transform.position = new Vector3(
|
||||
entity.KState.Position.X,
|
||||
entity.KState.Position.Z, // Unity使用Y作为高度
|
||||
entity.KState.Position.Y
|
||||
);
|
||||
```
|
||||
|
||||
#### 虚幻引擎集成
|
||||
```csharp
|
||||
// ThreatSource -> Unreal 坐标转换(右手系 -> 左手系)
|
||||
var location = new Vector3(
|
||||
entity.KState.Position.X,
|
||||
-entity.KState.Position.Y, // Y轴翻转
|
||||
entity.KState.Position.Z
|
||||
);
|
||||
```
|
||||
|
||||
### 事件处理
|
||||
|
||||
#### 导弹发射事件
|
||||
```csharp
|
||||
private void OnMissileFireEvent(MissileFireEvent evt)
|
||||
{
|
||||
// 播放发射特效
|
||||
var visualObject = GetVisualObject(evt.SenderId);
|
||||
PlayLaunchEffect(visualObject);
|
||||
}
|
||||
```
|
||||
|
||||
#### 导弹爆炸事件
|
||||
```csharp
|
||||
private void OnMissileExplodeEvent(MissileExplodeEvent evt)
|
||||
{
|
||||
// 播放爆炸特效
|
||||
PlayExplosionEffect(evt.Position);
|
||||
|
||||
// 销毁视觉对象
|
||||
DestroyVisualObject(evt.SenderId);
|
||||
}
|
||||
```
|
||||
|
||||
#### 飞行阶段变化事件
|
||||
```csharp
|
||||
private void OnFlightPhaseChangeEvent(FlightPhaseChangeEvent evt)
|
||||
{
|
||||
var visualObject = GetVisualObject(evt.SenderId);
|
||||
|
||||
switch (evt.NewPhase)
|
||||
{
|
||||
case FlightPhase.Boost:
|
||||
ShowBoostEffect(visualObject);
|
||||
break;
|
||||
case FlightPhase.Terminal:
|
||||
ShowTerminalEffect(visualObject);
|
||||
break;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 关键概念
|
||||
|
||||
### 适配器模式
|
||||
|
||||
- 实现 `ISimulationAdapter` 接口
|
||||
- 转换不同引擎的数据格式
|
||||
- 处理事件的发布和订阅
|
||||
适配器模式用于连接ThreatSource仿真系统和第三方引擎:
|
||||
|
||||
- **仿真层**:ThreatSource核心仿真逻辑
|
||||
- **适配器层**:数据转换和事件映射
|
||||
- **引擎层**:Unity/Unreal等第三方引擎
|
||||
|
||||
### 实体映射
|
||||
|
||||
- 在仿真系统和游戏引擎之间建立实体对应关系
|
||||
- 同步实体状态和属性
|
||||
- 处理实体的创建和销毁
|
||||
在仿真系统和游戏引擎之间建立实体对应关系:
|
||||
|
||||
```csharp
|
||||
// 映射关系管理
|
||||
private Dictionary<string, VisualObject> _entityMappings;
|
||||
|
||||
// 创建映射
|
||||
public void CreateEntityMapping(string entityId, VisualObject visualObject)
|
||||
{
|
||||
_entityMappings[entityId] = visualObject;
|
||||
}
|
||||
|
||||
// 同步状态
|
||||
public void SyncEntity(string entityId)
|
||||
{
|
||||
var entity = _simulationManager.GetEntity(entityId);
|
||||
var visualObject = _entityMappings[entityId];
|
||||
|
||||
// 同步位置、朝向、状态等
|
||||
SyncTransform(entity, visualObject);
|
||||
SyncVisualState(entity, visualObject);
|
||||
}
|
||||
```
|
||||
|
||||
### 事件系统
|
||||
|
||||
- 定义统一的事件数据结构
|
||||
- 处理事件的双向转换
|
||||
- 确保事件的正确分发
|
||||
统一的事件处理机制:
|
||||
|
||||
```csharp
|
||||
// 事件订阅
|
||||
_simulationManager.Subscribe<TEvent>(handler);
|
||||
|
||||
// 事件处理
|
||||
private void HandleEvent(TEvent evt)
|
||||
{
|
||||
// 转换为引擎特定的操作
|
||||
ConvertToEngineOperation(evt);
|
||||
}
|
||||
```
|
||||
|
||||
## 性能优化
|
||||
|
||||
### 批量更新
|
||||
```csharp
|
||||
// 批量同步实体状态,减少单次调用开销
|
||||
private void BatchSyncEntities()
|
||||
{
|
||||
var entities = _simulationManager.GetAllEntities();
|
||||
foreach (var entity in entities)
|
||||
{
|
||||
if (_entityMappings.TryGetValue(entity.Id, out var visualObject))
|
||||
{
|
||||
SyncEntity(entity, visualObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 距离剔除
|
||||
```csharp
|
||||
// 只同步视野范围内的实体
|
||||
private void SyncVisibleEntities(Vector3 viewerPosition, float maxDistance)
|
||||
{
|
||||
foreach (var kvp in _entityMappings)
|
||||
{
|
||||
var entity = _simulationManager.GetEntity(kvp.Key);
|
||||
var distance = Vector3.Distance(entity.KState.Position, viewerPosition);
|
||||
|
||||
if (distance <= maxDistance)
|
||||
{
|
||||
SyncEntity(entity, kvp.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 帧率控制
|
||||
```csharp
|
||||
// 控制仿真更新频率
|
||||
private float _lastUpdateTime;
|
||||
private float _updateInterval = 0.02f; // 50Hz
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Time.time - _lastUpdateTime >= _updateInterval)
|
||||
{
|
||||
_simulationManager.UpdateSimulation();
|
||||
SyncEntityStates();
|
||||
_lastUpdateTime = Time.time;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 注意事项
|
||||
|
||||
1. 需要处理线程安全问题
|
||||
2. 注意性能优化,特别是在状态同步时
|
||||
3. 合理处理资源的加载和释放
|
||||
4. 确保异常处理的完整性
|
||||
### 通用注意事项
|
||||
|
||||
1. **线程安全**:确保仿真更新和引擎渲染在正确的线程中执行
|
||||
2. **性能优化**:合理控制同步频率,避免过度更新
|
||||
3. **资源管理**:正确处理实体的创建和销毁
|
||||
4. **异常处理**:添加完整的异常处理机制
|
||||
|
||||
### Unity特定注意事项
|
||||
|
||||
1. **主线程操作**:Unity API必须在主线程中调用
|
||||
2. **生命周期管理**:正确处理MonoBehaviour的生命周期
|
||||
3. **预制体管理**:合理组织和加载预制体资源
|
||||
4. **坐标系转换**:注意Unity的左手坐标系
|
||||
|
||||
### 虚幻引擎特定注意事项
|
||||
|
||||
1. **蓝图集成**:考虑与蓝图系统的集成
|
||||
2. **Actor生命周期**:正确管理Actor的创建和销毁
|
||||
3. **坐标系转换**:处理右手系到左手系的转换
|
||||
4. **性能分析**:使用虚幻引擎的性能分析工具
|
||||
|
||||
## 扩展功能
|
||||
|
||||
### 多人同步
|
||||
```csharp
|
||||
// 网络同步支持
|
||||
public class NetworkedThreatSourceAdapter
|
||||
{
|
||||
public void SyncEntityOverNetwork(string entityId, EntityState state)
|
||||
{
|
||||
// 通过网络同步实体状态
|
||||
NetworkManager.SendEntityUpdate(entityId, state);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 录制回放
|
||||
```csharp
|
||||
// 仿真录制和回放
|
||||
public class SimulationRecorder
|
||||
{
|
||||
public void RecordFrame(float timestamp, List<EntityState> states)
|
||||
{
|
||||
// 记录当前帧的所有实体状态
|
||||
_recordedFrames.Add(new SimulationFrame(timestamp, states));
|
||||
}
|
||||
|
||||
public void PlaybackFrame(int frameIndex)
|
||||
{
|
||||
// 回放指定帧的状态
|
||||
var frame = _recordedFrames[frameIndex];
|
||||
ApplyFrameStates(frame);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 自定义渲染
|
||||
```csharp
|
||||
// 自定义渲染效果
|
||||
public class CustomMissileRenderer
|
||||
{
|
||||
public void RenderMissileTrail(Vector3 position, Vector3 velocity)
|
||||
{
|
||||
// 根据导弹状态渲染自定义拖尾效果
|
||||
var trailLength = velocity.magnitude * 0.1f;
|
||||
RenderTrail(position, velocity.normalized, trailLength);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@ -1,177 +1,375 @@
|
||||
#if NEVER // 使用编译指令确保此文件永远不会被编译
|
||||
|
||||
// 第三方系统实现适配器示例代码
|
||||
// 以虚幻引擎为例
|
||||
// 需要实现的方法: GetEntity, PublishToExternalSimulation, ReceiveFromExternalSimulation
|
||||
// 虚幻引擎集成示例代码
|
||||
// 展示如何将虚幻引擎与ThreatSource仿真系统集成
|
||||
// 需要实现的核心功能: 实体同步、事件处理、状态管理
|
||||
|
||||
using ThreatSource.Simulation;
|
||||
using ThreatSource.Data;
|
||||
using ThreatSource.Missile;
|
||||
|
||||
/// <summary>
|
||||
/// 虚幻引擎适配器类,演示如何将第三方系统集成到仿真系统中
|
||||
/// 虚幻引擎适配器类,演示如何将ThreatSource系统集成到虚幻引擎中
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 该类提供了以下功能:
|
||||
/// - 虚幻引擎与仿真系统的双向通信
|
||||
/// - 实体信息的同步和转换
|
||||
/// - Actor与仿真实体的映射和同步
|
||||
/// - 事件的发布和订阅
|
||||
/// - 数据的适配和转换
|
||||
/// 本示例代码仅作为参考,展示了基本的集成方法
|
||||
/// </remarks>
|
||||
public class UnrealEngineAdapter : ISimulationAdapter
|
||||
public class UnrealThreatSourceAdapter
|
||||
{
|
||||
/// <summary>
|
||||
/// 虚幻引擎API接口,定义了与虚幻引擎交互的基本方法
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 该接口包含:
|
||||
/// - 获取Actor对象
|
||||
/// - 生成导弹实体
|
||||
/// 实际项目中需要根据具体需求扩展
|
||||
/// </remarks>
|
||||
public interface IUnrealEngine
|
||||
{
|
||||
/// <summary>
|
||||
/// 根据ID获取虚幻引擎中的Actor对象
|
||||
/// </summary>
|
||||
/// <param name="id">Actor的唯一标识符</param>
|
||||
/// <returns>对应的Actor对象,如果未找到则返回null</returns>
|
||||
object? GetActor(string id);
|
||||
|
||||
/// <summary>
|
||||
/// 在虚幻引擎中生成导弹实体
|
||||
/// </summary>
|
||||
/// <param name="senderId">发射者ID</param>
|
||||
/// <param name="targetId">目标ID</param>
|
||||
void SpawnMissile(string senderId, string targetId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 虚幻引擎实例
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 用于与虚幻引擎进行实际交互
|
||||
/// 通过依赖注入方式提供
|
||||
/// </remarks>
|
||||
private readonly IUnrealEngine _unrealEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 仿真管理器实例
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 用于管理仿真系统的核心功能
|
||||
/// 处理事件分发和状态同步
|
||||
/// </remarks>
|
||||
private readonly ISimulationManager _simulationManager;
|
||||
private ISimulationManager _simulationManager;
|
||||
|
||||
/// <summary>
|
||||
/// 数据管理器实例
|
||||
/// </summary>
|
||||
private ThreatSourceDataManager _dataManager;
|
||||
|
||||
/// <summary>
|
||||
/// 实体映射字典:仿真实体ID -> 虚幻引擎Actor引用
|
||||
/// </summary>
|
||||
private Dictionary<string, object> _entityActors = new Dictionary<string, object>();
|
||||
|
||||
/// <summary>
|
||||
/// 虚幻引擎接口(需要在实际项目中实现)
|
||||
/// </summary>
|
||||
public interface IUnrealEngineInterface
|
||||
{
|
||||
/// <summary>
|
||||
/// 在虚幻引擎中生成Actor
|
||||
/// </summary>
|
||||
/// <param name="actorClass">Actor类名</param>
|
||||
/// <param name="location">位置</param>
|
||||
/// <param name="rotation">旋转</param>
|
||||
/// <returns>生成的Actor引用</returns>
|
||||
object SpawnActor(string actorClass, Vector3 location, Vector3 rotation);
|
||||
|
||||
/// <summary>
|
||||
/// 销毁Actor
|
||||
/// </summary>
|
||||
/// <param name="actor">要销毁的Actor</param>
|
||||
void DestroyActor(object actor);
|
||||
|
||||
/// <summary>
|
||||
/// 设置Actor位置
|
||||
/// </summary>
|
||||
/// <param name="actor">Actor引用</param>
|
||||
/// <param name="location">新位置</param>
|
||||
void SetActorLocation(object actor, Vector3 location);
|
||||
|
||||
/// <summary>
|
||||
/// 设置Actor旋转
|
||||
/// </summary>
|
||||
/// <param name="actor">Actor引用</param>
|
||||
/// <param name="rotation">新旋转</param>
|
||||
void SetActorRotation(object actor, Vector3 rotation);
|
||||
|
||||
/// <summary>
|
||||
/// 播放特效
|
||||
/// </summary>
|
||||
/// <param name="effectName">特效名称</param>
|
||||
/// <param name="location">播放位置</param>
|
||||
void PlayEffect(string effectName, Vector3 location);
|
||||
}
|
||||
|
||||
private readonly IUnrealEngineInterface _unrealEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化虚幻引擎适配器的新实例
|
||||
/// </summary>
|
||||
/// <param name="unrealEngine">虚幻引擎实例</param>
|
||||
/// <param name="simulationManager">仿真管理器实例</param>
|
||||
/// <remarks>
|
||||
/// 构造过程:
|
||||
/// - 验证参数有效性
|
||||
/// - 初始化引擎实例
|
||||
/// - 初始化管理器实例
|
||||
/// </remarks>
|
||||
public UnrealEngineAdapter(IUnrealEngine unrealEngine, ISimulationManager simulationManager)
|
||||
/// <param name="unrealEngine">虚幻引擎接口实现</param>
|
||||
public UnrealThreatSourceAdapter(IUnrealEngineInterface unrealEngine)
|
||||
{
|
||||
_unrealEngine = unrealEngine ?? throw new ArgumentNullException(nameof(unrealEngine));
|
||||
_simulationManager = simulationManager ?? throw new ArgumentNullException(nameof(simulationManager));
|
||||
InitializeSimulation();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定ID的实体对象
|
||||
/// 初始化仿真系统
|
||||
/// </summary>
|
||||
/// <param name="id">实体的唯一标识符</param>
|
||||
/// <returns>对应的实体对象,如果未找到则返回null</returns>
|
||||
/// <remarks>
|
||||
/// 该方法将仿真系统的实体ID转换为虚幻引擎中的实体
|
||||
/// </remarks>
|
||||
public object? GetEntity(string id)
|
||||
private void InitializeSimulation()
|
||||
{
|
||||
return _unrealEngine.GetActor(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将事件发布到外部仿真系统(虚幻引擎)
|
||||
/// </summary>
|
||||
/// <typeparam name="T">事件类型</typeparam>
|
||||
/// <param name="evt">要发布的事件对象</param>
|
||||
/// <remarks>
|
||||
/// 处理过程:
|
||||
/// - 识别事件类型
|
||||
/// - 转换为虚幻引擎事件
|
||||
/// - 调用相应的引擎API
|
||||
/// </remarks>
|
||||
public void PublishToExternalSimulation<T>(T evt)
|
||||
{
|
||||
if (evt is MissileFireEvent missileEvt)
|
||||
try
|
||||
{
|
||||
_unrealEngine.SpawnMissile(missileEvt.SenderId, missileEvt.TargetId);
|
||||
// 创建仿真管理器和数据管理器
|
||||
_simulationManager = new SimulationManager();
|
||||
_dataManager = new ThreatSourceDataManager();
|
||||
|
||||
// 启动仿真
|
||||
_simulationManager.StartSimulation(0.02); // 20ms时间步长
|
||||
|
||||
// 订阅仿真事件
|
||||
_simulationManager.Subscribe<MissileFireEvent>(OnMissileFireEvent);
|
||||
_simulationManager.Subscribe<MissileExplodeEvent>(OnMissileExplodeEvent);
|
||||
_simulationManager.Subscribe<FlightPhaseChangeEvent>(OnFlightPhaseChangeEvent);
|
||||
|
||||
Console.WriteLine("ThreatSource仿真系统初始化成功");
|
||||
}
|
||||
// ... 处理其他事件类型
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 接收来自外部仿真系统(虚幻引擎)的事件
|
||||
/// </summary>
|
||||
/// <typeparam name="T">事件类型</typeparam>
|
||||
/// <param name="evt">接收到的事件对象</param>
|
||||
/// <remarks>
|
||||
/// 处理过程:
|
||||
/// - 接收虚幻引擎事件
|
||||
/// - 转换为仿真系统事件
|
||||
/// - 分发到相应的处理器
|
||||
/// </remarks>
|
||||
public void ReceiveFromExternalSimulation<T>(T evt)
|
||||
{
|
||||
// 处理来自虚幻引擎的事件
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理来自虚幻引擎的事件
|
||||
/// </summary>
|
||||
/// <param name="eventType">事件类型标识符</param>
|
||||
/// <param name="data">事件数据对象</param>
|
||||
/// <remarks>
|
||||
/// 处理过程:
|
||||
/// - 解析事件类型
|
||||
/// - 转换事件数据
|
||||
/// - 调用相应的处理方法
|
||||
/// </remarks>
|
||||
public void OnUnrealEvent(string eventType, UnrealEventData data)
|
||||
{
|
||||
if (eventType == "MissileFired")
|
||||
catch (Exception ex)
|
||||
{
|
||||
var evt = new MissileFireEvent
|
||||
{
|
||||
SenderId = data.SenderId,
|
||||
TargetId = data.TargetId
|
||||
Console.WriteLine($"仿真系统初始化失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新仿真(应在虚幻引擎的Tick中调用)
|
||||
/// </summary>
|
||||
public void UpdateSimulation()
|
||||
{
|
||||
if (_simulationManager != null)
|
||||
{
|
||||
// 更新仿真
|
||||
_simulationManager.UpdateSimulation();
|
||||
|
||||
// 同步实体状态
|
||||
SyncEntityStates();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步仿真实体状态到虚幻引擎Actor
|
||||
/// </summary>
|
||||
private void SyncEntityStates()
|
||||
{
|
||||
foreach (var kvp in _entityActors)
|
||||
{
|
||||
string entityId = kvp.Key;
|
||||
object actor = kvp.Value;
|
||||
|
||||
// 获取仿真实体
|
||||
var entity = _simulationManager.GetEntity(entityId);
|
||||
if (entity != null && entity.KState != null)
|
||||
{
|
||||
// 同步位置(转换坐标系:ThreatSource使用右手坐标系,虚幻引擎使用左手坐标系)
|
||||
var location = new Vector3(
|
||||
entity.KState.Position.X,
|
||||
-entity.KState.Position.Y, // Y轴翻转
|
||||
entity.KState.Position.Z
|
||||
);
|
||||
_unrealEngine.SetActorLocation(actor, location);
|
||||
|
||||
// 同步旋转
|
||||
var orientation = entity.KState.Orientation;
|
||||
var rotation = new Vector3(
|
||||
orientation.Pitch * 180.0f / Math.PI, // 转换为度
|
||||
-orientation.Yaw * 180.0f / Math.PI, // Y轴翻转
|
||||
orientation.Roll * 180.0f / Math.PI
|
||||
);
|
||||
_unrealEngine.SetActorRotation(actor, rotation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建导弹实体
|
||||
/// </summary>
|
||||
/// <param name="missileType">导弹类型</param>
|
||||
/// <param name="location">初始位置</param>
|
||||
/// <param name="targetId">目标ID</param>
|
||||
/// <returns>导弹ID</returns>
|
||||
public string CreateMissile(string missileType, Vector3 location, string targetId)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 从配置创建导弹
|
||||
var missileData = _dataManager.GetMissile(missileType);
|
||||
string missileId = $"missile_{Guid.NewGuid():N}";
|
||||
|
||||
var missile = new InfraredImagingTerminalGuidanceMissile(missileId, missileData)
|
||||
{
|
||||
KState = new KinematicState
|
||||
{
|
||||
Position = new ThreatSource.Simulation.Vector3(location.X, -location.Y, location.Z),
|
||||
Velocity = new ThreatSource.Simulation.Vector3(0, 0, 0),
|
||||
Orientation = new Orientation(0, 0, 0)
|
||||
}
|
||||
};
|
||||
_simulationManager.GetSimulationAdapter()?.ReceiveFromExternalSimulation(evt);
|
||||
|
||||
// 注册到仿真系统
|
||||
_simulationManager.RegisterEntity(missile);
|
||||
|
||||
// 在虚幻引擎中创建Actor
|
||||
var missileActor = _unrealEngine.SpawnActor("BP_Missile", location, new Vector3(0, 0, 0));
|
||||
if (missileActor != null)
|
||||
{
|
||||
// 建立映射关系
|
||||
_entityActors[missileId] = missileActor;
|
||||
|
||||
Console.WriteLine($"创建导弹: {missileId}, 目标: {targetId}");
|
||||
return missileId;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"无法在虚幻引擎中创建导弹Actor");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"创建导弹失败: {ex.Message}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 虚幻引擎事件数据结构
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 用于封装虚幻引擎事件的相关数据
|
||||
/// 包含事件发送者和目标的标识信息
|
||||
/// </remarks>
|
||||
public class UnrealEventData
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置事件发送者的ID
|
||||
/// </summary>
|
||||
public string? SenderId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置事件目标的ID
|
||||
/// 创建目标实体
|
||||
/// </summary>
|
||||
public string? TargetId { get; set; }
|
||||
/// <param name="targetId">目标ID</param>
|
||||
/// <param name="location">位置</param>
|
||||
/// <param name="velocity">速度</param>
|
||||
/// <returns>是否创建成功</returns>
|
||||
public bool CreateTarget(string targetId, Vector3 location, Vector3 velocity)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 创建目标实体
|
||||
var target = new BaseEquipment(targetId)
|
||||
{
|
||||
KState = new KinematicState
|
||||
{
|
||||
Position = new ThreatSource.Simulation.Vector3(location.X, -location.Y, location.Z),
|
||||
Velocity = new ThreatSource.Simulation.Vector3(velocity.X, -velocity.Y, velocity.Z),
|
||||
Orientation = new Orientation(0, 0, 0)
|
||||
}
|
||||
};
|
||||
|
||||
// 注册到仿真系统
|
||||
_simulationManager.RegisterEntity(target);
|
||||
|
||||
// 在虚幻引擎中创建Actor
|
||||
var targetActor = _unrealEngine.SpawnActor("BP_Target", location, new Vector3(0, 0, 0));
|
||||
if (targetActor != null)
|
||||
{
|
||||
// 建立映射关系
|
||||
_entityActors[targetId] = targetActor;
|
||||
|
||||
Console.WriteLine($"创建目标: {targetId}");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"无法在虚幻引擎中创建目标Actor");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"创建目标失败: {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理导弹发射事件
|
||||
/// </summary>
|
||||
private void OnMissileFireEvent(MissileFireEvent evt)
|
||||
{
|
||||
Console.WriteLine($"导弹发射事件: {evt.SenderId} -> {evt.TargetId}");
|
||||
|
||||
// 播放发射特效
|
||||
if (_entityActors.TryGetValue(evt.SenderId, out object missileActor))
|
||||
{
|
||||
// 获取导弹位置并播放发射特效
|
||||
var entity = _simulationManager.GetEntity(evt.SenderId);
|
||||
if (entity != null && entity.KState != null)
|
||||
{
|
||||
var location = new Vector3(
|
||||
entity.KState.Position.X,
|
||||
-entity.KState.Position.Y,
|
||||
entity.KState.Position.Z
|
||||
);
|
||||
_unrealEngine.PlayEffect("FX_MissileLaunch", location);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理导弹爆炸事件
|
||||
/// </summary>
|
||||
private void OnMissileExplodeEvent(MissileExplodeEvent evt)
|
||||
{
|
||||
Console.WriteLine($"导弹爆炸事件: {evt.SenderId} 在位置 {evt.Position}");
|
||||
|
||||
if (_entityActors.TryGetValue(evt.SenderId, out object missileActor))
|
||||
{
|
||||
// 播放爆炸特效
|
||||
var location = new Vector3(
|
||||
evt.Position.X,
|
||||
-evt.Position.Y,
|
||||
evt.Position.Z
|
||||
);
|
||||
_unrealEngine.PlayEffect("FX_Explosion", location);
|
||||
|
||||
// 销毁导弹Actor
|
||||
_unrealEngine.DestroyActor(missileActor);
|
||||
_entityActors.Remove(evt.SenderId);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理飞行阶段变化事件
|
||||
/// </summary>
|
||||
private void OnFlightPhaseChangeEvent(FlightPhaseChangeEvent evt)
|
||||
{
|
||||
Console.WriteLine($"导弹 {evt.SenderId} 进入 {evt.NewPhase} 阶段");
|
||||
|
||||
// 可以根据飞行阶段改变导弹的视觉表现
|
||||
if (_entityActors.TryGetValue(evt.SenderId, out object missileActor))
|
||||
{
|
||||
switch (evt.NewPhase)
|
||||
{
|
||||
case FlightPhase.Boost:
|
||||
// 助推阶段:播放推进器特效
|
||||
_unrealEngine.PlayEffect("FX_BoostTrail", GetActorLocation(missileActor));
|
||||
break;
|
||||
case FlightPhase.Midcourse:
|
||||
// 中段飞行:调整拖尾特效
|
||||
_unrealEngine.PlayEffect("FX_MidcourseTrail", GetActorLocation(missileActor));
|
||||
break;
|
||||
case FlightPhase.Terminal:
|
||||
// 末段制导:改变特效颜色
|
||||
_unrealEngine.PlayEffect("FX_TerminalTrail", GetActorLocation(missileActor));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取Actor位置(示例方法,实际需要通过虚幻引擎API实现)
|
||||
/// </summary>
|
||||
private Vector3 GetActorLocation(object actor)
|
||||
{
|
||||
// 这里应该调用虚幻引擎的API获取Actor位置
|
||||
// 示例返回零向量
|
||||
return new Vector3(0, 0, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理仿真系统
|
||||
/// </summary>
|
||||
public void Cleanup()
|
||||
{
|
||||
if (_simulationManager != null)
|
||||
{
|
||||
_simulationManager.StopSimulation();
|
||||
_simulationManager = null;
|
||||
}
|
||||
|
||||
// 清理Actor映射
|
||||
foreach (var actor in _entityActors.Values)
|
||||
{
|
||||
_unrealEngine.DestroyActor(actor);
|
||||
}
|
||||
_entityActors.Clear();
|
||||
|
||||
Console.WriteLine("ThreatSource仿真系统已清理");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -179,63 +377,123 @@ public class UnrealEventData
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 该类演示了:
|
||||
/// - 仿真系统的初始化
|
||||
/// - 适配器的配置
|
||||
/// - 事件的处理流程
|
||||
/// - 虚幻引擎仿真系统的初始化
|
||||
/// - 适配器的配置和使用
|
||||
/// - 事件系统的使用
|
||||
/// 用于指导实际项目中的集成实现
|
||||
/// </remarks>
|
||||
public class UnrealSimulation
|
||||
public class UnrealSimulationExample
|
||||
{
|
||||
/// <summary>
|
||||
/// 仿真管理器实例
|
||||
/// </summary>
|
||||
private readonly ISimulationManager _simulationManager;
|
||||
private UnrealThreatSourceAdapter _adapter;
|
||||
private UnrealThreatSourceAdapter.IUnrealEngineInterface _unrealEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 虚幻引擎实例
|
||||
/// 初始化示例
|
||||
/// </summary>
|
||||
private readonly UnrealEngineAdapter.IUnrealEngine _unrealEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化虚幻引擎仿真的新实例
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 初始化过程:
|
||||
/// - 创建仿真管理器
|
||||
/// - 创建引擎实例
|
||||
/// - 配置适配器
|
||||
/// </remarks>
|
||||
public UnrealSimulation()
|
||||
/// <param name="unrealEngine">虚幻引擎接口实现</param>
|
||||
public void Initialize(UnrealThreatSourceAdapter.IUnrealEngineInterface unrealEngine)
|
||||
{
|
||||
_simulationManager = new SimulationManager();
|
||||
_unrealEngine = new UnrealEngineImplementation(); // 实际项目中需要实现这个类
|
||||
_simulationManager.SetSimulationAdapter(
|
||||
new UnrealEngineAdapter(_unrealEngine, _simulationManager)
|
||||
);
|
||||
_unrealEngine = unrealEngine;
|
||||
_adapter = new UnrealThreatSourceAdapter(_unrealEngine);
|
||||
|
||||
Console.WriteLine("虚幻引擎ThreatSource集成示例初始化完成");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理虚幻引擎事件
|
||||
/// 运行示例场景
|
||||
/// </summary>
|
||||
/// <param name="eventType">事件类型标识符</param>
|
||||
/// <param name="data">事件数据对象</param>
|
||||
/// <remarks>
|
||||
/// 处理过程:
|
||||
/// - 识别事件类型
|
||||
/// - 转换事件数据
|
||||
/// - 通过适配器分发事件
|
||||
/// </remarks>
|
||||
public void OnUnrealEvent(string eventType, UnrealEventData data)
|
||||
public void RunExampleScene()
|
||||
{
|
||||
if (eventType == "MissileFired")
|
||||
try
|
||||
{
|
||||
var evt = new MissileFireEvent
|
||||
{
|
||||
SenderId = data.SenderId,
|
||||
TargetId = data.TargetId
|
||||
};
|
||||
_simulationManager.GetSimulationAdapter()?.ReceiveFromExternalSimulation(evt);
|
||||
// 创建目标
|
||||
var targetLocation = new Vector3(5000, 0, 1000); // 5km距离,1km高度
|
||||
var targetVelocity = new Vector3(-50, 0, 0); // 50m/s向西移动
|
||||
_adapter.CreateTarget("target_001", targetLocation, targetVelocity);
|
||||
|
||||
// 创建导弹
|
||||
var missileLocation = new Vector3(0, 0, 100); // 起始位置
|
||||
string missileId = _adapter.CreateMissile("IR_Missile_Example", missileLocation, "target_001");
|
||||
|
||||
if (!string.IsNullOrEmpty(missileId))
|
||||
{
|
||||
Console.WriteLine($"示例场景创建成功 - 导弹: {missileId}, 目标: target_001");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("示例场景创建失败");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"运行示例场景失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新仿真(应在虚幻引擎的Tick中调用)
|
||||
/// </summary>
|
||||
public void Tick()
|
||||
{
|
||||
_adapter?.UpdateSimulation();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理资源
|
||||
/// </summary>
|
||||
public void Cleanup()
|
||||
{
|
||||
_adapter?.Cleanup();
|
||||
Console.WriteLine("虚幻引擎ThreatSource集成示例已清理");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 虚幻引擎接口的示例实现(仅用于演示)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 实际项目中需要使用真实的虚幻引擎API实现此接口
|
||||
/// </remarks>
|
||||
public class MockUnrealEngineInterface : UnrealThreatSourceAdapter.IUnrealEngineInterface
|
||||
{
|
||||
private Dictionary<object, Vector3> _actorLocations = new Dictionary<object, Vector3>();
|
||||
private Dictionary<object, Vector3> _actorRotations = new Dictionary<object, Vector3>();
|
||||
|
||||
public object SpawnActor(string actorClass, Vector3 location, Vector3 rotation)
|
||||
{
|
||||
var actor = new object(); // 模拟Actor对象
|
||||
_actorLocations[actor] = location;
|
||||
_actorRotations[actor] = rotation;
|
||||
Console.WriteLine($"模拟生成Actor: {actorClass} 在位置 {location}");
|
||||
return actor;
|
||||
}
|
||||
|
||||
public void DestroyActor(object actor)
|
||||
{
|
||||
_actorLocations.Remove(actor);
|
||||
_actorRotations.Remove(actor);
|
||||
Console.WriteLine("模拟销毁Actor");
|
||||
}
|
||||
|
||||
public void SetActorLocation(object actor, Vector3 location)
|
||||
{
|
||||
if (_actorLocations.ContainsKey(actor))
|
||||
{
|
||||
_actorLocations[actor] = location;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetActorRotation(object actor, Vector3 rotation)
|
||||
{
|
||||
if (_actorRotations.ContainsKey(actor))
|
||||
{
|
||||
_actorRotations[actor] = rotation;
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayEffect(string effectName, Vector3 location)
|
||||
{
|
||||
Console.WriteLine($"模拟播放特效: {effectName} 在位置 {location}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
#if NEVER // 使用编译指令确保此文件永远不会被编译
|
||||
|
||||
// 第三方系统实现适配器示例代码
|
||||
// 以Unity引擎为例
|
||||
// 需要实现的方法: GetEntity, PublishToExternalSimulation, ReceiveFromExternalSimulation
|
||||
// Unity引擎集成示例代码
|
||||
// 展示如何将Unity引擎与ThreatSource仿真系统集成
|
||||
// 需要实现的核心功能: 实体同步、事件处理、状态管理
|
||||
|
||||
using ThreatSource.Simulation;
|
||||
using ThreatSource.Data;
|
||||
using ThreatSource.Missile;
|
||||
using UnityEngine; // 仅用于示例,实际项目中需要引用真实的Unity命名空间
|
||||
|
||||
/// <summary>
|
||||
@ -13,324 +15,412 @@ using UnityEngine; // 仅用于示例,实际项目中需要引用真实的Uni
|
||||
/// <remarks>
|
||||
/// 该类提供了以下功能:
|
||||
/// - Unity引擎与仿真系统的双向通信
|
||||
/// - GameObject与实体的映射和转换
|
||||
/// - GameObject与仿真实体的映射和同步
|
||||
/// - MonoBehaviour生命周期管理
|
||||
/// - 事件的发布和订阅
|
||||
/// - 数据的适配和转换
|
||||
/// 本示例代码仅作为参考,展示了基本的集成方法
|
||||
/// </remarks>
|
||||
public class UnityEngineAdapter : MonoBehaviour, ISimulationAdapter
|
||||
public class UnityThreatSourceAdapter : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// Unity引擎API接口,定义了与Unity引擎交互的基本方法
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 该接口包含:
|
||||
/// - 获取GameObject对象
|
||||
/// - 生成导弹预制体
|
||||
/// - 场景管理
|
||||
/// 实际项目中需要根据具体需求扩展
|
||||
/// </remarks>
|
||||
public interface IUnityEngine
|
||||
{
|
||||
/// <summary>
|
||||
/// 根据ID获取Unity场景中的GameObject对象
|
||||
/// </summary>
|
||||
/// <param name="id">GameObject的唯一标识符</param>
|
||||
/// <returns>对应的GameObject对象,如果未找到则返回null</returns>
|
||||
GameObject GetGameObject(string id);
|
||||
|
||||
/// <summary>
|
||||
/// 在Unity场景中实例化导弹预制体
|
||||
/// </summary>
|
||||
/// <param name="prefabPath">预制体资源路径</param>
|
||||
/// <param name="position">生成位置</param>
|
||||
/// <param name="rotation">生成朝向</param>
|
||||
/// <returns>生成的导弹GameObject实例</returns>
|
||||
GameObject InstantiateMissile(string prefabPath, Vector3 position, Quaternion rotation);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unity引擎实例
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 用于与Unity引擎进行实际交互
|
||||
/// 通过依赖注入方式提供
|
||||
/// </remarks>
|
||||
private readonly IUnityEngine _unityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 仿真管理器实例
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 用于管理仿真系统的核心功能
|
||||
/// 处理事件分发和状态同步
|
||||
/// </remarks>
|
||||
private readonly ISimulationManager _simulationManager;
|
||||
private ISimulationManager _simulationManager;
|
||||
|
||||
/// <summary>
|
||||
/// 数据管理器实例
|
||||
/// </summary>
|
||||
private ThreatSourceDataManager _dataManager;
|
||||
|
||||
/// <summary>
|
||||
/// 实体映射字典:仿真实体ID -> Unity GameObject
|
||||
/// </summary>
|
||||
private Dictionary<string, GameObject> _entityGameObjects = new Dictionary<string, GameObject>();
|
||||
|
||||
/// <summary>
|
||||
/// 导弹预制体路径
|
||||
/// </summary>
|
||||
private const string MissilePrefabPath = "Prefabs/Missile";
|
||||
[SerializeField]
|
||||
private string missilePrefabPath = "Prefabs/Missile";
|
||||
|
||||
/// <summary>
|
||||
/// 初始化Unity引擎适配器的新实例
|
||||
/// 目标预制体路径
|
||||
/// </summary>
|
||||
/// <param name="unityEngine">Unity引擎实例</param>
|
||||
/// <param name="simulationManager">仿真管理器实例</param>
|
||||
/// <remarks>
|
||||
/// 构造过程:
|
||||
/// - 验证参数有效性
|
||||
/// - 初始化引擎实例
|
||||
/// - 初始化管理器实例
|
||||
/// - 注册Unity生命周期事件
|
||||
/// </remarks>
|
||||
public UnityEngineAdapter(IUnityEngine unityEngine, ISimulationManager simulationManager)
|
||||
[SerializeField]
|
||||
private string targetPrefabPath = "Prefabs/Target";
|
||||
|
||||
/// <summary>
|
||||
/// 仿真时间步长
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
private float simulationTimeStep = 0.02f;
|
||||
|
||||
/// <summary>
|
||||
/// Unity生命周期方法:初始化
|
||||
/// </summary>
|
||||
private void Awake()
|
||||
{
|
||||
_unityEngine = unityEngine ?? throw new ArgumentNullException(nameof(unityEngine));
|
||||
_simulationManager = simulationManager ?? throw new ArgumentNullException(nameof(simulationManager));
|
||||
InitializeSimulation();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定ID的实体对象
|
||||
/// 初始化仿真系统
|
||||
/// </summary>
|
||||
/// <param name="id">实体的唯一标识符</param>
|
||||
/// <returns>对应的实体对象,如果未找到则返回null</returns>
|
||||
/// <remarks>
|
||||
/// 该方法将仿真系统的实体ID转换为Unity场景中的GameObject
|
||||
/// </remarks>
|
||||
public object? GetEntity(string id)
|
||||
private void InitializeSimulation()
|
||||
{
|
||||
return _unityEngine.GetGameObject(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将事件发布到外部仿真系统(Unity引擎)
|
||||
/// </summary>
|
||||
/// <typeparam name="T">事件类型</typeparam>
|
||||
/// <param name="evt">要发布的事件对象</param>
|
||||
/// <remarks>
|
||||
/// 处理过程:
|
||||
/// - 识别事件类型
|
||||
/// - 转换为Unity事件
|
||||
/// - 在Unity主线程中执行相应操作
|
||||
/// </remarks>
|
||||
public void PublishToExternalSimulation<T>(T evt)
|
||||
{
|
||||
if (evt is MissileFireEvent missileEvt)
|
||||
try
|
||||
{
|
||||
// 获取发射者位置和朝向
|
||||
var sender = _unityEngine.GetGameObject(missileEvt.SenderId);
|
||||
if (sender != null)
|
||||
{
|
||||
// 在Unity主线程中实例化导弹
|
||||
UnityMainThreadDispatcher.Instance.Enqueue(() =>
|
||||
{
|
||||
var missile = _unityEngine.InstantiateMissile(
|
||||
MissilePrefabPath,
|
||||
sender.transform.position,
|
||||
sender.transform.rotation
|
||||
);
|
||||
|
||||
// 设置导弹目标
|
||||
var missileComponent = missile.GetComponent<MissileController>();
|
||||
if (missileComponent != null)
|
||||
{
|
||||
missileComponent.SetTarget(missileEvt.TargetId);
|
||||
}
|
||||
});
|
||||
}
|
||||
// 创建仿真管理器和数据管理器
|
||||
_simulationManager = new SimulationManager();
|
||||
_dataManager = new ThreatSourceDataManager();
|
||||
|
||||
// 启动仿真
|
||||
_simulationManager.StartSimulation(simulationTimeStep);
|
||||
|
||||
// 订阅仿真事件
|
||||
_simulationManager.Subscribe<MissileFireEvent>(OnMissileFireEvent);
|
||||
_simulationManager.Subscribe<MissileExplodeEvent>(OnMissileExplodeEvent);
|
||||
_simulationManager.Subscribe<FlightPhaseChangeEvent>(OnFlightPhaseChangeEvent);
|
||||
|
||||
Debug.Log("ThreatSource仿真系统初始化成功");
|
||||
}
|
||||
// ... 处理其他事件类型
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 接收来自外部仿真系统(Unity引擎)的事件
|
||||
/// </summary>
|
||||
/// <typeparam name="T">事件类型</typeparam>
|
||||
/// <param name="evt">接收到的事件对象</param>
|
||||
/// <remarks>
|
||||
/// 处理过程:
|
||||
/// - 接收Unity事件
|
||||
/// - 转换为仿真系统事件
|
||||
/// - 分发到相应的处理器
|
||||
/// </remarks>
|
||||
public void ReceiveFromExternalSimulation<T>(T evt)
|
||||
{
|
||||
// 处理来自Unity引擎的事件
|
||||
if (evt is CollisionEvent collisionEvt)
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
// 处理碰撞事件
|
||||
_simulationManager.HandleCollision(collisionEvt);
|
||||
Debug.LogError($"仿真系统初始化失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unity生命周期方法:更新
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 在每一帧执行:
|
||||
/// - 更新实体状态
|
||||
/// - 处理输入事件
|
||||
/// - 同步仿真数据
|
||||
/// </remarks>
|
||||
private void Update()
|
||||
{
|
||||
// 在Unity的Update循环中同步状态
|
||||
SyncSimulationState();
|
||||
if (_simulationManager != null)
|
||||
{
|
||||
// 更新仿真
|
||||
_simulationManager.UpdateSimulation();
|
||||
|
||||
// 同步实体状态
|
||||
SyncEntityStates();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步仿真状态
|
||||
/// 同步仿真实体状态到Unity GameObject
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 同步过程:
|
||||
/// - 更新实体位置和朝向
|
||||
/// - 同步物理状态
|
||||
/// - 更新传感器数据
|
||||
/// </remarks>
|
||||
private void SyncSimulationState()
|
||||
private void SyncEntityStates()
|
||||
{
|
||||
// 实现仿真状态同步逻辑
|
||||
foreach (var kvp in _entityGameObjects)
|
||||
{
|
||||
string entityId = kvp.Key;
|
||||
GameObject gameObject = kvp.Value;
|
||||
|
||||
// 获取仿真实体
|
||||
var entity = _simulationManager.GetEntity(entityId);
|
||||
if (entity != null && entity.KState != null)
|
||||
{
|
||||
// 同步位置
|
||||
gameObject.transform.position = new Vector3(
|
||||
entity.KState.Position.X,
|
||||
entity.KState.Position.Z, // Unity使用Y作为高度
|
||||
entity.KState.Position.Y
|
||||
);
|
||||
|
||||
// 同步旋转
|
||||
var orientation = entity.KState.Orientation;
|
||||
gameObject.transform.rotation = Quaternion.Euler(
|
||||
orientation.Pitch * Mathf.Rad2Deg,
|
||||
orientation.Yaw * Mathf.Rad2Deg,
|
||||
orientation.Roll * Mathf.Rad2Deg
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unity事件数据基类
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 用于封装Unity事件的基本信息
|
||||
/// 所有具体的Unity事件类型都应该继承此类
|
||||
/// </remarks>
|
||||
public abstract class UnityEventData
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置事件发送者的ID
|
||||
/// </summary>
|
||||
public string? SenderId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置事件发生的时间戳
|
||||
/// 创建导弹实体
|
||||
/// </summary>
|
||||
public float TimeStamp { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unity碰撞事件数据
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 用于封装Unity物理碰撞事件的相关数据
|
||||
/// 包含碰撞的详细信息
|
||||
/// </remarks>
|
||||
public class CollisionEvent : UnityEventData
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置碰撞对象的ID
|
||||
/// </summary>
|
||||
public string? ColliderId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置碰撞点的位置
|
||||
/// </summary>
|
||||
public Vector3 CollisionPoint { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置碰撞的冲量
|
||||
/// </summary>
|
||||
public float ImpulseForce { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unity仿真示例类
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 该类演示了:
|
||||
/// - Unity仿真系统的初始化
|
||||
/// - MonoBehaviour组件的配置
|
||||
/// - 事件系统的使用
|
||||
/// 用于指导实际项目中的集成实现
|
||||
/// </remarks>
|
||||
public class UnitySimulation : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// 仿真管理器实例
|
||||
/// </summary>
|
||||
private readonly ISimulationManager _simulationManager;
|
||||
|
||||
/// <summary>
|
||||
/// Unity引擎实例
|
||||
/// </summary>
|
||||
private readonly UnityEngineAdapter.IUnityEngine _unityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Unity引擎适配器实例
|
||||
/// </summary>
|
||||
private UnityEngineAdapter _adapter;
|
||||
|
||||
/// <summary>
|
||||
/// Unity生命周期方法:初始化
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 初始化过程:
|
||||
/// - 创建仿真管理器
|
||||
/// - 创建引擎实例
|
||||
/// - 配置适配器
|
||||
/// - 初始化场景
|
||||
/// </remarks>
|
||||
private void Awake()
|
||||
/// <param name="missileType">导弹类型</param>
|
||||
/// <param name="position">初始位置</param>
|
||||
/// <param name="targetId">目标ID</param>
|
||||
public void CreateMissile(string missileType, Vector3 position, string targetId)
|
||||
{
|
||||
_simulationManager = new SimulationManager();
|
||||
_unityEngine = new UnityEngineImplementation(); // 实际项目中需要实现这个类
|
||||
try
|
||||
{
|
||||
// 从配置创建导弹
|
||||
var missileData = _dataManager.GetMissile(missileType);
|
||||
string missileId = $"missile_{System.Guid.NewGuid():N}";
|
||||
|
||||
var missile = new InfraredImagingTerminalGuidanceMissile(missileId, missileData)
|
||||
{
|
||||
KState = new KinematicState
|
||||
{
|
||||
Position = new ThreatSource.Simulation.Vector3(position.x, position.z, position.y),
|
||||
Velocity = new ThreatSource.Simulation.Vector3(0, 0, 0),
|
||||
Orientation = new Orientation(0, 0, 0)
|
||||
}
|
||||
};
|
||||
|
||||
// 注册到仿真系统
|
||||
_simulationManager.RegisterEntity(missile);
|
||||
|
||||
// 在Unity中创建GameObject
|
||||
var missilePrefab = Resources.Load<GameObject>(missilePrefabPath);
|
||||
if (missilePrefab != null)
|
||||
{
|
||||
var missileGameObject = Instantiate(missilePrefab, position, Quaternion.identity);
|
||||
missileGameObject.name = missileId;
|
||||
|
||||
// 添加导弹控制组件
|
||||
var missileController = missileGameObject.GetComponent<MissileController>();
|
||||
if (missileController == null)
|
||||
{
|
||||
missileController = missileGameObject.AddComponent<MissileController>();
|
||||
}
|
||||
missileController.Initialize(missileId, targetId);
|
||||
|
||||
// 建立映射关系
|
||||
_entityGameObjects[missileId] = missileGameObject;
|
||||
|
||||
Debug.Log($"创建导弹: {missileId}, 目标: {targetId}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"无法加载导弹预制体: {missilePrefabPath}");
|
||||
}
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
Debug.LogError($"创建导弹失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建目标实体
|
||||
/// </summary>
|
||||
/// <param name="targetId">目标ID</param>
|
||||
/// <param name="position">位置</param>
|
||||
/// <param name="velocity">速度</param>
|
||||
public void CreateTarget(string targetId, Vector3 position, Vector3 velocity)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 创建目标实体
|
||||
var target = new BaseEquipment(targetId)
|
||||
{
|
||||
KState = new KinematicState
|
||||
{
|
||||
Position = new ThreatSource.Simulation.Vector3(position.x, position.z, position.y),
|
||||
Velocity = new ThreatSource.Simulation.Vector3(velocity.x, velocity.z, velocity.y),
|
||||
Orientation = new Orientation(0, 0, 0)
|
||||
}
|
||||
};
|
||||
|
||||
// 注册到仿真系统
|
||||
_simulationManager.RegisterEntity(target);
|
||||
|
||||
// 在Unity中创建GameObject
|
||||
var targetPrefab = Resources.Load<GameObject>(targetPrefabPath);
|
||||
if (targetPrefab != null)
|
||||
{
|
||||
var targetGameObject = Instantiate(targetPrefab, position, Quaternion.identity);
|
||||
targetGameObject.name = targetId;
|
||||
|
||||
// 建立映射关系
|
||||
_entityGameObjects[targetId] = targetGameObject;
|
||||
|
||||
Debug.Log($"创建目标: {targetId}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"无法加载目标预制体: {targetPrefabPath}");
|
||||
}
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
Debug.LogError($"创建目标失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理导弹发射事件
|
||||
/// </summary>
|
||||
private void OnMissileFireEvent(MissileFireEvent evt)
|
||||
{
|
||||
Debug.Log($"导弹发射事件: {evt.SenderId} -> {evt.TargetId}");
|
||||
|
||||
// 创建并配置适配器
|
||||
_adapter = gameObject.AddComponent<UnityEngineAdapter>();
|
||||
_simulationManager.SetSimulationAdapter(_adapter);
|
||||
|
||||
// 初始化场景
|
||||
InitializeScene();
|
||||
// 可以在这里添加视觉效果,如发射烟雾、声音等
|
||||
var missileGameObject = GetGameObject(evt.SenderId);
|
||||
if (missileGameObject != null)
|
||||
{
|
||||
// 播放发射特效
|
||||
var particleSystem = missileGameObject.GetComponentInChildren<ParticleSystem>();
|
||||
if (particleSystem != null)
|
||||
{
|
||||
particleSystem.Play();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化Unity场景
|
||||
/// 处理导弹爆炸事件
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 初始化过程:
|
||||
/// - 加载必要的资源
|
||||
/// - 创建初始实体
|
||||
/// - 设置场景参数
|
||||
/// </remarks>
|
||||
private void InitializeScene()
|
||||
private void OnMissileExplodeEvent(MissileExplodeEvent evt)
|
||||
{
|
||||
// 实现场景初始化逻辑
|
||||
Debug.Log($"导弹爆炸事件: {evt.SenderId} 在位置 {evt.Position}");
|
||||
|
||||
var missileGameObject = GetGameObject(evt.SenderId);
|
||||
if (missileGameObject != null)
|
||||
{
|
||||
// 播放爆炸特效
|
||||
var explosionPrefab = Resources.Load<GameObject>("Prefabs/Explosion");
|
||||
if (explosionPrefab != null)
|
||||
{
|
||||
Instantiate(explosionPrefab, missileGameObject.transform.position, Quaternion.identity);
|
||||
}
|
||||
|
||||
// 销毁导弹GameObject
|
||||
Destroy(missileGameObject);
|
||||
_entityGameObjects.Remove(evt.SenderId);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理飞行阶段变化事件
|
||||
/// </summary>
|
||||
private void OnFlightPhaseChangeEvent(FlightPhaseChangeEvent evt)
|
||||
{
|
||||
Debug.Log($"导弹 {evt.SenderId} 进入 {evt.NewPhase} 阶段");
|
||||
|
||||
// 可以根据飞行阶段改变导弹的视觉表现
|
||||
var missileGameObject = GetGameObject(evt.SenderId);
|
||||
if (missileGameObject != null)
|
||||
{
|
||||
var missileController = missileGameObject.GetComponent<MissileController>();
|
||||
if (missileController != null)
|
||||
{
|
||||
missileController.OnFlightPhaseChanged(evt.NewPhase);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据实体ID获取对应的GameObject
|
||||
/// </summary>
|
||||
private GameObject GetGameObject(string entityId)
|
||||
{
|
||||
_entityGameObjects.TryGetValue(entityId, out GameObject gameObject);
|
||||
return gameObject;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unity生命周期方法:销毁
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 清理过程:
|
||||
/// - 释放资源
|
||||
/// - 清理事件订阅
|
||||
/// - 保存必要数据
|
||||
/// </remarks>
|
||||
private void OnDestroy()
|
||||
{
|
||||
// 清理资源和状态
|
||||
CleanupSimulation();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理仿真系统
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 清理过程:
|
||||
/// - 停止所有协程
|
||||
/// - 移除事件监听
|
||||
/// - 销毁动态创建的对象
|
||||
/// </remarks>
|
||||
private void CleanupSimulation()
|
||||
{
|
||||
// 实现清理逻辑
|
||||
if (_simulationManager != null)
|
||||
{
|
||||
_simulationManager.StopSimulation();
|
||||
_simulationManager = null;
|
||||
}
|
||||
|
||||
// 清理GameObject映射
|
||||
foreach (var gameObject in _entityGameObjects.Values)
|
||||
{
|
||||
if (gameObject != null)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
_entityGameObjects.Clear();
|
||||
|
||||
Debug.Log("ThreatSource仿真系统已清理");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导弹控制器组件
|
||||
/// </summary>
|
||||
public class MissileController : MonoBehaviour
|
||||
{
|
||||
private string _missileId;
|
||||
private string _targetId;
|
||||
private TrailRenderer _trailRenderer;
|
||||
|
||||
public void Initialize(string missileId, string targetId)
|
||||
{
|
||||
_missileId = missileId;
|
||||
_targetId = targetId;
|
||||
|
||||
// 获取拖尾渲染器
|
||||
_trailRenderer = GetComponent<TrailRenderer>();
|
||||
if (_trailRenderer == null)
|
||||
{
|
||||
_trailRenderer = gameObject.AddComponent<TrailRenderer>();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnFlightPhaseChanged(FlightPhase newPhase)
|
||||
{
|
||||
// 根据飞行阶段调整视觉效果
|
||||
switch (newPhase)
|
||||
{
|
||||
case FlightPhase.Boost:
|
||||
// 助推阶段:显示推进器火焰
|
||||
break;
|
||||
case FlightPhase.Midcourse:
|
||||
// 中段飞行:调整拖尾效果
|
||||
if (_trailRenderer != null)
|
||||
{
|
||||
_trailRenderer.enabled = true;
|
||||
}
|
||||
break;
|
||||
case FlightPhase.Terminal:
|
||||
// 末段制导:可能改变颜色或效果
|
||||
if (_trailRenderer != null)
|
||||
{
|
||||
_trailRenderer.material.color = Color.red;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 示例使用脚本
|
||||
/// </summary>
|
||||
public class ThreatSourceExample : MonoBehaviour
|
||||
{
|
||||
private UnityThreatSourceAdapter _adapter;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// 获取适配器组件
|
||||
_adapter = FindObjectOfType<UnityThreatSourceAdapter>();
|
||||
if (_adapter == null)
|
||||
{
|
||||
_adapter = gameObject.AddComponent<UnityThreatSourceAdapter>();
|
||||
}
|
||||
|
||||
// 延迟创建示例场景
|
||||
Invoke(nameof(CreateExampleScene), 1.0f);
|
||||
}
|
||||
|
||||
private void CreateExampleScene()
|
||||
{
|
||||
// 创建目标
|
||||
_adapter.CreateTarget("target_001", new Vector3(1000, 0, 100), new Vector3(-50, 0, 0));
|
||||
|
||||
// 创建导弹
|
||||
_adapter.CreateMissile("IR_Missile_Example", Vector3.zero, "target_001");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -3,126 +3,160 @@
|
||||
* 实际项目中需要:
|
||||
* 1. 创建C++/CLI项目
|
||||
* 2. 引用ThreatSource.dll
|
||||
* 3. 配置正确的目标框架
|
||||
* 3. 配置正确的目标框架(.NET 8.0)
|
||||
*/
|
||||
|
||||
using namespace System;
|
||||
using namespace ThreatSource::Simulation;
|
||||
using namespace ThreatSource::Guidance;
|
||||
using namespace ThreatSource::Sensor;
|
||||
using namespace ThreatSource::Data;
|
||||
using namespace ThreatSource::Missile;
|
||||
|
||||
namespace ThreatSourceWrapper {
|
||||
|
||||
// 包装类,用于在C++中使用仿真系统
|
||||
/// <summary>
|
||||
/// C++/CLI包装类,用于在C++项目中使用红外成像制导导弹仿真
|
||||
/// </summary>
|
||||
public ref class IRMissileSimulationWrapper
|
||||
{
|
||||
private:
|
||||
TestSimulationAdapter^ adapter;
|
||||
SimulationEntity^ missile;
|
||||
SimulationEntity^ target;
|
||||
InfraredImagingGuidanceSystem^ guidanceSystem;
|
||||
ISimulationManager^ simulationManager;
|
||||
ThreatSourceDataManager^ dataManager;
|
||||
|
||||
public:
|
||||
IRMissileSimulationWrapper()
|
||||
{
|
||||
adapter = gcnew TestSimulationAdapter();
|
||||
simulationManager = gcnew SimulationManager();
|
||||
dataManager = gcnew ThreatSourceDataManager();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 运行红外成像制导导弹仿真示例
|
||||
/// </summary>
|
||||
void RunSimulationExample()
|
||||
{
|
||||
try {
|
||||
// 步骤1:创建导弹实体
|
||||
missile = gcnew SimulationEntity();
|
||||
missile->Id = "missile_001";
|
||||
missile->Position = Vector3(0, 0, 0);
|
||||
missile->Velocity = Vector3(0, 0, 0);
|
||||
missile->Mass = 100.0f; // kg
|
||||
// 步骤1:初始化仿真管理器
|
||||
simulationManager->StartSimulation(0.02); // 20ms时间步长
|
||||
|
||||
// 步骤2:配置红外成像制导系统
|
||||
guidanceSystem = gcnew InfraredImagingGuidanceSystem();
|
||||
guidanceSystem->FieldOfView = 60.0f; // 视场角(度)
|
||||
guidanceSystem->TrackingRange = 20000.0f; // 最大跟踪距离(米)
|
||||
guidanceSystem->UpdateRate = 50; // 制导更新频率(Hz)
|
||||
// 步骤2:创建目标实体
|
||||
auto target = gcnew BaseEquipment("target_001");
|
||||
target->KState = gcnew KinematicState();
|
||||
target->KState->Position = Vector3(5000, 0, 1000); // 5km距离,1km高度
|
||||
target->KState->Velocity = Vector3(-50, 0, 0); // 50m/s向西移动
|
||||
target->KState->Orientation = Orientation(0, 0, 0);
|
||||
|
||||
missile->GuidanceSystem = guidanceSystem;
|
||||
// 步骤3:从配置创建红外成像制导导弹
|
||||
auto missileData = dataManager->GetMissile("IR_Missile_Example");
|
||||
auto missile = gcnew InfraredImagingTerminalGuidanceMissile("missile_001", missileData);
|
||||
missile->KState = gcnew KinematicState();
|
||||
missile->KState->Position = Vector3(0, 0, 100); // 起始位置
|
||||
missile->KState->Velocity = Vector3(200, 0, 0); // 初始速度200m/s
|
||||
missile->KState->Orientation = Orientation(0, 0, 0); // 初始朝向
|
||||
|
||||
// 步骤3:设置目标
|
||||
target = gcnew SimulationEntity();
|
||||
target->Id = "target_001";
|
||||
target->Position = Vector3(10000.0f, 1000.0f, 1000.0f); // 目标在10km外
|
||||
target->Velocity = Vector3(-100.0f, 0.0f, 0.0f); // 目标以100m/s速度移动
|
||||
// 步骤4:注册实体到仿真管理器
|
||||
simulationManager->RegisterEntity(target);
|
||||
simulationManager->RegisterEntity(missile);
|
||||
|
||||
InfraredSignature^ signature = gcnew InfraredSignature();
|
||||
signature->Temperature = 400.0f; // 目标温度(开尔文)
|
||||
signature->EmissivityFactor = 0.8f;
|
||||
target->Signature = signature;
|
||||
// 步骤5:订阅仿真事件
|
||||
simulationManager->Subscribe<MissileExplodeEvent^>(
|
||||
gcnew Action<MissileExplodeEvent^>(this, &IRMissileSimulationWrapper::OnMissileExplode)
|
||||
);
|
||||
simulationManager->Subscribe<FlightPhaseChangeEvent^>(
|
||||
gcnew Action<FlightPhaseChangeEvent^>(this, &IRMissileSimulationWrapper::OnFlightPhaseChange)
|
||||
);
|
||||
|
||||
// 步骤4:配置仿真参数
|
||||
SimulationConfig^ config = gcnew SimulationConfig();
|
||||
config->TimeStep = 0.02f; // 仿真步长(秒)
|
||||
config->MaxSimulationTime = 60.0f; // 最大仿真时间(秒)
|
||||
// 步骤6:运行仿真循环
|
||||
double simulationTime = 0;
|
||||
double maxTime = 60.0; // 最大仿真时间60秒
|
||||
|
||||
EnvironmentConditions^ env = gcnew EnvironmentConditions();
|
||||
env->Temperature = 288.15f; // 环境温度(开尔文)
|
||||
env->Pressure = 101325.0f; // 大气压力(帕)
|
||||
env->Humidity = 0.5f; // 相对湿度
|
||||
config->EnvironmentConditions = env;
|
||||
Console::WriteLine("开始红外成像制导导弹仿真...");
|
||||
Console::WriteLine("目标位置: ({0}, {1}, {2})",
|
||||
target->KState->Position.X,
|
||||
target->KState->Position.Y,
|
||||
target->KState->Position.Z);
|
||||
Console::WriteLine("导弹初始位置: ({0}, {1}, {2})",
|
||||
missile->KState->Position.X,
|
||||
missile->KState->Position.Y,
|
||||
missile->KState->Position.Z);
|
||||
|
||||
// 步骤5:注册事件处理
|
||||
adapter->EntityUpdated += gcnew EntityUpdateHandler(this, &IRMissileSimulationWrapper::OnEntityUpdated);
|
||||
adapter->GuidanceUpdate += gcnew GuidanceUpdateHandler(this, &IRMissileSimulationWrapper::OnGuidanceUpdate);
|
||||
|
||||
// 步骤6:初始化仿真
|
||||
adapter->Initialize(config);
|
||||
adapter->AddEntity(missile);
|
||||
adapter->AddEntity(target);
|
||||
|
||||
// 步骤7:启动仿真
|
||||
adapter->StartSimulation();
|
||||
|
||||
// 步骤8:等待仿真结束
|
||||
while (adapter->IsRunning)
|
||||
while (simulationTime < maxTime && missile->IsActive)
|
||||
{
|
||||
System::Threading::Thread::Sleep(100);
|
||||
// 更新仿真
|
||||
simulationManager->UpdateSimulation();
|
||||
simulationTime = simulationManager->CurrentTime;
|
||||
|
||||
// 每秒输出一次状态
|
||||
if (Math::Abs(simulationTime - Math::Floor(simulationTime)) < 0.02)
|
||||
{
|
||||
auto distance = Vector3::Distance(missile->KState->Position, target->KState->Position);
|
||||
Console::WriteLine("时间: {0:F1}s, 距离目标: {1:F1}m, 导弹阶段: {2}",
|
||||
simulationTime, distance, missile->FlightPhase);
|
||||
}
|
||||
|
||||
System::Threading::Thread::Sleep(1); // 避免阻塞
|
||||
}
|
||||
|
||||
// 步骤9:获取仿真结果
|
||||
SimulationResults^ results = adapter->GetSimulationResults();
|
||||
Console::WriteLine(String::Format("仿真结束,命中精度: {0:F2}米", results->MissDistance));
|
||||
// 步骤7:输出仿真结果
|
||||
auto finalDistance = Vector3::Distance(missile->KState->Position, target->KState->Position);
|
||||
Console::WriteLine("仿真结束 - 最终距离: {0:F2}m", finalDistance);
|
||||
|
||||
if (finalDistance < 10.0)
|
||||
{
|
||||
Console::WriteLine("导弹成功命中目标!");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console::WriteLine("导弹未能命中目标。");
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception^ e) {
|
||||
Console::WriteLine(String::Format("仿真过程出错: {0}", e->Message));
|
||||
Console::WriteLine("仿真过程出错: {0}", e->Message);
|
||||
}
|
||||
finally {
|
||||
// 清理资源
|
||||
simulationManager->StopSimulation();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void OnEntityUpdated(SimulationEntity^ entity)
|
||||
/// <summary>
|
||||
/// 处理导弹爆炸事件
|
||||
/// </summary>
|
||||
void OnMissileExplode(MissileExplodeEvent^ evt)
|
||||
{
|
||||
Console::WriteLine(String::Format("实体 {0} 位置更新: ({1:F2}, {2:F2}, {3:F2})",
|
||||
entity->Id,
|
||||
entity->Position.X,
|
||||
entity->Position.Y,
|
||||
entity->Position.Z));
|
||||
Console::WriteLine("导弹 {0} 在位置 ({1}, {2}, {3}) 爆炸",
|
||||
evt->SenderId,
|
||||
evt->Position.X,
|
||||
evt->Position.Y,
|
||||
evt->Position.Z);
|
||||
}
|
||||
|
||||
void OnGuidanceUpdate(GuidanceInfo^ info)
|
||||
/// <summary>
|
||||
/// 处理飞行阶段变化事件
|
||||
/// </summary>
|
||||
void OnFlightPhaseChange(FlightPhaseChangeEvent^ evt)
|
||||
{
|
||||
Console::WriteLine(String::Format("制导更新: 距离目标 {0:F2}米", info->DistanceToTarget));
|
||||
Console::WriteLine("导弹 {0} 进入 {1} 阶段", evt->SenderId, evt->NewPhase);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// 示例:如何在原生C++代码中使用包装类
|
||||
/// <summary>
|
||||
/// 示例:如何在原生C++代码中使用包装类
|
||||
/// </summary>
|
||||
int main()
|
||||
{
|
||||
try {
|
||||
auto simulation = gcnew ThreatSourceWrapper::IRMissileSimulationWrapper();
|
||||
simulation->RunSimulationExample();
|
||||
|
||||
Console::WriteLine("按任意键退出...");
|
||||
Console::ReadKey();
|
||||
return 0;
|
||||
}
|
||||
catch (Exception^ e) {
|
||||
Console::WriteLine(String::Format("错误: {0}", e->Message));
|
||||
Console::WriteLine("错误: {0}", e->Message);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using ThreatSource.Simulation;
|
||||
using ThreatSource.Guidance;
|
||||
using ThreatSource.Sensor;
|
||||
using ThreatSource.Data;
|
||||
using ThreatSource.Missile;
|
||||
|
||||
namespace ThreatSource.Examples
|
||||
{
|
||||
@ -15,97 +15,133 @@ namespace ThreatSource.Examples
|
||||
/// </summary>
|
||||
public class IRMissileSimulationExample
|
||||
{
|
||||
private TestSimulationAdapter _adapter;
|
||||
private SimulationEntity _missile;
|
||||
private SimulationEntity _target;
|
||||
private InfraredImagingGuidanceSystem _guidanceSystem;
|
||||
private ISimulationManager _simulationManager;
|
||||
private ThreatSourceDataManager _dataManager;
|
||||
|
||||
public IRMissileSimulationExample()
|
||||
{
|
||||
_simulationManager = new SimulationManager();
|
||||
_dataManager = new ThreatSourceDataManager();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 运行红外成像制导导弹仿真示例
|
||||
/// </summary>
|
||||
public async Task RunSimulationExample()
|
||||
{
|
||||
try
|
||||
{
|
||||
// 步骤1:创建导弹实体
|
||||
_missile = new SimulationEntity
|
||||
{
|
||||
Id = "missile_001",
|
||||
Position = new Vector3(0, 0, 0),
|
||||
Velocity = new Vector3(0, 0, 0),
|
||||
Mass = 100.0f // kg
|
||||
};
|
||||
// 步骤1:初始化仿真管理器
|
||||
_simulationManager.StartSimulation(0.02); // 20ms时间步长
|
||||
|
||||
// 步骤2:配置红外成像制导系统
|
||||
_guidanceSystem = new InfraredImagingGuidanceSystem
|
||||
// 步骤2:创建目标实体
|
||||
var target = new BaseEquipment("target_001")
|
||||
{
|
||||
FieldOfView = 60.0f, // 视场角(度)
|
||||
TrackingRange = 20000.0f, // 最大跟踪距离(米)
|
||||
UpdateRate = 50 // 制导更新频率(Hz)
|
||||
};
|
||||
|
||||
_missile.GuidanceSystem = _guidanceSystem;
|
||||
|
||||
// 步骤3:设置目标
|
||||
_target = new SimulationEntity
|
||||
{
|
||||
Id = "target_001",
|
||||
Position = new Vector3(10000.0f, 1000.0f, 1000.0f), // 目标在10km外
|
||||
Velocity = new Vector3(-100.0f, 0.0f, 0.0f), // 目标以100m/s速度移动
|
||||
Signature = new InfraredSignature
|
||||
KState = new KinematicState
|
||||
{
|
||||
Temperature = 400.0f, // 目标温度(开尔文)
|
||||
EmissivityFactor = 0.8f
|
||||
Position = new Vector3(5000, 0, 1000), // 5km距离,1km高度
|
||||
Velocity = new Vector3(-50, 0, 0), // 50m/s向西移动
|
||||
Orientation = new Orientation(0, 0, 0)
|
||||
}
|
||||
};
|
||||
|
||||
// 步骤4:配置仿真参数
|
||||
var config = new SimulationConfig
|
||||
// 步骤3:从配置创建红外成像制导导弹
|
||||
var missileData = _dataManager.GetMissile("IR_Missile_Example");
|
||||
var missile = new InfraredImagingTerminalGuidanceMissile("missile_001", missileData)
|
||||
{
|
||||
TimeStep = 0.02f, // 仿真步长(秒)
|
||||
MaxSimulationTime = 60.0f, // 最大仿真时间(秒)
|
||||
EnvironmentConditions = new EnvironmentConditions
|
||||
KState = new KinematicState
|
||||
{
|
||||
Temperature = 288.15f, // 环境温度(开尔文)
|
||||
Pressure = 101325.0f, // 大气压力(帕)
|
||||
Humidity = 0.5f // 相对湿度
|
||||
Position = new Vector3(0, 0, 100), // 起始位置
|
||||
Velocity = new Vector3(200, 0, 0), // 初始速度200m/s
|
||||
Orientation = new Orientation(0, 0, 0) // 初始朝向
|
||||
}
|
||||
};
|
||||
|
||||
// 步骤5:创建仿真适配器并注册事件
|
||||
_adapter = new TestSimulationAdapter();
|
||||
_adapter.EntityUpdated += OnEntityUpdated;
|
||||
_adapter.GuidanceUpdate += OnGuidanceUpdate;
|
||||
// 步骤4:注册实体到仿真管理器
|
||||
_simulationManager.RegisterEntity(target);
|
||||
_simulationManager.RegisterEntity(missile);
|
||||
|
||||
// 步骤6:初始化仿真
|
||||
await _adapter.Initialize(config);
|
||||
await _adapter.AddEntity(_missile);
|
||||
await _adapter.AddEntity(_target);
|
||||
// 步骤5:订阅仿真事件
|
||||
_simulationManager.Subscribe<MissileExplodeEvent>(OnMissileExplode);
|
||||
_simulationManager.Subscribe<FlightPhaseChangeEvent>(OnFlightPhaseChange);
|
||||
|
||||
// 步骤7:启动仿真
|
||||
await _adapter.StartSimulation();
|
||||
// 步骤6:运行仿真循环
|
||||
double simulationTime = 0;
|
||||
double maxTime = 60.0; // 最大仿真时间60秒
|
||||
|
||||
// 步骤8:等待仿真结束
|
||||
while (_adapter.IsRunning)
|
||||
Console.WriteLine("开始红外成像制导导弹仿真...");
|
||||
Console.WriteLine($"目标位置: {target.KState.Position}");
|
||||
Console.WriteLine($"导弹初始位置: {missile.KState.Position}");
|
||||
|
||||
while (simulationTime < maxTime && missile.IsActive)
|
||||
{
|
||||
await Task.Delay(100);
|
||||
// 更新仿真
|
||||
_simulationManager.UpdateSimulation();
|
||||
simulationTime = _simulationManager.CurrentTime;
|
||||
|
||||
// 每秒输出一次状态
|
||||
if (simulationTime % 1.0 < 0.02)
|
||||
{
|
||||
var distance = Vector3.Distance(missile.KState.Position, target.KState.Position);
|
||||
Console.WriteLine($"时间: {simulationTime:F1}s, 距离目标: {distance:F1}m, 导弹阶段: {missile.FlightPhase}");
|
||||
}
|
||||
|
||||
await Task.Delay(1); // 避免阻塞
|
||||
}
|
||||
|
||||
// 步骤9:获取仿真结果
|
||||
var results = await _adapter.GetSimulationResults();
|
||||
Trace.TraceInformation($"仿真结束,命中精度: {results.MissDistance:F2}米");
|
||||
// 步骤7:输出仿真结果
|
||||
var finalDistance = Vector3.Distance(missile.KState.Position, target.KState.Position);
|
||||
Console.WriteLine($"仿真结束 - 最终距离: {finalDistance:F2}m");
|
||||
|
||||
if (finalDistance < 10.0)
|
||||
{
|
||||
Console.WriteLine("导弹成功命中目标!");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("导弹未能命中目标。");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Trace.TraceError($"仿真过程出错: {ex.Message}");
|
||||
Console.WriteLine($"仿真过程出错: {ex.Message}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
// 清理资源
|
||||
_simulationManager.StopSimulation();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEntityUpdated(SimulationEntity entity)
|
||||
/// <summary>
|
||||
/// 处理导弹爆炸事件
|
||||
/// </summary>
|
||||
private void OnMissileExplode(MissileExplodeEvent evt)
|
||||
{
|
||||
Trace.TraceInformation($"实体 {entity.Id} 位置更新: ({entity.Position.X:F2}, {entity.Position.Y:F2}, {entity.Position.Z:F2})");
|
||||
Console.WriteLine($"导弹 {evt.SenderId} 在位置 {evt.Position} 爆炸");
|
||||
}
|
||||
|
||||
private void OnGuidanceUpdate(GuidanceInfo info)
|
||||
/// <summary>
|
||||
/// 处理飞行阶段变化事件
|
||||
/// </summary>
|
||||
private void OnFlightPhaseChange(FlightPhaseChangeEvent evt)
|
||||
{
|
||||
Trace.TraceInformation($"制导更新: 距离目标 {info.DistanceToTarget:F2}米");
|
||||
Console.WriteLine($"导弹 {evt.SenderId} 进入 {evt.NewPhase} 阶段");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 示例程序入口点
|
||||
/// </summary>
|
||||
public class Program
|
||||
{
|
||||
public static async Task Main(string[] args)
|
||||
{
|
||||
var example = new IRMissileSimulationExample();
|
||||
await example.RunSimulationExample();
|
||||
|
||||
Console.WriteLine("按任意键退出...");
|
||||
Console.ReadKey();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,10 +1,16 @@
|
||||
# 导弹仿真示例
|
||||
|
||||
本目录包含了使用仿真系统进行导弹仿真的示例代码。这些示例展示了如何配置和运行不同类型的导弹仿真。
|
||||
本目录包含了使用ThreatSource仿真系统进行导弹仿真的示例代码。这些示例展示了如何配置和运行不同类型的导弹仿真。
|
||||
|
||||
## 关于本库
|
||||
|
||||
ThreatSource 是一个基于 .NET 8.0 的类库,提供了完整的导弹仿真功能。
|
||||
ThreatSource 是一个基于 .NET 8.0 的类库,提供了完整的导弹仿真功能,包括:
|
||||
|
||||
- 多种制导系统(激光、红外、毫米波等)
|
||||
- 运动学仿真和物理建模
|
||||
- 事件驱动的仿真架构
|
||||
- 智能数据管理系统
|
||||
- 外部系统集成支持
|
||||
|
||||
## 系统要求
|
||||
|
||||
@ -12,13 +18,15 @@ ThreatSource 是一个基于 .NET 8.0 的类库,提供了完整的导弹仿真
|
||||
|
||||
- .NET 8.0 或更高版本
|
||||
- 通过 NuGet 包管理器安装或直接引用 ThreatSource.dll
|
||||
- Visual Studio 2019+ 或 Visual Studio Code
|
||||
|
||||
### C++用户
|
||||
|
||||
本库是一个 .NET 类库,C++用户需要通过 C++/CLI 包装层来使用:
|
||||
|
||||
- Windows 操作系统
|
||||
- Visual Studio 2019 或更高版本
|
||||
- Visual Studio 2019 或更高版本(支持C++/CLI)
|
||||
- .NET 8.0 运行时
|
||||
- 创建 C++/CLI 项目并引用 ThreatSource.dll
|
||||
|
||||
## 示例文件
|
||||
@ -27,116 +35,65 @@ ThreatSource 是一个基于 .NET 8.0 的类库,提供了完整的导弹仿真
|
||||
|
||||
红外成像制导导弹仿真示例,展示了:
|
||||
|
||||
- 如何创建和配置导弹实体
|
||||
- 如何设置红外成像制导系统
|
||||
- 如何配置仿真环境和参数
|
||||
- 如何运行仿真并获取结果
|
||||
- 如何使用SimulationManager管理仿真
|
||||
- 如何从配置文件创建导弹实体
|
||||
- 如何设置目标和仿真环境
|
||||
- 如何订阅和处理仿真事件
|
||||
- 如何运行仿真循环并获取结果
|
||||
|
||||
#### 源代码
|
||||
#### 核心代码片段
|
||||
|
||||
```csharp
|
||||
using ThreatSource.Simulation;
|
||||
using ThreatSource.Data;
|
||||
using ThreatSource.Missile;
|
||||
using ThreatSource.Sensor;
|
||||
using ThreatSource.Target;
|
||||
|
||||
/// <summary>
|
||||
/// 红外成像制导导弹仿真示例
|
||||
/// </summary>
|
||||
public class IRMissileSimulation
|
||||
public class IRMissileSimulationExample
|
||||
{
|
||||
private readonly ISimulationManager _simulationManager;
|
||||
private readonly IMissileFactory _missileFactory;
|
||||
private readonly ITargetFactory _targetFactory;
|
||||
private readonly ISensorFactory _sensorFactory;
|
||||
private ISimulationManager _simulationManager;
|
||||
private ThreatSourceDataManager _dataManager;
|
||||
|
||||
public IRMissileSimulation()
|
||||
public async Task RunSimulationExample()
|
||||
{
|
||||
// 1. 初始化仿真管理器
|
||||
_simulationManager = new SimulationManager();
|
||||
_missileFactory = new MissileFactory();
|
||||
_targetFactory = new TargetFactory();
|
||||
_sensorFactory = new SensorFactory();
|
||||
}
|
||||
_dataManager = new ThreatSourceDataManager();
|
||||
_simulationManager.StartSimulation(0.02); // 20ms时间步长
|
||||
|
||||
/// <summary>
|
||||
/// 运行仿真
|
||||
/// </summary>
|
||||
public async Task RunSimulation()
|
||||
{
|
||||
// 创建目标
|
||||
var target = _targetFactory.CreateTarget(new TargetConfig
|
||||
// 2. 创建目标实体
|
||||
var target = new BaseEquipment("target_001")
|
||||
{
|
||||
Id = "target_001",
|
||||
Position = new Vector3(1000, 0, 100),
|
||||
Velocity = new Vector3(-100, 0, 0),
|
||||
Signature = new IRSignature
|
||||
KState = new KinematicState
|
||||
{
|
||||
Temperature = 350, // 开尔文
|
||||
EmissivityFactor = 0.8f
|
||||
}
|
||||
});
|
||||
|
||||
// 创建导弹
|
||||
var missile = _missileFactory.CreateMissile(new MissileConfig
|
||||
{
|
||||
Id = "missile_001",
|
||||
Position = new Vector3(0, 0, 0),
|
||||
MaxSpeed = 800, // 米/秒
|
||||
MaxAcceleration = 30, // G
|
||||
MaxTurnRate = 20 // 度/秒
|
||||
});
|
||||
|
||||
// 创建红外成像传感器
|
||||
var sensor = _sensorFactory.CreateSensor(new IRSensorConfig
|
||||
{
|
||||
Id = "sensor_001",
|
||||
Resolution = new Vector2(640, 480),
|
||||
FieldOfView = 60, // 度
|
||||
MinTemperature = 270, // 开尔文
|
||||
MaxTemperature = 400 // 开尔文
|
||||
});
|
||||
|
||||
// 配置仿真参数
|
||||
var config = new SimulationConfig
|
||||
{
|
||||
TimeStep = 0.02f, // 仿真步长(秒)
|
||||
MaxSimulationTime = 60.0f, // 最大仿真时间(秒)
|
||||
EnvironmentConditions = new EnvironmentConfig
|
||||
{
|
||||
Temperature = 288, // 开尔文
|
||||
Pressure = 101325, // 帕斯卡
|
||||
Humidity = 0.5f // 相对湿度
|
||||
Position = new Vector3(5000, 0, 1000), // 5km距离
|
||||
Velocity = new Vector3(-50, 0, 0), // 50m/s移动
|
||||
Orientation = new Orientation(0, 0, 0)
|
||||
}
|
||||
};
|
||||
|
||||
// 初始化仿真
|
||||
await _simulationManager.Initialize(config);
|
||||
|
||||
// 添加实体
|
||||
_simulationManager.AddEntity(target);
|
||||
_simulationManager.AddEntity(missile);
|
||||
_simulationManager.AddEntity(sensor);
|
||||
|
||||
// 启动仿真
|
||||
await _simulationManager.StartSimulation();
|
||||
|
||||
// 等待仿真完成
|
||||
while (_simulationManager.IsRunning)
|
||||
// 3. 从配置创建导弹
|
||||
var missileData = _dataManager.GetMissile("IR_Missile_Example");
|
||||
var missile = new InfraredImagingTerminalGuidanceMissile("missile_001", missileData)
|
||||
{
|
||||
await Task.Delay(100);
|
||||
KState = new KinematicState
|
||||
{
|
||||
Position = new Vector3(0, 0, 100),
|
||||
Velocity = new Vector3(200, 0, 0),
|
||||
Orientation = new Orientation(0, 0, 0)
|
||||
}
|
||||
};
|
||||
|
||||
// 4. 注册实体和事件
|
||||
_simulationManager.RegisterEntity(target);
|
||||
_simulationManager.RegisterEntity(missile);
|
||||
_simulationManager.Subscribe<MissileExplodeEvent>(OnMissileExplode);
|
||||
|
||||
// 5. 运行仿真循环
|
||||
while (simulationTime < maxTime && missile.IsActive)
|
||||
{
|
||||
_simulationManager.UpdateSimulation();
|
||||
// 处理仿真状态...
|
||||
}
|
||||
|
||||
// 获取仿真结果
|
||||
var results = _simulationManager.GetSimulationResults();
|
||||
ProcessResults(results);
|
||||
}
|
||||
|
||||
private void ProcessResults(SimulationResults results)
|
||||
{
|
||||
// 处理仿真结果
|
||||
Trace.TraceInformation($"仿真完成时间: {results.CompletionTime}秒");
|
||||
Trace.TraceInformation($"命中精度: {results.HitAccuracy}米");
|
||||
Trace.TraceInformation($"导引头跟踪时间: {results.TrackingTime}秒");
|
||||
}
|
||||
}
|
||||
```
|
||||
@ -146,199 +103,206 @@ public class IRMissileSimulation
|
||||
这是一个使用C++/CLI的示例代码,展示了如何在C++项目中使用本库:
|
||||
|
||||
- 如何创建C++/CLI包装层
|
||||
- 如何配置导弹实体
|
||||
- 如何配置导弹实体和目标
|
||||
- 如何设置仿真参数
|
||||
- 如何运行仿真并获取结果
|
||||
|
||||
#### 源代码
|
||||
#### 核心代码片段
|
||||
|
||||
```cpp
|
||||
#include "ThreatSource.h"
|
||||
using namespace System;
|
||||
using namespace ThreatSource::Simulation;
|
||||
using namespace ThreatSource::Data;
|
||||
using namespace ThreatSource::Missile;
|
||||
using namespace ThreatSource::Sensor;
|
||||
using namespace ThreatSource::Target;
|
||||
|
||||
/// <summary>
|
||||
/// C++/CLI包装类,用于在C++项目中使用仿真系统
|
||||
/// </summary>
|
||||
public ref class SimulationWrapper
|
||||
public ref class IRMissileSimulationWrapper
|
||||
{
|
||||
private:
|
||||
ISimulationManager^ _simulationManager;
|
||||
IMissileFactory^ _missileFactory;
|
||||
ITargetFactory^ _targetFactory;
|
||||
ISensorFactory^ _sensorFactory;
|
||||
ISimulationManager^ simulationManager;
|
||||
ThreatSourceDataManager^ dataManager;
|
||||
|
||||
public:
|
||||
SimulationWrapper()
|
||||
void RunSimulationExample()
|
||||
{
|
||||
_simulationManager = gcnew SimulationManager();
|
||||
_missileFactory = gcnew MissileFactory();
|
||||
_targetFactory = gcnew TargetFactory();
|
||||
_sensorFactory = gcnew SensorFactory();
|
||||
}
|
||||
// 1. 初始化仿真系统
|
||||
simulationManager = gcnew SimulationManager();
|
||||
dataManager = gcnew ThreatSourceDataManager();
|
||||
simulationManager->StartSimulation(0.02);
|
||||
|
||||
void RunSimulation()
|
||||
{
|
||||
// 创建目标
|
||||
auto target = _targetFactory->CreateTarget(gcnew TargetConfig {
|
||||
Id = "target_001",
|
||||
Position = Vector3(1000, 0, 100),
|
||||
Velocity = Vector3(-100, 0, 0),
|
||||
Signature = gcnew IRSignature {
|
||||
Temperature = 350,
|
||||
EmissivityFactor = 0.8f
|
||||
}
|
||||
});
|
||||
// 2. 创建目标
|
||||
auto target = gcnew BaseEquipment("target_001");
|
||||
target->KState = gcnew KinematicState();
|
||||
target->KState->Position = Vector3(5000, 0, 1000);
|
||||
|
||||
// 创建导弹
|
||||
auto missile = _missileFactory->CreateMissile(gcnew MissileConfig {
|
||||
Id = "missile_001",
|
||||
Position = Vector3(0, 0, 0),
|
||||
MaxSpeed = 800,
|
||||
MaxAcceleration = 30,
|
||||
MaxTurnRate = 20
|
||||
});
|
||||
// 3. 创建导弹
|
||||
auto missileData = dataManager->GetMissile("IR_Missile_Example");
|
||||
auto missile = gcnew InfraredImagingTerminalGuidanceMissile("missile_001", missileData);
|
||||
|
||||
// 创建传感器
|
||||
auto sensor = _sensorFactory->CreateSensor(gcnew IRSensorConfig {
|
||||
Id = "sensor_001",
|
||||
Resolution = Vector2(640, 480),
|
||||
FieldOfView = 60,
|
||||
MinTemperature = 270,
|
||||
MaxTemperature = 400
|
||||
});
|
||||
// 4. 注册实体
|
||||
simulationManager->RegisterEntity(target);
|
||||
simulationManager->RegisterEntity(missile);
|
||||
|
||||
// 配置仿真参数
|
||||
auto config = gcnew SimulationConfig {
|
||||
TimeStep = 0.02f,
|
||||
MaxSimulationTime = 60.0f,
|
||||
EnvironmentConditions = gcnew EnvironmentConfig {
|
||||
Temperature = 288,
|
||||
Pressure = 101325,
|
||||
Humidity = 0.5f
|
||||
}
|
||||
};
|
||||
|
||||
// 初始化仿真
|
||||
_simulationManager->Initialize(config)->Wait();
|
||||
|
||||
// 添加实体
|
||||
_simulationManager->AddEntity(target);
|
||||
_simulationManager->AddEntity(missile);
|
||||
_simulationManager->AddEntity(sensor);
|
||||
|
||||
// 启动仿真
|
||||
_simulationManager->StartSimulation()->Wait();
|
||||
|
||||
// 等待仿真完成
|
||||
while (_simulationManager->IsRunning)
|
||||
// 5. 运行仿真
|
||||
while (simulationTime < maxTime && missile->IsActive)
|
||||
{
|
||||
System::Threading::Thread::Sleep(100);
|
||||
simulationManager->UpdateSimulation();
|
||||
// 处理仿真状态...
|
||||
}
|
||||
|
||||
// 获取仿真结果
|
||||
auto results = _simulationManager->GetSimulationResults();
|
||||
ProcessResults(results);
|
||||
}
|
||||
|
||||
private:
|
||||
void ProcessResults(SimulationResults^ results)
|
||||
{
|
||||
Console::WriteLine("仿真完成时间: {0}秒", results->CompletionTime);
|
||||
Console::WriteLine("命中精度: {0}米", results->HitAccuracy);
|
||||
Console::WriteLine("导引头跟踪时间: {0}秒", results->TrackingTime);
|
||||
}
|
||||
};
|
||||
|
||||
// 在C++代码中使用
|
||||
int main()
|
||||
{
|
||||
auto simulation = gcnew SimulationWrapper();
|
||||
simulation->RunSimulation();
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
## 使用说明
|
||||
|
||||
### C#/.NET使用方式
|
||||
### 基本仿真流程
|
||||
|
||||
1. 创建仿真适配器
|
||||
1. **初始化仿真管理器**
|
||||
```csharp
|
||||
var simulationManager = new SimulationManager();
|
||||
var dataManager = new ThreatSourceDataManager();
|
||||
simulationManager.StartSimulation(timeStep);
|
||||
```
|
||||
|
||||
```csharp
|
||||
var adapter = new TestSimulationAdapter();
|
||||
```
|
||||
2. **创建仿真实体**
|
||||
```csharp
|
||||
// 从配置创建导弹
|
||||
var missileData = dataManager.GetMissile("missile_type");
|
||||
var missile = new InfraredImagingTerminalGuidanceMissile("id", missileData);
|
||||
|
||||
// 创建目标
|
||||
var target = new BaseEquipment("target_id");
|
||||
```
|
||||
|
||||
2. 配置导弹和目标
|
||||
3. **配置实体状态**
|
||||
```csharp
|
||||
missile.KState = new KinematicState
|
||||
{
|
||||
Position = new Vector3(x, y, z),
|
||||
Velocity = new Vector3(vx, vy, vz),
|
||||
Orientation = new Orientation(yaw, pitch, roll)
|
||||
};
|
||||
```
|
||||
|
||||
```csharp
|
||||
var missile = new SimulationEntity
|
||||
{
|
||||
Id = "missile_001",
|
||||
Position = new Vector3(0, 0, 0),
|
||||
// ... 其他配置
|
||||
};
|
||||
```
|
||||
4. **注册实体和事件**
|
||||
```csharp
|
||||
simulationManager.RegisterEntity(missile);
|
||||
simulationManager.RegisterEntity(target);
|
||||
simulationManager.Subscribe<MissileExplodeEvent>(OnMissileExplode);
|
||||
```
|
||||
|
||||
3. 设置仿真参数
|
||||
5. **运行仿真循环**
|
||||
```csharp
|
||||
while (condition)
|
||||
{
|
||||
simulationManager.UpdateSimulation();
|
||||
// 处理仿真状态和结果
|
||||
}
|
||||
```
|
||||
|
||||
```csharp
|
||||
var simConfig = new SimulationConfig
|
||||
{
|
||||
TimeStep = 0.02f, // 仿真步长(秒)
|
||||
MaxSimulationTime = 60.0f, // 最大仿真时间(秒)
|
||||
// ... 其他配置
|
||||
};
|
||||
```
|
||||
### 配置文件要求
|
||||
|
||||
4. 运行仿真
|
||||
示例代码需要相应的TOML配置文件:
|
||||
|
||||
```csharp
|
||||
await adapter.Initialize(simConfig);
|
||||
await adapter.StartSimulation();
|
||||
```
|
||||
```toml
|
||||
# data/missiles/IR_Missile_Example.toml
|
||||
Type = "missile"
|
||||
|
||||
### C++使用方式
|
||||
[Name]
|
||||
zh = "红外成像制导导弹示例"
|
||||
en = "IR Imaging Guided Missile Example"
|
||||
|
||||
1. 创建C++/CLI项目
|
||||
- 在Visual Studio中创建新的C++/CLI项目
|
||||
- 添加对 ThreatSource.dll 的引用
|
||||
[Properties]
|
||||
MaxSpeed = 800.0
|
||||
MaxAcceleration = 50.0
|
||||
MaxFlightTime = 120.0
|
||||
MaxFlightDistance = 8000.0
|
||||
|
||||
2. 创建包装类
|
||||
[InfraredImagingGuidanceConfig]
|
||||
MaxDetectionRange = 5000.0
|
||||
FieldOfView = 30.0
|
||||
TargetRecognitionProbability = 0.9
|
||||
```
|
||||
|
||||
```cpp
|
||||
public ref class SimulationWrapper
|
||||
{
|
||||
private:
|
||||
TestSimulationAdapter^ adapter;
|
||||
### C++/CLI项目配置
|
||||
|
||||
public:
|
||||
SimulationWrapper()
|
||||
{
|
||||
adapter = gcnew TestSimulationAdapter();
|
||||
}
|
||||
1. **创建C++/CLI项目**
|
||||
- 在Visual Studio中选择"CLR空项目"
|
||||
- 设置目标框架为.NET 8.0
|
||||
|
||||
// ... 其他包装方法
|
||||
};
|
||||
```
|
||||
2. **添加引用**
|
||||
```xml
|
||||
<Reference Include="ThreatSource">
|
||||
<HintPath>path\to\ThreatSource.dll</HintPath>
|
||||
</Reference>
|
||||
```
|
||||
|
||||
3. 在C++代码中使用
|
||||
|
||||
```cpp
|
||||
auto simulation = gcnew SimulationWrapper();
|
||||
simulation->Initialize();
|
||||
simulation->StartSimulation();
|
||||
```
|
||||
3. **编译设置**
|
||||
- 启用公共语言运行时支持 (/clr)
|
||||
- 设置正确的.NET目标框架版本
|
||||
|
||||
## 注意事项
|
||||
|
||||
1. 确保所有参数单位正确(米、秒、开尔文等)
|
||||
2. 合理设置仿真时间步长,平衡精度和性能
|
||||
3. 注意处理异步操作和事件回调
|
||||
4. C++/CLI注意事项:
|
||||
- 仅支持Windows平台
|
||||
- 需要正确配置项目的目标框架
|
||||
- 注意托管和非托管资源的正确释放
|
||||
### 通用注意事项
|
||||
|
||||
1. **单位系统**:确保所有参数使用正确的单位(米、秒、弧度等)
|
||||
2. **时间步长**:合理设置仿真时间步长,平衡精度和性能
|
||||
3. **资源管理**:正确处理仿真资源的创建和释放
|
||||
4. **异常处理**:添加适当的异常处理机制
|
||||
|
||||
### C#特定注意事项
|
||||
|
||||
1. 使用async/await处理异步操作
|
||||
2. 正确订阅和取消订阅事件
|
||||
3. 注意内存管理和垃圾回收
|
||||
|
||||
### C++/CLI特定注意事项
|
||||
|
||||
1. **平台限制**:仅支持Windows平台
|
||||
2. **内存管理**:注意托管和非托管资源的正确释放
|
||||
3. **类型转换**:正确处理托管和原生类型之间的转换
|
||||
4. **异常处理**:使用托管异常处理机制
|
||||
|
||||
## 扩展示例
|
||||
|
||||
### 添加自定义事件处理
|
||||
|
||||
```csharp
|
||||
// 订阅多种事件
|
||||
simulationManager.Subscribe<FlightPhaseChangeEvent>(OnFlightPhaseChange);
|
||||
simulationManager.Subscribe<TargetHitEvent>(OnTargetHit);
|
||||
simulationManager.Subscribe<GuidanceActivationEvent>(OnGuidanceActivation);
|
||||
|
||||
private void OnFlightPhaseChange(FlightPhaseChangeEvent evt)
|
||||
{
|
||||
Console.WriteLine($"导弹 {evt.SenderId} 进入 {evt.NewPhase} 阶段");
|
||||
}
|
||||
```
|
||||
|
||||
### 多导弹仿真
|
||||
|
||||
```csharp
|
||||
// 创建多个导弹
|
||||
for (int i = 0; i < missileCount; i++)
|
||||
{
|
||||
var missile = new InfraredImagingTerminalGuidanceMissile($"missile_{i:D3}", missileData);
|
||||
// 设置不同的初始位置和参数
|
||||
simulationManager.RegisterEntity(missile);
|
||||
}
|
||||
```
|
||||
|
||||
### 实时状态监控
|
||||
|
||||
```csharp
|
||||
// 在仿真循环中监控状态
|
||||
while (simulationManager.IsRunning)
|
||||
{
|
||||
simulationManager.UpdateSimulation();
|
||||
|
||||
// 获取所有导弹状态
|
||||
var missiles = simulationManager.GetEntitiesByType<BaseMissile>();
|
||||
foreach (var missile in missiles)
|
||||
{
|
||||
var status = missile.GetStatusInfo();
|
||||
// 处理状态信息
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
110
docs/index.md
110
docs/index.md
@ -4,17 +4,36 @@
|
||||
|
||||
## 简介
|
||||
|
||||
威胁源仿真库是一个用于模拟和仿真各种威胁源的.NET类库。它提供了以下主要功能:
|
||||
威胁源仿真库是一个基于 **.NET 8.0** 的高性能仿真类库,用于模拟和仿真各种威胁源。它提供了以下主要功能:
|
||||
|
||||
- 导弹仿真(包括各种类型的导弹)
|
||||
- 目标仿真
|
||||
- 传感器仿真
|
||||
- 制导系统仿真
|
||||
- **导弹仿真**:支持多种制导系统(激光、红外、毫米波等)
|
||||
- **目标仿真**:各类设备和目标的建模
|
||||
- **传感器仿真**:雷达、光电等传感器系统
|
||||
- **制导系统仿真**:完整的制导算法实现
|
||||
- **事件驱动架构**:高效的仿真事件系统
|
||||
- **智能数据管理**:TOML配置文件支持和智能路径解析
|
||||
- **外部系统集成**:支持Unity、虚幻引擎等第三方引擎集成
|
||||
|
||||
## 系统要求
|
||||
|
||||
### 基本要求
|
||||
- **.NET 8.0** 或更高版本
|
||||
- Windows、Linux 或 macOS 操作系统
|
||||
- Visual Studio 2019+ 或 Visual Studio Code(推荐)
|
||||
|
||||
### C# 开发
|
||||
- .NET 8.0 SDK
|
||||
- 支持 .NET 8.0 的 IDE
|
||||
|
||||
### C++ 开发
|
||||
- Windows 操作系统
|
||||
- Visual Studio 2019+ (支持C++/CLI)
|
||||
- .NET 8.0 运行时
|
||||
|
||||
## 支持的开发语言
|
||||
|
||||
- C# (.NET):原生支持,提供完整的API和功能
|
||||
- C++:通过C++/CLI包装层支持,可以在C++项目中使用全部功能
|
||||
- **C# (.NET)**:原生支持,提供完整的API和功能
|
||||
- **C++**:通过C++/CLI包装层支持,可以在C++项目中使用全部功能
|
||||
|
||||
## 快速开始
|
||||
|
||||
@ -24,28 +43,75 @@
|
||||
|
||||
完整的API文档请参阅[API参考](./api/toc.yml)。
|
||||
|
||||
## 集成示例
|
||||
## 示例代码
|
||||
|
||||
### 第三方引擎集成
|
||||
### 基础仿真示例
|
||||
|
||||
- [仿真示例说明](examples/Simulation/README.md) - 基础仿真功能的详细说明
|
||||
- [C# 红外成像制导导弹仿真](examples/Simulation/IRMissileSimulation.cs) - C# 仿真示例
|
||||
- [C++ 红外成像制导导弹仿真](examples/Simulation/IRMissileSimulation.cpp) - C++/CLI 仿真示例
|
||||
|
||||
### 第三方引擎集成示例
|
||||
|
||||
- [集成示例说明](examples/Integration/README.md) - 第三方引擎集成的详细说明
|
||||
- [虚幻引擎示例](./examples/Integration/UEExample.cs) - 虚幻引擎集成示例代码
|
||||
- [Unity引擎示例](./examples/Integration/UnityExample.cs) - Unity引擎集成示例代码
|
||||
- [虚幻引擎集成示例](examples/Integration/UEExample.cs) - 虚幻引擎集成示例代码
|
||||
- [Unity引擎集成示例](examples/Integration/UnityExample.cs) - Unity引擎集成示例代码
|
||||
|
||||
## 示例说明
|
||||
## 示例功能说明
|
||||
|
||||
这些示例展示了如何将不同的游戏引擎与仿真系统集成:
|
||||
### 基础仿真示例
|
||||
|
||||
1. 虚幻引擎(UE)示例
|
||||
- 虚幻引擎与仿真系统的双向通信
|
||||
- 实体信息的同步和转换
|
||||
- 事件的发布和订阅
|
||||
- 数据的适配和转换
|
||||
这些示例展示了如何使用ThreatSource进行基础仿真:
|
||||
|
||||
2. Unity引擎示例
|
||||
- Unity引擎与仿真系统的双向通信
|
||||
- GameObject与实体的映射和转换
|
||||
1. **C# 仿真示例**
|
||||
- 使用SimulationManager管理仿真
|
||||
- 从TOML配置文件创建导弹实体
|
||||
- 设置目标和仿真环境
|
||||
- 订阅和处理仿真事件
|
||||
- 运行仿真循环并获取结果
|
||||
|
||||
2. **C++/CLI 仿真示例**
|
||||
- C++/CLI包装层的使用方法
|
||||
- 托管和非托管代码的交互
|
||||
- 事件处理和资源管理
|
||||
- 跨语言的仿真集成
|
||||
|
||||
### 第三方引擎集成示例
|
||||
|
||||
这些示例展示了如何将ThreatSource与游戏引擎集成:
|
||||
|
||||
1. **虚幻引擎集成示例**
|
||||
- ThreatSource与虚幻引擎的双向通信
|
||||
- Actor与仿真实体的映射和同步
|
||||
- 坐标系转换(右手系到左手系)
|
||||
- 事件驱动的视觉效果处理
|
||||
|
||||
2. **Unity引擎集成示例**
|
||||
- ThreatSource与Unity引擎的双向通信
|
||||
- GameObject与仿真实体的映射和转换
|
||||
- MonoBehaviour生命周期管理
|
||||
- 事件系统的使用
|
||||
- 实时状态同步和视觉效果
|
||||
|
||||
## 核心特性
|
||||
|
||||
### 事件驱动架构
|
||||
- 类型安全的事件系统
|
||||
- 异步事件处理
|
||||
- 异常隔离机制
|
||||
|
||||
### 智能数据管理
|
||||
- TOML配置文件支持
|
||||
- 智能路径解析
|
||||
- 复合制导配置后处理
|
||||
|
||||
### 高性能仿真
|
||||
- 优化的运动学计算
|
||||
- 高效的碰撞检测
|
||||
- 可配置的仿真精度
|
||||
|
||||
### 扩展性设计
|
||||
- 模块化架构
|
||||
- 插件式制导系统
|
||||
- 灵活的实体系统
|
||||
|
||||
所有示例代码都提供了详细的注释和说明,可以作为实际开发的参考。
|
||||
|
||||
@ -8,7 +8,7 @@ metadata:
|
||||
items:
|
||||
- name: 简介
|
||||
href: index.md
|
||||
- name: 入门指南
|
||||
- name: 使用说明
|
||||
href: articles/intro.md
|
||||
- name: API 文档
|
||||
href: api/toc.yml
|
||||
|
||||
@ -19,7 +19,7 @@ namespace ThreatSource.Tools.MissileSimulation
|
||||
public event EventHandler? SimulationEnded;
|
||||
|
||||
private ConsoleTraceListener consoleListener;
|
||||
private EventTypeFilter logLevelFilter;
|
||||
private readonly EventTypeFilter logLevelFilter;
|
||||
|
||||
private readonly SimulationManager simulationManager;
|
||||
private readonly ThreatSourceFactory _threatSourceFactory;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user