deploy: 54c7e5fbc7
This commit is contained in:
168
coverage/playmode/Assets/Scripts/Config/ConfigLoader.cs
Normal file
168
coverage/playmode/Assets/Scripts/Config/ConfigLoader.cs
Normal file
@@ -0,0 +1,168 @@
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
public static class ConfigLoader {
|
||||
|
||||
private static string LoadFromStreamingAssets(string relativePath)
|
||||
{
|
||||
string filePath = Path.Combine(Application.streamingAssetsPath, relativePath);
|
||||
|
||||
#if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX || UNITY_STANDALONE_LINUX || UNITY_EDITOR_LINUX || UNITY_IOS
|
||||
if (!filePath.StartsWith("file://"))
|
||||
{
|
||||
filePath = "file://" + filePath;
|
||||
}
|
||||
#endif
|
||||
|
||||
UnityWebRequest www = UnityWebRequest.Get(filePath);
|
||||
www.SendWebRequest();
|
||||
|
||||
// Wait for the request to complete
|
||||
while (!www.isDone)
|
||||
{
|
||||
// You might want to yield return null here if this is called from a coroutine
|
||||
}
|
||||
|
||||
if (www.result != UnityWebRequest.Result.Success)
|
||||
{
|
||||
Debug.LogError($"Error loading file at {filePath}: {www.error}");
|
||||
return null;
|
||||
}
|
||||
|
||||
return www.downloadHandler.text;
|
||||
}
|
||||
|
||||
public static SimulationConfig LoadSimulationConfig(string configFileName)
|
||||
{
|
||||
string relativePath = Path.Combine("Configs", configFileName);
|
||||
string fileContent = LoadFromStreamingAssets(relativePath);
|
||||
|
||||
if (string.IsNullOrEmpty(fileContent))
|
||||
{
|
||||
Debug.LogError($"Failed to load SimulationConfig from {relativePath}");
|
||||
return null;
|
||||
}
|
||||
|
||||
return JsonConvert.DeserializeObject<SimulationConfig>(fileContent, new JsonSerializerSettings
|
||||
{
|
||||
Converters = { new Newtonsoft.Json.Converters.StringEnumConverter() }
|
||||
});
|
||||
}
|
||||
|
||||
public static StaticConfig LoadStaticConfig(string configFileName)
|
||||
{
|
||||
string relativePath = Path.Combine("Configs/Models", configFileName);
|
||||
string fileContent = LoadFromStreamingAssets(relativePath);
|
||||
|
||||
if (string.IsNullOrEmpty(fileContent))
|
||||
{
|
||||
Debug.LogError($"Failed to load StaticConfig from {relativePath}");
|
||||
return null;
|
||||
}
|
||||
|
||||
return JsonConvert.DeserializeObject<StaticConfig>(fileContent, new JsonSerializerSettings
|
||||
{
|
||||
Converters = { new Newtonsoft.Json.Converters.StringEnumConverter() }
|
||||
});
|
||||
}
|
||||
|
||||
public static void PrintSimulationConfig(SimulationConfig config)
|
||||
{
|
||||
if (config == null)
|
||||
{
|
||||
Debug.Log("SimulationConfig is null");
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.Log("SimulationConfig:");
|
||||
Debug.Log($"Time Scale: {config.timeScale}");
|
||||
|
||||
Debug.Log("Interceptor Swarm Configurations:");
|
||||
for (int i = 0; i < config.interceptor_swarm_configs.Count; i++)
|
||||
{
|
||||
PrintSwarmConfig(config.interceptor_swarm_configs[i], $"Interceptor Swarm {i + 1}");
|
||||
}
|
||||
|
||||
Debug.Log("Threat Swarm Configurations:");
|
||||
for (int i = 0; i < config.threat_swarm_configs.Count; i++)
|
||||
{
|
||||
PrintSwarmConfig(config.threat_swarm_configs[i], $"Threat Swarm {i + 1}");
|
||||
}
|
||||
}
|
||||
|
||||
private static void PrintSwarmConfig(SwarmConfig swarmConfig, string swarmName)
|
||||
{
|
||||
Debug.Log($"{swarmName}:");
|
||||
Debug.Log($" Number of Agents: {swarmConfig.num_agents}");
|
||||
PrintAgentConfig(swarmConfig.agent_config);
|
||||
}
|
||||
|
||||
private static void PrintAgentConfig(AgentConfig agentConfig)
|
||||
{
|
||||
Debug.Log(" Agent Configuration:");
|
||||
Debug.Log($" Interceptor Type: {agentConfig.interceptor_type}");
|
||||
Debug.Log($" Threat Type: {agentConfig.threat_type}");
|
||||
PrintInitialState(agentConfig.initial_state);
|
||||
PrintStandardDeviation(agentConfig.standard_deviation);
|
||||
PrintDynamicConfig(agentConfig.dynamic_config);
|
||||
PrintPlottingConfig(agentConfig.plotting_config);
|
||||
PrintSubmunitionsConfig(agentConfig.submunitions_config);
|
||||
}
|
||||
|
||||
private static void PrintInitialState(InitialState initialState)
|
||||
{
|
||||
Debug.Log(" Initial State:");
|
||||
Debug.Log($" Position: {initialState.position}");
|
||||
Debug.Log($" Rotation: {initialState.rotation}");
|
||||
Debug.Log($" Velocity: {initialState.velocity}");
|
||||
}
|
||||
|
||||
private static void PrintStandardDeviation(StandardDeviation standardDeviation)
|
||||
{
|
||||
Debug.Log(" Standard Deviation:");
|
||||
Debug.Log($" Position: {standardDeviation.position}");
|
||||
Debug.Log($" Velocity: {standardDeviation.velocity}");
|
||||
}
|
||||
|
||||
private static void PrintDynamicConfig(DynamicConfig dynamicConfig)
|
||||
{
|
||||
Debug.Log(" Dynamic Configuration:");
|
||||
Debug.Log($" Launch Time: {dynamicConfig.launch_config.launch_time}");
|
||||
Debug.Log($" Sensor Type: {dynamicConfig.sensor_config.type}");
|
||||
Debug.Log($" Sensor Frequency: {dynamicConfig.sensor_config.frequency}");
|
||||
}
|
||||
|
||||
private static void PrintPlottingConfig(PlottingConfig plottingConfig)
|
||||
{
|
||||
Debug.Log(" Plotting Configuration:");
|
||||
Debug.Log($" Color: {plottingConfig.color}");
|
||||
Debug.Log($" Line Style: {plottingConfig.linestyle}");
|
||||
Debug.Log($" Marker: {plottingConfig.marker}");
|
||||
}
|
||||
|
||||
private static void PrintSubmunitionsConfig(SubmunitionsConfig submunitionsConfig)
|
||||
{
|
||||
if (submunitionsConfig == null)
|
||||
{
|
||||
Debug.Log(" Submunitions Configuration: None");
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.Log(" Submunitions Configuration:");
|
||||
Debug.Log($" Number of Submunitions: {submunitionsConfig.num_submunitions}");
|
||||
Debug.Log($" Launch Time: {submunitionsConfig.launch_config.launch_time}");
|
||||
PrintSubmunitionAgentConfig(submunitionsConfig.agent_config);
|
||||
}
|
||||
|
||||
private static void PrintSubmunitionAgentConfig(SubmunitionAgentConfig agentConfig)
|
||||
{
|
||||
Debug.Log(" Submunition Agent Configuration:");
|
||||
Debug.Log($" Interceptor Type: {agentConfig.interceptor_type}");
|
||||
PrintInitialState(agentConfig.initial_state);
|
||||
PrintStandardDeviation(agentConfig.standard_deviation);
|
||||
PrintDynamicConfig(agentConfig.dynamic_config);
|
||||
PrintPlottingConfig(agentConfig.plotting_config);
|
||||
}
|
||||
}
|
||||
11
coverage/playmode/Assets/Scripts/Config/ConfigLoader.cs.meta
Normal file
11
coverage/playmode/Assets/Scripts/Config/ConfigLoader.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: da3b9eead33b94a4f8df7a4af7a79d49
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
123
coverage/playmode/Assets/Scripts/Config/SimulationConfig.cs
Normal file
123
coverage/playmode/Assets/Scripts/Config/SimulationConfig.cs
Normal file
@@ -0,0 +1,123 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
|
||||
[Serializable]
|
||||
public class SimulationConfig {
|
||||
[Header("Simulation Settings")]
|
||||
public float timeScale = 0.05f;
|
||||
|
||||
[Header("Interceptor Swarm Configurations")]
|
||||
public List<SwarmConfig> interceptor_swarm_configs = new List<SwarmConfig>();
|
||||
|
||||
[Header("Threat Swarm Configurations")]
|
||||
public List<SwarmConfig> threat_swarm_configs = new List<SwarmConfig>();
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class DynamicConfig {
|
||||
public LaunchConfig launch_config;
|
||||
public SensorConfig sensor_config;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class SwarmConfig {
|
||||
public int num_agents;
|
||||
public AgentConfig agent_config;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class AgentConfig {
|
||||
public InterceptorType interceptor_type;
|
||||
public ThreatType threat_type;
|
||||
public InitialState initial_state;
|
||||
public StandardDeviation standard_deviation;
|
||||
public DynamicConfig dynamic_config;
|
||||
public PlottingConfig plotting_config;
|
||||
public SubmunitionsConfig submunitions_config;
|
||||
|
||||
public static AgentConfig FromSubmunitionAgentConfig(SubmunitionAgentConfig submunitionConfig) {
|
||||
return new AgentConfig {
|
||||
interceptor_type = submunitionConfig.interceptor_type,
|
||||
initial_state = submunitionConfig.initial_state,
|
||||
standard_deviation = submunitionConfig.standard_deviation,
|
||||
dynamic_config = submunitionConfig.dynamic_config,
|
||||
plotting_config = submunitionConfig.plotting_config,
|
||||
// Set other fields as needed, using default values if not present in SubmunitionAgentConfig
|
||||
threat_type = ThreatType.DRONE, // Or another default value
|
||||
submunitions_config = null // Or a default value if needed
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class InitialState {
|
||||
public Vector3 position;
|
||||
public Vector3 rotation;
|
||||
public Vector3 velocity;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class StandardDeviation {
|
||||
public Vector3 position;
|
||||
public Vector3 velocity;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class LaunchConfig {
|
||||
public float launch_time;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class PlottingConfig {
|
||||
public ConfigColor color;
|
||||
public LineStyle linestyle;
|
||||
public Marker marker;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class SubmunitionsConfig {
|
||||
public int num_submunitions;
|
||||
public LaunchConfig launch_config;
|
||||
public SubmunitionAgentConfig agent_config;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class SubmunitionAgentConfig {
|
||||
public InterceptorType interceptor_type;
|
||||
public InitialState initial_state;
|
||||
public StandardDeviation standard_deviation;
|
||||
public DynamicConfig dynamic_config;
|
||||
public PlottingConfig plotting_config;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class SensorConfig {
|
||||
public SensorType type;
|
||||
public float frequency;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class TargetConfig {
|
||||
public ThreatType threat_type;
|
||||
public InitialState initial_state;
|
||||
public PlottingConfig plotting_config;
|
||||
public string prefabName;
|
||||
}
|
||||
|
||||
// Enums
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public enum InterceptorType { HYDRA_70, MICROMISSILE }
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public enum ThreatType { DRONE, ANTISHIP_MISSILE }
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public enum ConfigColor { BLUE, GREEN, RED }
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public enum LineStyle { DOTTED, SOLID }
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public enum Marker { TRIANGLE_UP, TRIANGLE_DOWN, SQUARE }
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public enum SensorType { IDEAL }
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 79f1fe138866d6a40b209a4edcf2ee06
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
43
coverage/playmode/Assets/Scripts/Config/StaticConfig.cs
Normal file
43
coverage/playmode/Assets/Scripts/Config/StaticConfig.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
|
||||
[Serializable]
|
||||
public class StaticConfig {
|
||||
[Serializable]
|
||||
public class AccelerationConfig {
|
||||
public float maxReferenceAcceleration = 300f;
|
||||
public float referenceSpeed = 1000f;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class BoostConfig {
|
||||
public float boostTime = 0.3f;
|
||||
public float boostAcceleration = 350f;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class LiftDragConfig {
|
||||
public float liftCoefficient = 0.2f;
|
||||
public float dragCoefficient = 0.7f;
|
||||
public float liftDragRatio = 5f;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class BodyConfig {
|
||||
public float mass = 0.37f;
|
||||
public float crossSectionalArea = 3e-4f;
|
||||
public float finArea = 6e-4f;
|
||||
public float bodyArea = 1e-2f;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class HitConfig {
|
||||
public float hitRadius = 1f;
|
||||
public float killProbability = 0.9f;
|
||||
}
|
||||
|
||||
public AccelerationConfig accelerationConfig;
|
||||
public BoostConfig boostConfig;
|
||||
public LiftDragConfig liftDragConfig;
|
||||
public BodyConfig bodyConfig;
|
||||
public HitConfig hitConfig;
|
||||
}
|
||||
11
coverage/playmode/Assets/Scripts/Config/StaticConfig.cs.meta
Normal file
11
coverage/playmode/Assets/Scripts/Config/StaticConfig.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 35d9cdcf93cb04b40a7538fc87071e3b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user