将目标平台改成net6.0, 语言改为C# 9.0, 提高在Unity中的兼容性

This commit is contained in:
Tian jianyong 2024-10-19 13:53:21 +08:00
parent e14978c785
commit a7c6f01d17
51 changed files with 516 additions and 195 deletions

65
.cursorrules Normal file
View File

@ -0,0 +1,65 @@
# Cursor Rules
You are an expert in C#, Unity, and scalable game development.
Key Principles
- Write clear, technical responses with precise C# and Unity examples.
- Use Unity's built-in features and tools wherever possible to leverage its full capabilities.
- Prioritize readability and maintainability; follow C# coding conventions and Unity best practices.
- Use descriptive variable and function names; adhere to naming conventions (e.g., PascalCase for public members, camelCase for private members).
- Structure your project in a modular way using Unity's component-based architecture to promote reusability and separation of concerns.
C#/Unity
- Use MonoBehaviour for script components attached to GameObjects; prefer ScriptableObjects for data containers and shared resources.
- Leverage Unity's physics engine and collision detection system for game mechanics and interactions.
- Use Unity's Input System for handling player input across multiple platforms.
- Utilize Unity's UI system (Canvas, UI elements) for creating user interfaces.
- Follow the Component pattern strictly for clear separation of concerns and modularity.
- Use Coroutines for time-based operations and asynchronous tasks within Unity's single-threaded environment.
- Use System.Console for logging and debugging in the console.
- Using C# 9.0 features.
Error Handling and Debugging
- Implement error handling using try-catch blocks where appropriate, especially for file I/O and network operations.
- Use Unity's Debug class for logging and debugging (e.g., Debug.Log, Debug.LogWarning, Debug.LogError).
- Utilize Unity's profiler and frame debugger to identify and resolve performance issues.
- Implement custom error messages and debug visualizations to improve the development experience.
- Use Unity's assertion system (Debug.Assert) to catch logical errors during development.
Dependencies
- Unity Engine
- .NET Framework (version compatible with your Unity version)
- Unity Asset Store packages (as needed for specific functionality)
- Third-party plugins (carefully vetted for compatibility and performance)
Unity-Specific Guidelines
- Use Prefabs for reusable game objects and UI elements.
- Keep game logic in scripts; use the Unity Editor for scene composition and initial setup.
- Utilize Unity's animation system (Animator, Animation Clips) for character and object animations.
- Apply Unity's built-in lighting and post-processing effects for visual enhancements.
- Use Unity's built-in testing framework for unit testing and integration testing.
- Leverage Unity's asset bundle system for efficient resource management and loading.
- Use Unity's tag and layer system for object categorization and collision filtering.
Performance Optimization
- Use object pooling for frequently instantiated and destroyed objects.
- Optimize draw calls by batching materials and using atlases for sprites and UI elements.
- Implement level of detail (LOD) systems for complex 3D models to improve rendering performance.
- Use Unity's Job System and Burst Compiler for CPU-intensive operations.
- Optimize physics performance by using simplified collision meshes and adjusting fixed timestep.
Key Conventions
1. Follow Unity's component-based architecture for modular and reusable game elements.
2. Prioritize performance optimization and memory management in every stage of development.
3. Maintain a clear and logical project structure to enhance readability and asset management.
Refer to Unity documentation and C# programming guides for best practices in scripting, game architecture, and performance optimization.

View File

@ -2,8 +2,9 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>9.0</LangVersion>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

View File

@ -5,28 +5,38 @@ namespace ActiveProtect.Models
/// <summary>
/// 表示三维空间中的向量
/// </summary>
public class Vector3D(double x, double y, double z)
public class Vector3D
{
// 添加静态单位向量属性
public static Vector3D UnitX => new(1, 0, 0);
public static Vector3D UnitY => new(0, 1, 0);
public static Vector3D UnitZ => new(0, 0, 1);
public static Vector3D Zero => new(0, 0, 0);
public static Vector3D UnitX => new Vector3D(1, 0, 0);
public static Vector3D UnitY => new Vector3D(0, 1, 0);
public static Vector3D UnitZ => new Vector3D(0, 0, 1);
public static Vector3D Zero => new Vector3D(0, 0, 0);
/// <summary>
/// X 坐标
/// </summary>
public double X { get; set; } = x;
public double X { get; set; }
/// <summary>
/// Y 坐标
/// </summary>
public double Y { get; set; } = y;
public double Y { get; set; }
/// <summary>
/// Z 坐标
/// </summary>
public double Z { get; set; } = z;
public double Z { get; set; }
/// <summary>
/// 构造函数
/// </summary>
public Vector3D(double x, double y, double z)
{
X = x;
Y = y;
Z = z;
}
/// <summary>
/// 计算两个向量之间的距离
@ -161,22 +171,32 @@ namespace ActiveProtect.Models
/// <summary>
/// 表示三维空间中的方向
/// </summary>
public struct Orientation(double yaw, double pitch, double roll)
public struct Orientation
{
/// <summary>
/// 偏航角绕Y轴旋转
/// </summary>
public double Yaw { get; set; } = yaw;
public double Yaw { get; set; }
/// <summary>
/// 俯仰角绕X轴旋转
/// </summary>
public double Pitch { get; set; } = pitch;
public double Pitch { get; set; }
/// <summary>
/// 滚转角绕Z轴旋转
/// </summary>
public double Roll { get; set; } = roll;
public double Roll { get; set; }
/// <summary>
/// 构造函数
/// </summary>
public Orientation(double yaw, double pitch, double roll)
{
Yaw = yaw;
Pitch = pitch;
Roll = roll;
}
/// <summary>
/// 将方向转换为字符串表示
@ -272,6 +292,6 @@ namespace ActiveProtect.Models
Y = y;
}
public static Vector2D Zero => new(0, 0);
public static Vector2D Zero => new Vector2D(0, 0);
}
}

View File

@ -1,30 +0,0 @@
using ActiveProtect.SimulationEnvironment;
namespace ActiveProtect.Models
{
/// <summary>
/// 定义可被激光照射的实体接口
/// </summary>
public interface ILaserIlluminatable
{
/// <summary>
/// 获取实体是否正在被激光照射
/// </summary>
bool IsIlluminated { get; }
/// <summary>
/// 开始激光照射
/// </summary>
void Illuminate();
/// <summary>
/// 停止激光照射
/// </summary>
void StopIllumination();
/// <summary>
/// 获取实体的位置
/// </summary>
Vector3D Position { get; }
}
}

View File

@ -1,6 +1,4 @@
using ActiveProtect.SimulationEnvironment;
using System;
using System.Formats.Tar;
namespace ActiveProtect.Models
{
@ -23,17 +21,26 @@ namespace ActiveProtect.Models
private void OnLaserBeamStart(LaserBeamStartEvent evt)
{
LaserBeamRiderGuidanceSystem.ActivateLaserBeam(evt.LaserBeamRider.Position, evt.LaserBeamRider.LaserDirection, evt.LaserBeamRider.LaserPower);
if (evt?.LaserBeamRider != null)
{
LaserBeamRiderGuidanceSystem?.ActivateLaserBeam(evt.LaserBeamRider.Position, evt.LaserBeamRider.LaserDirection, evt.LaserBeamRider.LaserPower);
}
}
private void OnLaserBeamUpdate(LaserBeamUpdateEvent evt)
{
LaserBeamRiderGuidanceSystem.UpdateLaserBeamRider(evt.LaserBeamRider.Position, evt.LaserBeamRider.LaserDirection, evt.LaserBeamRider.LaserPower);
if (evt?.LaserBeamRider != null)
{
LaserBeamRiderGuidanceSystem?.UpdateLaserBeamRider(evt.LaserBeamRider.Position, evt.LaserBeamRider.LaserDirection, evt.LaserBeamRider.LaserPower);
}
}
private void OnLaserBeamStop(LaserBeamStopEvent evt)
{
LaserBeamRiderGuidanceSystem.DeactivateLaserBeam(evt.LaserBeamRider.Position, evt.LaserBeamRider.LaserDirection);
if (evt?.LaserBeamRider != null)
{
LaserBeamRiderGuidanceSystem?.DeactivateLaserBeam(evt.LaserBeamRider.Position, evt.LaserBeamRider.LaserDirection);
}
}
public override void Update(double deltaTime)

View File

@ -38,8 +38,11 @@ namespace ActiveProtect.Models
/// <param name="evt">激光照射事件</param>
private void OnLaserIlluminationStart(LaserIlluminationStartEvent evt)
{
LaserGuidanceSystem.ActivateLaserDesignator(evt.LaserDesignator.Position, evt.Target.Position, evt.Target.Velocity,
evt.LaserDesignator.LaserPower, evt.LaserDesignator.LaserDivergenceAngle);
if (evt?.LaserDesignator != null && evt?.Target != null)
{
LaserGuidanceSystem.ActivateLaserDesignator(evt.LaserDesignator.Position, evt.Target.Position, evt.Target.Velocity,
evt.LaserDesignator.LaserPower, evt.LaserDesignator.LaserDivergenceAngle);
}
}
/// <summary>
@ -48,8 +51,11 @@ namespace ActiveProtect.Models
/// <param name="evt">激光照射更新事件</param>
private void OnLaserIlluminationUpdate(LaserIlluminationUpdateEvent evt)
{
LaserGuidanceSystem.UpdateLaserDesignator(evt.LaserDesignator.Position, evt.Target.Position, evt.Target.Velocity,
evt.LaserDesignator.LaserPower, evt.LaserDesignator.LaserDivergenceAngle);
if (evt?.LaserDesignator != null && evt?.Target != null)
{
LaserGuidanceSystem.UpdateLaserDesignator(evt.LaserDesignator.Position, evt.Target.Position, evt.Target.Velocity,
evt.LaserDesignator.LaserPower, evt.LaserDesignator.LaserDivergenceAngle);
}
}
/// <summary>

View File

@ -78,7 +78,7 @@ namespace ActiveProtect.Models
/// <param name="evt">激光照射事件</param>
private void OnLaserIlluminationStart(LaserIlluminationStartEvent evt)
{
if (evt.Target.Id == MonitoredEntityId)
if (evt?.Target != null && evt.Target.Id == MonitoredEntityId)
{
TriggerAlarm();
}
@ -90,7 +90,7 @@ namespace ActiveProtect.Models
/// <param name="evt">激光照射停止事件</param>
private void OnLaserIlluminationStop(LaserIlluminationStopEvent evt)
{
if (evt.Target.Id == MonitoredEntityId)
if (evt?.Target != null && evt.Target.Id == MonitoredEntityId)
{
StopAlarm();
}

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using ActiveProtect.SimulationEnvironment;
using Model;
@ -360,7 +361,7 @@ namespace ActiveProtect.Models
/// </summary>
private void TryChangeToNextAvailableStage(FlightStage startStage)
{
FlightStage[] stageOrder = [FlightStage.Launch, FlightStage.Acceleration, FlightStage.Cruise, FlightStage.TerminalGuidance, FlightStage.Attack];
FlightStage[] stageOrder = new FlightStage[] {FlightStage.Launch, FlightStage.Acceleration, FlightStage.Cruise, FlightStage.TerminalGuidance, FlightStage.Attack};
int startIndex = Array.IndexOf(stageOrder, startStage);
for (int i = startIndex + 1; i < stageOrder.Length; i++)

View File

@ -1,4 +1,6 @@
using System;
namespace ActiveProtect.Models
{
/// <summary>
@ -45,12 +47,18 @@ namespace ActiveProtect.Models
}
}
/// <summary>
/// <summary>
/// 加速阶段策略
/// </summary>
public class AccelerationStageStrategy(MissileBase missile) : IMissileStageStrategy
public class AccelerationStageStrategy : IMissileStageStrategy
{
private readonly MissileBase missile = missile;
private readonly MissileBase missile;
public AccelerationStageStrategy(MissileBase missile)
{
this.missile = missile;
}
public void Update(double deltaTime)
{
@ -64,9 +72,14 @@ namespace ActiveProtect.Models
/// <summary>
/// 巡航阶段策略
/// </summary>
public class CruiseStageStrategy(MissileBase missile) : IMissileStageStrategy
public class CruiseStageStrategy : IMissileStageStrategy
{
private readonly MissileBase missile = missile;
private readonly MissileBase missile;
public CruiseStageStrategy(MissileBase missile)
{
this.missile = missile;
}
public void Update(double deltaTime)
{
@ -80,9 +93,14 @@ namespace ActiveProtect.Models
/// <summary>
/// 终端制导阶段策略
/// </summary>
public class TerminalGuidanceStageStrategy(MissileBase missile) : IMissileStageStrategy
public class TerminalGuidanceStageStrategy : IMissileStageStrategy
{
private readonly MissileBase missile = missile;
private readonly MissileBase missile;
public TerminalGuidanceStageStrategy(MissileBase missile)
{
this.missile = missile;
}
public void Update(double deltaTime)
{
@ -96,9 +114,14 @@ namespace ActiveProtect.Models
/// <summary>
/// 攻击阶段策略
/// </summary>
public class AttackStageStrategy(MissileBase missile) : IMissileStageStrategy
public class AttackStageStrategy : IMissileStageStrategy
{
private readonly MissileBase missile = missile;
private readonly MissileBase missile;
public AttackStageStrategy(MissileBase missile)
{
this.missile = missile;
}
public void Update(double deltaTime)
{
@ -112,9 +135,14 @@ namespace ActiveProtect.Models
/// <summary>
/// 无制导阶段策略
/// </summary>
public class UnguidedStageStrategy(MissileBase missile) : IMissileStageStrategy
public class UnguidedStageStrategy : IMissileStageStrategy
{
private readonly MissileBase missile = missile;
private readonly MissileBase missile;
public UnguidedStageStrategy(MissileBase missile)
{
this.missile = missile;
}
public void Update(double deltaTime)
{

View File

@ -6,28 +6,42 @@ namespace ActiveProtect.Models
/// <summary>
/// 表示仿真中的坦克
/// </summary>
public class Tank(string id, TankConfig tankConfig, ISimulationManager simulationManager)
: SimulationElement(id, tankConfig.InitialPosition, tankConfig.InitialOrientation, simulationManager)
public class Tank : SimulationElement
{
/// <summary>
/// 当前速度(米/秒)
/// </summary>
public double Speed { get; set; } = tankConfig.InitialSpeed;
public double Speed { get; set; }
/// <summary>
/// 最大速度(米/秒)
/// </summary>
public double MaxSpeed { get; private set; } = tankConfig.MaxSpeed;
public double MaxSpeed { get; private set; }
/// <summary>
/// 最大装甲值
/// </summary>
public double MaxArmor { get; private set; } = tankConfig.MaxArmor;
public double MaxArmor { get; private set; }
/// <summary>
/// 当前装甲值
/// </summary>
public double CurrentArmor { get; private set; } = tankConfig.MaxArmor;
public double CurrentArmor { get; private set; }
/// <summary>
/// 构造函数
/// </summary>
/// <param name="id">坦克ID</param>
/// <param name="tankConfig">坦克配置</param>
/// <param name="simulationManager">仿真管理器</param>
public Tank(string id, TankConfig tankConfig, ISimulationManager simulationManager)
: base(id, tankConfig.InitialPosition, tankConfig.InitialOrientation, simulationManager)
{
Speed = tankConfig.InitialSpeed;
MaxSpeed = tankConfig.MaxSpeed;
MaxArmor = tankConfig.MaxArmor;
CurrentArmor = tankConfig.MaxArmor;
}
/// <summary>
/// 更新坦克状态

View File

@ -4,6 +4,7 @@ using ActiveProtect.SimulationEnvironment;
using ActiveProtect.Models;
using Model;
using System.Security.Cryptography.X509Certificates;
using System.Collections.Generic;
namespace ActiveProtect
{
@ -32,9 +33,10 @@ namespace ActiveProtect
var config = new SimulationConfig
{
// 配置坦克
TankConfigs =
[
new(tankinfo) {
TankConfigs = new List<TankConfig>
{
new TankConfig(tankinfo)
{
InitialOrientation = new Orientation(Math.PI/4, 0, 0),
InitialSpeed = 15,
MaxSpeed = 20,
@ -42,7 +44,7 @@ namespace ActiveProtect
HasLaserWarner = false,
HasLaserJammer = true
}
],
},
// 配置激光指示器
LaserDesignatorConfig = new LaserDesignatorConfig
{
@ -71,69 +73,19 @@ namespace ActiveProtect
ControlFieldDiameter = 6
},
// 配置导弹
MissileConfigs =
[
// 标准导弹配置
// new(mIniInfo) {
// MaxSpeed = 300,
// TargetIndex = 0,
// MaxFlightTime = 0.5,
// MaxFlightDistance = 3000,
// ThrustAcceleration = 50,
// MaxEngineBurnTime = 10,
// MaxAcceleration = 100,
// ProportionalNavigationCoefficient = 3,
// StageConfig = FlightStageConfig.StandardMissile,
// DistanceParams = new MissileDistanceParams(500, 100, 20),
// Mass = 50,
// Type = MissileType.StandardMissile,
// },
// // 红外指令制导导弹配置
// new() {
// InitialPosition = new Vector3D(2000, 150, 100),
// InitialOrientation = new Orientation(Math.PI, -0.15, 0),
// InitialSpeed = 0,
// MaxSpeed = 300,
// TargetIndex = 0,
// MaxFlightTime = 1,
// MaxFlightDistance = 5000,
// ThrustAcceleration = 50,
// MaxEngineBurnTime = 10,
// MaxAcceleration = 100,
// ProportionalNavigationCoefficient = 3,
// StageConfig = FlightStageConfig.InfraredCommandGuidance,
// DistanceParams = new MissileDistanceParams(500, 100, 20),
// Mass = 50,
// Type = MissileType.InfraredCommandGuidance
// },
// // 毫米波终端制导导弹配置
// new() {
// InitialPosition = new Vector3D(2000, 50, 100),
// InitialOrientation = new Orientation(Math.PI, -0.05, 0),
// InitialSpeed = 0,
// MaxSpeed = 300,
// TargetIndex = 0,
// MaxFlightTime = 0.5,
// MaxFlightDistance = 3000,
// ThrustAcceleration = 50,
// MaxEngineBurnTime = 10,
// MaxAcceleration = 100,
// ProportionalNavigationCoefficient = 3,
// StageConfig = FlightStageConfig.MillimeterWaveTerminalGuidance,
// DistanceParams = new MissileDistanceParams(500, 100, 20),
// Mass = 50,
// Type = MissileType.MillimeterWaveTerminalGuidance
// },
MissileConfigs = new List<MissileConfig>
{
// 激光半主动制导导弹配置
new() {
InitialPosition = new Vector3D(2000, 100, 100),
InitialOrientation = new Orientation(Math.PI, -0.1, 0), // 调整初始俯仰角
InitialSpeed = 700,
new MissileConfig
{
InitialPosition = new Vector3D(2000, 100, 100),
InitialOrientation = new Orientation(Math.PI, -0.1, 0),
InitialSpeed = 700,
MaxSpeed = 800,
TargetIndex = 0,
MaxFlightTime = 0.5, // 增加最大飞行时间
MaxFlightTime = 0.05,
MaxFlightDistance = 5000,
ThrustAcceleration = 50, // 添加推力加速度
ThrustAcceleration = 50,
MaxEngineBurnTime = 10,
MaxAcceleration = 400,
ProportionalNavigationCoefficient = 3,
@ -143,15 +95,16 @@ namespace ActiveProtect
Type = MissileType.LaserSemiActiveGuidance
},
// 激光驾束制导导弹配置
new() {
InitialPosition = new Vector3D(2000, 10, 100),
InitialOrientation = new Orientation(Math.PI, 0.1, 0.0), // 调整初始俯仰角
InitialSpeed = 300,
new MissileConfig
{
InitialPosition = new Vector3D(2000, 10, 100),
InitialOrientation = new Orientation(Math.PI, 0.1, 0.0),
InitialSpeed = 300,
MaxSpeed = 400,
TargetIndex = 0,
MaxFlightTime = 10, // 增加最大飞行时间
MaxFlightTime = 0.05,
MaxFlightDistance = 3000,
ThrustAcceleration = 50, // 添加推力加速度
ThrustAcceleration = 50,
MaxEngineBurnTime = 10,
MaxAcceleration = 400,
ProportionalNavigationCoefficient = 3,
@ -160,7 +113,7 @@ namespace ActiveProtect
Mass = 50,
Type = MissileType.LaserBeamRiderGuidance
}
],
},
SimulationTimeStep = 0.025
};

View File

@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.ComponentModel;
using ActiveProtect.Models;
using Model;
@ -49,8 +50,8 @@ namespace ActiveProtect.SimulationEnvironment
/// </summary>
public SimulationConfig()
{
TankConfigs = [];
MissileConfigs = [];
TankConfigs = new List<TankConfig>();
MissileConfigs = new List<MissileConfig>();
LaserDesignatorConfig = new LaserDesignatorConfig();
LaserBeamRiderConfig = new LaserBeamRiderConfig();
LaserWarnerConfig = new LaserWarnerConfig();
@ -325,35 +326,55 @@ namespace ActiveProtect.SimulationEnvironment
/// <summary>
/// 导弹距离参数结构
/// </summary>
public struct MissileDistanceParams(double terminalGuidanceDistance, double attackDistance, double explosionDistance)
public struct MissileDistanceParams
{
/// <summary>
/// 终端制导距离(米)
/// </summary>
public double TerminalGuidanceDistance { get; set; } = terminalGuidanceDistance;
public double TerminalGuidanceDistance;
/// <summary>
/// 攻击距离(米)
/// </summary>
public double AttackDistance { get; set; } = attackDistance;
public double AttackDistance;
/// <summary>
/// 爆炸距离(米)
/// </summary>
public double ExplosionDistance { get; set; } = explosionDistance;
public double ExplosionDistance;
public MissileDistanceParams(double terminalGuidanceDistance, double attackDistance, double explosionDistance)
{
TerminalGuidanceDistance = terminalGuidanceDistance;
AttackDistance = attackDistance;
ExplosionDistance = explosionDistance;
}
}
/// <summary>
/// <summary>
/// 导弹飞行阶段配置结构
/// </summary>
public struct FlightStageConfig(bool enableLaunch = true, bool enableAcceleration = true, bool enableCruise = true,
bool enableTerminalGuidance = true, bool enableAttack = true)
public struct FlightStageConfig
{
public bool EnableLaunch = enableLaunch;
public bool EnableAcceleration = enableAcceleration;
public bool EnableCruise = enableCruise;
public bool EnableTerminalGuidance = enableTerminalGuidance;
public bool EnableAttack = enableAttack;
/// <summary>
/// 启用发射阶段
/// </summary>
public bool EnableLaunch;
/// <summary>
/// 启用加速阶段
/// </summary>
public bool EnableAcceleration;
/// <summary>
/// 启用巡航阶段
/// </summary>
public bool EnableCruise;
/// <summary>
/// 启用终端制导阶段
/// </summary>
public bool EnableTerminalGuidance;
/// <summary>
/// 启用攻击阶段
/// </summary>
public bool EnableAttack;
/// <summary>
/// 标准导弹的预设配置, 所有阶段都启用
@ -384,6 +405,15 @@ namespace ActiveProtect.SimulationEnvironment
/// 毫米波末制导导弹的预设配置
/// </summary>
public static FlightStageConfig MillimeterWaveTerminalGuidance => new(true, true, true, true, true);
public FlightStageConfig(bool enableLaunch, bool enableAcceleration, bool enableCruise, bool enableTerminalGuidance, bool enableAttack)
{
EnableLaunch = enableLaunch;
EnableAcceleration = enableAcceleration;
EnableCruise = enableCruise;
EnableTerminalGuidance = enableTerminalGuidance;
EnableAttack = enableAttack;
}
}
/// <summary>

View File

@ -5,37 +5,54 @@ namespace ActiveProtect.SimulationEnvironment
/// <summary>
/// 仿真元素的抽象基类,所有仿真中的实体都继承自此类
/// </summary>
public abstract class SimulationElement(string id, Vector3D position, Orientation orientation, ISimulationManager simulationManager)
public abstract class SimulationElement
{
/// <summary>
/// 仿真元素的唯一标识符
/// </summary>
public virtual string Id { get; set; } = id;
public virtual string Id { get; set; }
/// <summary>
/// 仿真元素的当前位置
/// </summary>
public virtual Vector3D Position { get; set; } = position;
public virtual Vector3D Position { get; set; }
/// <summary>
/// 仿真元素的当前速度
/// </summary>
public virtual Vector3D Velocity { get; set; } = Vector3D.Zero;
public virtual Vector3D Velocity { get; set; }
/// <summary>
/// 仿真元素的当前朝向
/// </summary>
public virtual Orientation Orientation { get; set; } = orientation;
public virtual Orientation Orientation { get; set; }
/// <summary>
/// 仿真元素是否处于活动状态
/// </summary>
public virtual bool IsActive { get; protected set; } = true;
public virtual bool IsActive { get; protected set; }
/// <summary>
/// 仿真管理器的引用
/// </summary>
public ISimulationManager SimulationManager { get; set; } = simulationManager;
public ISimulationManager SimulationManager { get; set; }
/// <summary>
/// 构造函数
/// </summary>
/// <param name="id">仿真元素的唯一标识符</param>
/// <param name="position">初始位置</param>
/// <param name="orientation">初始朝向</param>
/// <param name="simulationManager">仿真管理器</param>
protected SimulationElement(string id, Vector3D position, Orientation orientation, ISimulationManager simulationManager)
{
Id = id;
Position = position;
Orientation = orientation;
SimulationManager = simulationManager;
Velocity = Vector3D.Zero;
IsActive = true;
}
/// <summary>
/// 更新仿真元素的状态

View File

@ -34,17 +34,32 @@ namespace ActiveProtect.SimulationEnvironment
/// </summary>
public class LaserIlluminationStartEvent : SimulationEvent
{
public required LaserDesignator LaserDesignator { get; set; }
public required SimulationElement Target { get; set; }
/// <summary>
/// 激光定位器
/// </summary>
public LaserDesignator? LaserDesignator { get; set; }
/// <summary>
/// 目标元素
/// </summary>
public SimulationElement? Target { get; set; }
}
/// <summary
/// <summary>
/// 激光照射更新事件
/// </summary>
public class LaserIlluminationUpdateEvent : SimulationEvent
{
public required LaserDesignator LaserDesignator { get; set; }
public required SimulationElement Target { get; set; }
/// <summary>
/// 激光定位器
/// </summary>
public LaserDesignator? LaserDesignator { get; set; }
/// <summary>
/// 目标元素
/// </summary>
public SimulationElement? Target { get; set; }
}
/// <summary
@ -52,8 +67,8 @@ namespace ActiveProtect.SimulationEnvironment
/// </summary>
public class LaserIlluminationStopEvent : SimulationEvent
{
public required LaserDesignator LaserDesignator { get; set; }
public required SimulationElement Target { get; set; }
public LaserDesignator? LaserDesignator { get; set; }
public SimulationElement? Target { get; set; }
}
/// <summary>
@ -135,7 +150,7 @@ namespace ActiveProtect.SimulationEnvironment
/// </summary>
public class LaserBeamStartEvent : SimulationEvent
{
public required LaserBeamRider LaserBeamRider { get; set; }
public LaserBeamRider? LaserBeamRider { get; set; }
}
/// <summary>
@ -143,7 +158,7 @@ namespace ActiveProtect.SimulationEnvironment
/// </summary>
public class LaserBeamUpdateEvent : SimulationEvent
{
public required LaserBeamRider LaserBeamRider { get; set; }
public LaserBeamRider? LaserBeamRider { get; set; }
}
/// <summary>
@ -151,6 +166,6 @@ namespace ActiveProtect.SimulationEnvironment
/// </summary>
public class LaserBeamStopEvent : SimulationEvent
{
public required LaserBeamRider LaserBeamRider { get; set; }
public LaserBeamRider? LaserBeamRider { get; set; }
}
}

View File

@ -81,7 +81,7 @@ namespace ActiveProtect.SimulationEnvironment
public SimulationManager(SimulationConfig config)
{
this.config = config;
Elements = [];
Elements = new List<SimulationElement>();
CurrentTime = 0;
IsSimulationEnded = false;
InitializeSimulation();
@ -232,7 +232,7 @@ namespace ActiveProtect.SimulationEnvironment
var eventType = typeof(T);
if (!eventHandlers.TryGetValue(eventType, out List<Delegate>? value))
{
value = [];
value = new List<Delegate>();
eventHandlers[eventType] = value;
}
@ -244,7 +244,7 @@ namespace ActiveProtect.SimulationEnvironment
{
if (!elementSubscriptions.TryGetValue(element, out List<(Type, Delegate)>? subscriptions))
{
subscriptions = [];
subscriptions = new List<(Type, Delegate)>();
elementSubscriptions[element] = subscriptions;
}

BIN
bin/Debug/net6.0/ActiveProtect Executable file

Binary file not shown.

View File

@ -0,0 +1,23 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v6.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v6.0": {
"ActiveProtect/1.0.0": {
"runtime": {
"ActiveProtect.dll": {}
}
}
}
},
"libraries": {
"ActiveProtect/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,9 @@
{
"runtimeOptions": {
"tfm": "net6.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "6.0.0"
}
}
}

View File

@ -0,0 +1,24 @@
{
"runtimeTarget": {
"name": ".NETStandard,Version=v2.1/",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETStandard,Version=v2.1": {},
".NETStandard,Version=v2.1/": {
"ActiveProtect/1.0.0": {
"runtime": {
"ActiveProtect.dll": {}
}
}
}
},
"libraries": {
"ActiveProtect/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}

Binary file not shown.

Binary file not shown.

View File

@ -17,14 +17,14 @@
"/Users/tianjianyong/.nuget/NuGet/NuGet.Config"
],
"originalTargetFrameworks": [
"net8.0"
"net6.0"
],
"sources": {
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"net6.0": {
"targetAlias": "net6.0",
"projectReferences": {}
}
},
@ -40,8 +40,8 @@
}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"net6.0": {
"targetAlias": "net6.0",
"imports": [
"net461",
"net462",
@ -53,12 +53,26 @@
],
"assetTargetFallback": true,
"warn": true,
"downloadDependencies": [
{
"name": "Microsoft.AspNetCore.App.Ref",
"version": "[6.0.33, 6.0.33]"
},
{
"name": "Microsoft.NETCore.App.Host.osx-arm64",
"version": "[6.0.33, 6.0.33]"
},
{
"name": "Microsoft.NETCore.App.Ref",
"version": "[6.0.33, 6.0.33]"
}
],
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "/usr/local/share/dotnet/sdk/8.0.402/PortableRuntimeIdentifierGraph.json"
"runtimeIdentifierGraphPath": "/usr/local/share/dotnet/sdk/8.0.402/RuntimeIdentifierGraph.json"
}
}
}

View File

@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]

View File

@ -0,0 +1,22 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("ActiveProtect")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+e14978c785bbbc984facc644a8d191edce24c75c")]
[assembly: System.Reflection.AssemblyProductAttribute("ActiveProtect")]
[assembly: System.Reflection.AssemblyTitleAttribute("ActiveProtect")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// 由 MSBuild WriteCodeFragment 类生成。

View File

@ -0,0 +1 @@
d6e2f077e469fa47c1242ecde48fddf59a202b3ea36ab99595984219b25752f5

View File

@ -0,0 +1,13 @@
is_global = true
build_property.TargetFramework = net6.0
build_property.TargetPlatformMinVersion =
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property.EnforceExtendedAnalyzerRules =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = ActiveProtect
build_property.ProjectDir = /Users/tianjianyong/apps/ActiveProtect/
build_property.EnableComHosting =
build_property.EnableGeneratedComInterfaceComImportInterop =

Binary file not shown.

View File

@ -0,0 +1 @@
d599ebd2c33554dd309f6ac72929b62ad5bb06769660812e83f209fa4bb5a0fe

View File

@ -0,0 +1,14 @@
/Users/tianjianyong/apps/ActiveProtect/bin/Debug/net6.0/ActiveProtect
/Users/tianjianyong/apps/ActiveProtect/bin/Debug/net6.0/ActiveProtect.deps.json
/Users/tianjianyong/apps/ActiveProtect/bin/Debug/net6.0/ActiveProtect.runtimeconfig.json
/Users/tianjianyong/apps/ActiveProtect/bin/Debug/net6.0/ActiveProtect.dll
/Users/tianjianyong/apps/ActiveProtect/bin/Debug/net6.0/ActiveProtect.pdb
/Users/tianjianyong/apps/ActiveProtect/obj/Debug/net6.0/ActiveProtect.GeneratedMSBuildEditorConfig.editorconfig
/Users/tianjianyong/apps/ActiveProtect/obj/Debug/net6.0/ActiveProtect.AssemblyInfoInputs.cache
/Users/tianjianyong/apps/ActiveProtect/obj/Debug/net6.0/ActiveProtect.AssemblyInfo.cs
/Users/tianjianyong/apps/ActiveProtect/obj/Debug/net6.0/ActiveProtect.csproj.CoreCompileInputs.cache
/Users/tianjianyong/apps/ActiveProtect/obj/Debug/net6.0/ActiveProtect.dll
/Users/tianjianyong/apps/ActiveProtect/obj/Debug/net6.0/refint/ActiveProtect.dll
/Users/tianjianyong/apps/ActiveProtect/obj/Debug/net6.0/ActiveProtect.pdb
/Users/tianjianyong/apps/ActiveProtect/obj/Debug/net6.0/ActiveProtect.genruntimeconfig.cache
/Users/tianjianyong/apps/ActiveProtect/obj/Debug/net6.0/ref/ActiveProtect.dll

Binary file not shown.

View File

@ -0,0 +1 @@
404a820adea6677bf6611952c76ec29661acb00b5148a15f219d74c18797fd97

Binary file not shown.

BIN
obj/Debug/net6.0/apphost Executable file

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("ActiveProtect")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+f574c1be6bcbb73b38f2347680d3f4f4e2c241dd")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+e14978c785bbbc984facc644a8d191edce24c75c")]
[assembly: System.Reflection.AssemblyProductAttribute("ActiveProtect")]
[assembly: System.Reflection.AssemblyTitleAttribute("ActiveProtect")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@ -1 +1 @@
26cdf876bff1ffe1787c12bced73fbbaf39d90b3e9182600d9597f4f5ccc12d8
d6e2f077e469fa47c1242ecde48fddf59a202b3ea36ab99595984219b25752f5

View File

@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]

View File

@ -0,0 +1,22 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("ActiveProtect")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+e14978c785bbbc984facc644a8d191edce24c75c")]
[assembly: System.Reflection.AssemblyProductAttribute("ActiveProtect")]
[assembly: System.Reflection.AssemblyTitleAttribute("ActiveProtect")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// 由 MSBuild WriteCodeFragment 类生成。

View File

@ -0,0 +1 @@
d6e2f077e469fa47c1242ecde48fddf59a202b3ea36ab99595984219b25752f5

View File

@ -0,0 +1,5 @@
is_global = true
build_property.RootNamespace = ActiveProtect
build_property.ProjectDir = /Users/tianjianyong/apps/ActiveProtect/
build_property.EnableComHosting =
build_property.EnableGeneratedComInterfaceComImportInterop =

View File

@ -0,0 +1,8 @@
// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;

Binary file not shown.

View File

@ -0,0 +1 @@
d1ea287e903154dc338b90307ca21673394cf3b7d4242612dd7b8e88b0421550

View File

@ -0,0 +1,9 @@
/Users/tianjianyong/apps/ActiveProtect/obj/Debug/netstandard2.1/ActiveProtect.GeneratedMSBuildEditorConfig.editorconfig
/Users/tianjianyong/apps/ActiveProtect/obj/Debug/netstandard2.1/ActiveProtect.AssemblyInfoInputs.cache
/Users/tianjianyong/apps/ActiveProtect/obj/Debug/netstandard2.1/ActiveProtect.AssemblyInfo.cs
/Users/tianjianyong/apps/ActiveProtect/obj/Debug/netstandard2.1/ActiveProtect.csproj.CoreCompileInputs.cache
/Users/tianjianyong/apps/ActiveProtect/bin/Debug/netstandard2.1/ActiveProtect.deps.json
/Users/tianjianyong/apps/ActiveProtect/bin/Debug/netstandard2.1/ActiveProtect.dll
/Users/tianjianyong/apps/ActiveProtect/bin/Debug/netstandard2.1/ActiveProtect.pdb
/Users/tianjianyong/apps/ActiveProtect/obj/Debug/netstandard2.1/ActiveProtect.dll
/Users/tianjianyong/apps/ActiveProtect/obj/Debug/netstandard2.1/ActiveProtect.pdb

Binary file not shown.

Binary file not shown.

View File

@ -1,11 +1,11 @@
{
"version": 3,
"targets": {
"net8.0": {}
"net6.0": {}
},
"libraries": {},
"projectFileDependencyGroups": {
"net8.0": []
"net6.0": []
},
"packageFolders": {
"/Users/tianjianyong/.nuget/packages/": {}
@ -23,14 +23,14 @@
"/Users/tianjianyong/.nuget/NuGet/NuGet.Config"
],
"originalTargetFrameworks": [
"net8.0"
"net6.0"
],
"sources": {
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"net6.0": {
"targetAlias": "net6.0",
"projectReferences": {}
}
},
@ -46,8 +46,8 @@
}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"net6.0": {
"targetAlias": "net6.0",
"imports": [
"net461",
"net462",
@ -59,12 +59,26 @@
],
"assetTargetFallback": true,
"warn": true,
"downloadDependencies": [
{
"name": "Microsoft.AspNetCore.App.Ref",
"version": "[6.0.33, 6.0.33]"
},
{
"name": "Microsoft.NETCore.App.Host.osx-arm64",
"version": "[6.0.33, 6.0.33]"
},
{
"name": "Microsoft.NETCore.App.Ref",
"version": "[6.0.33, 6.0.33]"
}
],
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "/usr/local/share/dotnet/sdk/8.0.402/PortableRuntimeIdentifierGraph.json"
"runtimeIdentifierGraphPath": "/usr/local/share/dotnet/sdk/8.0.402/RuntimeIdentifierGraph.json"
}
}
}

View File

@ -1,8 +1,12 @@
{
"version": 2,
"dgSpecHash": "jBSl2ThGU2M=",
"dgSpecHash": "j5PpCU9trrQ=",
"success": true,
"projectFilePath": "/Users/tianjianyong/apps/ActiveProtect/ActiveProtect.csproj",
"expectedPackageFiles": [],
"expectedPackageFiles": [
"/Users/tianjianyong/.nuget/packages/microsoft.netcore.app.ref/6.0.33/microsoft.netcore.app.ref.6.0.33.nupkg.sha512",
"/Users/tianjianyong/.nuget/packages/microsoft.aspnetcore.app.ref/6.0.33/microsoft.aspnetcore.app.ref.6.0.33.nupkg.sha512",
"/Users/tianjianyong/.nuget/packages/microsoft.netcore.app.host.osx-arm64/6.0.33/microsoft.netcore.app.host.osx-arm64.6.0.33.nupkg.sha512"
],
"logs": []
}