| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using UnityEngine; |
| | 4 | | using Newtonsoft.Json; |
| | 5 | | using Newtonsoft.Json.Converters; |
| | 6 | |
|
| | 7 | | [Serializable] |
| | 8 | | public class SimulationConfig { |
| | 9 | | [Header("Simulation Settings")] |
| | 10 | | public float timeScale = 0.05f; |
| | 11 | |
|
| | 12 | | public float endTime = 300f; // 5 minutes by default |
| | 13 | |
|
| | 14 | | [Header("Interceptor Swarm Configurations")] |
| | 15 | | public List<SwarmConfig> interceptor_swarm_configs = new List<SwarmConfig>(); |
| | 16 | |
|
| | 17 | | [Header("Threat Swarm Configurations")] |
| | 18 | | public List<SwarmConfig> threat_swarm_configs = new List<SwarmConfig>(); |
| | 19 | | } |
| | 20 | |
|
| | 21 | | [Serializable] |
| | 22 | | public class DynamicConfig { |
| | 23 | | public LaunchConfig launch_config; |
| | 24 | | public SensorConfig sensor_config; |
| | 25 | | public FlightConfig flight_config; |
| | 26 | | } |
| | 27 | |
|
| | 28 | | [Serializable] |
| | 29 | | public class SwarmConfig { |
| | 30 | | public int num_agents; |
| | 31 | | public DynamicAgentConfig dynamic_agent_config; |
| | 32 | | } |
| | 33 | |
|
| | 34 | | [Serializable] |
| | 35 | | public class DynamicAgentConfig { |
| | 36 | | public string name; |
| | 37 | | public string agent_model; |
| | 38 | | public string attack_behavior; |
| | 39 | | public InitialState initial_state; |
| | 40 | | public StandardDeviation standard_deviation; |
| | 41 | | public DynamicConfig dynamic_config; |
| | 42 | | public PlottingConfig plotting_config; |
| | 43 | | public SubmunitionsConfig submunitions_config; |
| | 44 | |
|
| | 45 | | public static DynamicAgentConfig FromSubmunitionDynamicAgentConfig( |
| 0 | 46 | | SubmunitionDynamicAgentConfig submunitionConfig) { |
| 0 | 47 | | return new DynamicAgentConfig { |
| | 48 | | agent_model = submunitionConfig.agent_model, initial_state = submunitionConfig.initial_state, |
| | 49 | | standard_deviation = submunitionConfig.standard_deviation, |
| | 50 | | dynamic_config = submunitionConfig.dynamic_config, |
| | 51 | | plotting_config = submunitionConfig.plotting_config, |
| | 52 | | // Set other fields as needed, using default values if not present in |
| | 53 | | // SubmunitionDynamicAgentConfig |
| | 54 | | submunitions_config = null, // Or a default value if needed |
| | 55 | | }; |
| 0 | 56 | | } |
| | 57 | | } |
| | 58 | |
|
| | 59 | | [Serializable] |
| | 60 | | public class InitialState { |
| | 61 | | public Vector3 position; |
| | 62 | | public Vector3 rotation; |
| | 63 | | public Vector3 velocity; |
| | 64 | | } |
| | 65 | |
|
| | 66 | | [Serializable] |
| | 67 | | public class StandardDeviation { |
| | 68 | | public Vector3 position; |
| | 69 | | public Vector3 velocity; |
| | 70 | | } |
| | 71 | |
|
| | 72 | | [Serializable] |
| | 73 | | public class LaunchConfig { |
| | 74 | | public float launch_time; |
| | 75 | | } |
| | 76 | |
|
| | 77 | | [Serializable] |
| | 78 | | public class PlottingConfig { |
| | 79 | | public ConfigColor color; |
| | 80 | | public LineStyle linestyle; |
| | 81 | | public Marker marker; |
| | 82 | | } |
| | 83 | |
|
| | 84 | | [Serializable] |
| | 85 | | public class SubmunitionsConfig { |
| | 86 | | public int num_submunitions; |
| | 87 | | public double dispense_time; |
| | 88 | | public SubmunitionDynamicAgentConfig dynamic_agent_config; |
| | 89 | | } |
| | 90 | |
|
| | 91 | | [Serializable] |
| | 92 | | public class SubmunitionDynamicAgentConfig { |
| | 93 | | public string agent_model; |
| | 94 | | public InitialState initial_state; |
| | 95 | | public StandardDeviation standard_deviation; |
| | 96 | | public DynamicConfig dynamic_config; |
| | 97 | | public PlottingConfig plotting_config; |
| | 98 | | } |
| | 99 | |
|
| | 100 | | [Serializable] |
| | 101 | | public class SensorConfig { |
| | 102 | | public SensorType type; |
| | 103 | | public float frequency; |
| | 104 | | } |
| | 105 | |
|
| | 106 | | [Serializable] |
| | 107 | | public class FlightConfig { |
| | 108 | | public bool augmentedPnEnabled; |
| | 109 | | public bool evasionEnabled; |
| | 110 | | public float evasionRangeThreshold; |
| | 111 | | } |
| | 112 | |
|
| | 113 | | [Serializable] |
| | 114 | | public class ThreatConfig { |
| | 115 | | public AgentClass threat_class; |
| | 116 | | public InitialState initial_state; |
| | 117 | | public PlottingConfig plotting_config; |
| | 118 | | public string prefabName; |
| | 119 | | } |
| | 120 | |
|
| | 121 | | // Enums |
| | 122 | |
|
| | 123 | | [JsonConverter(typeof(StringEnumConverter))] |
| | 124 | | public enum AgentClass { NONE, FIXEDWING, ROTARYWING, BALLISTIC } |
| | 125 | | [JsonConverter(typeof(StringEnumConverter))] |
| | 126 | | public enum ConfigColor { BLUE, GREEN, RED } |
| | 127 | | [JsonConverter(typeof(StringEnumConverter))] |
| | 128 | | public enum LineStyle { DOTTED, SOLID } |
| | 129 | | [JsonConverter(typeof(StringEnumConverter))] |
| | 130 | | public enum Marker { TRIANGLE_UP, TRIANGLE_DOWN, SQUARE } |
| | 131 | | [JsonConverter(typeof(StringEnumConverter))] |
| | 132 | | public enum SensorType { IDEAL } |