Better input and UI control, low FOV render

more-targets
Daniel Lovell 2024-09-24 17:05:33 -07:00
parent 2d56273d5a
commit e62ed34371
18 changed files with 2988 additions and 233 deletions

65
Assets/CameraPanel.cs Normal file
View File

@ -0,0 +1,65 @@
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Rendering;
public class CameraPanel : MonoBehaviour
{
/*
private RenderTexture _renderTexture;
private Camera _camera;
private RawImage _rawImage;
private Vector2Int _lastScreenSize;
void Start()
{
_rawImage = GetComponentInChildren<RawImage>();
_camera = GameObject.Find("Main Camera").GetComponent<Camera>();
_lastScreenSize = new Vector2Int(Screen.width, Screen.height);
// Create initial RenderTexture
_renderTexture = _rawImage.texture as RenderTexture;
_renderTexture.useDynamicScale = true;
_rawImage.texture = _renderTexture;
if (_camera != null)
{
_camera.targetTexture = _renderTexture;
}
UpdateRenderTextureSize();
}
void Update()
{
Vector2Int currentScreenSize = new Vector2Int(Screen.width, Screen.height);
if (currentScreenSize != _lastScreenSize)
{
UpdateRenderTextureSize();
_lastScreenSize = currentScreenSize;
}
}
void UpdateRenderTextureSize()
{
Vector2 panelSize = GetScaledPanelSize();
float widthScale = Mathf.Clamp01(panelSize.x / Screen.width);
float heightScale = Mathf.Clamp01(panelSize.y / Screen.height);
// Use the smaller scale to maintain aspect ratio
float scale = Mathf.Min(widthScale, heightScale);
// Update ScalableBufferManager
ScalableBufferManager.ResizeBuffers(scale, scale);
}
Vector2 GetScaledPanelSize()
{
RectTransform panelRectTransform = GetComponent<RectTransform>();
Vector2 panelSize = panelRectTransform.rect.size;
return new Vector2(
panelSize.x * panelRectTransform.lossyScale.x,
panelSize.y * panelRectTransform.lossyScale.y
);
}
*/
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 80fb2205acf32ec4c9e8dd8bfcf9b310
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@ -79,7 +79,11 @@ public class InputManager : MonoBehaviour
void HandleLockableInput()
{
HandleMouseInput();
if(mouseActive)
{
HandleMouseInput();
}
if (Input.GetKey(KeyCode.LeftShift))
{
CameraController.Instance.SetCameraSpeed(CameraController.Instance.GetCameraSpeedMax());
@ -131,6 +135,16 @@ public class InputManager : MonoBehaviour
}
if(Input.GetKeyDown(KeyCode.R))
{
SimManager.Instance.RestartSimulation();
}
if (Input.GetKeyDown(KeyCode.L)) // 'L' for Load
{
UIManager.Instance.ToggleConfigSelectorPanel();
}
if (Input.GetKeyDown(KeyCode.Space))
{
// Pause the time

View File

@ -30,8 +30,9 @@ public class SimManager : MonoBehaviour {
private IAssignment _assignmentScheme;
public delegate void SimulationEndedHandler();
public event SimulationEndedHandler OnSimulationEnded;
public delegate void SimulationEventHandler();
public event SimulationEventHandler OnSimulationEnded;
public event SimulationEventHandler OnSimulationStarted;
/// <summary>
/// Gets the elapsed simulation time.
@ -61,15 +62,14 @@ public class SimManager : MonoBehaviour {
} else {
Destroy(gameObject);
}
simulationConfig = ConfigLoader.LoadSimulationConfig("seven_missiles_seven_drone_targets.json");
simulationConfig = ConfigLoader.LoadSimulationConfig("1_salvo_1_hydra_7_drones.json");
Debug.Log(simulationConfig);
}
void Start() {
// Slow down time by simulationConfig.timeScale
if (Instance == this) {
InitializeSimulation();
simulationRunning = true;
StartSimulation();
}
}
@ -79,6 +79,12 @@ public class SimManager : MonoBehaviour {
Time.maximumDeltaTime = Time.timeScale * 0.15f;
}
public void StartSimulation() {
InitializeSimulation();
simulationRunning = true;
OnSimulationStarted?.Invoke();
}
public void PauseSimulation() {
SetTimeScale(0);
simulationRunning = false;
@ -115,6 +121,7 @@ public class SimManager : MonoBehaviour {
}
_assignmentScheme = new ThreatAssignment();
OnSimulationStarted?.Invoke();
}
public void AssignMissilesToTargets() {
@ -259,6 +266,20 @@ public class SimManager : MonoBehaviour {
return agentObject;
}
public void LoadNewConfig(string configFileName)
{
simulationConfig = ConfigLoader.LoadSimulationConfig(configFileName);
if (simulationConfig != null)
{
Debug.Log($"Loaded new configuration: {configFileName}");
RestartSimulation();
}
else
{
Debug.LogError($"Failed to load configuration: {configFileName}");
}
}
public void RestartSimulation() {
OnSimulationEnded?.Invoke();
@ -284,7 +305,7 @@ public class SimManager : MonoBehaviour {
_targets.Clear();
_unassignedTargets.Clear();
InitializeSimulation();
StartSimulation();
}
void Update() {

View File

@ -112,7 +112,8 @@ public class CameraController : MonoBehaviour
/// <summary>
/// Maximum distance for orbit.
/// </summary>
private float _orbitDistanceMax = 10000f;
[SerializeField]
private float _orbitDistanceMax = 20000f;
/// <summary>
/// Current horizontal orbit angle.

View File

@ -5,17 +5,25 @@ using UnityEngine.EventSystems;
public class UIElementMouseCapturer : EventTrigger
{
private bool _hasPointerEntered = false;
public override void OnPointerEnter(PointerEventData eventData)
{
InputManager.Instance.mouseActive = false;
_hasPointerEntered = true;
base.OnPointerEnter(eventData);
}
public override void OnPointerExit(PointerEventData eventData)
{
InputManager.Instance.mouseActive = true;
_hasPointerEntered = false;
base.OnPointerExit(eventData);
}
public void OnDisable()
{
Debug.Log("UIElementMouseCapturer OnDisable");
OnPointerExit(null);
}
}

View File

@ -1,8 +1,8 @@
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.UIElements;
using TMPro;
public class UIManager : MonoBehaviour
@ -10,8 +10,14 @@ public class UIManager : MonoBehaviour
public static UIManager Instance { get; private set; }
public GameObject botPanel;
[SerializeField]
private GameObject _agentStatusPanel;
[SerializeField]
private GameObject _configSelectorPanel;
private TMP_Dropdown _configDropdown;
public TextMeshProUGUI agentPanelText;
public TextMeshProUGUI simTimeText;
public TMP_FontAsset Font;
@ -26,15 +32,51 @@ public class UIManager : MonoBehaviour
if (Instance == null)
Instance = this;
else
Destroy(gameObject);
Destroy(gameObject);
}
void Start()
{
_configSelectorPanel.SetActive(false);
SetupConfigSelectorPanel();
//inputManager = InputManager.Instance;
//worldManager = WorldManager.Instance;
}
public void ToggleConfigSelectorPanel(){
_configSelectorPanel.SetActive(!_configSelectorPanel.activeSelf);
}
private void SetupConfigSelectorPanel(){
_configSelectorPanel.GetComponentInChildren<Button>().onClick.AddListener(delegate {
LoadSelectedConfig();
});
_configDropdown = _configSelectorPanel.GetComponentInChildren<TMP_Dropdown>();
PopulateConfigDropdown();
}
private void PopulateConfigDropdown(){
_configDropdown.ClearOptions();
string configPath = Path.Combine(Application.streamingAssetsPath, "Configs");
string[] configFiles = Directory.GetFiles(configPath, "*.json");
List<string> configFileNames = new List<string>();
foreach (string configFile in configFiles)
{
configFileNames.Add(Path.GetFileName(configFile));
}
_configDropdown.AddOptions(configFileNames);
}
private void LoadSelectedConfig(){
string selectedConfig = _configDropdown.options[_configDropdown.value].text;
SimManager.Instance.LoadNewConfig(selectedConfig);
_configSelectorPanel.SetActive(false);
//if(!InputManager.Instance.mouseActive){
// InputManager.Instance.mouseActive = true;
//}
}
public void SetUIMode(UIMode mode){
curMode = mode;
}
@ -65,12 +107,15 @@ public class UIManager : MonoBehaviour
SetAgentPanelText(agentPanelText);
}
private void UpdateSimTimeText()
{
simTimeText.text = "Elapsed Sim Time: " + SimManager.Instance.GetElapsedSimulationTime().ToString("F2");
}
// Update is called once per frame
void Update()
{
UpdateAgentPanel();
//UpdateAgentPanel();
UpdateSimTimeText();
}
}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: e0c9493619e84524083dc7a2928765c8
guid: be31f4e8178a52c4da61d1b82e74562f
DefaultImporter:
externalObjects: {}
userData:

View File

@ -0,0 +1,191 @@
{
"timeScale": 1,
"missile_swarm_configs": [
{
"num_agents": 10,
"agent_config": {
"missile_type": "HYDRA_70",
"target_type": "DRONE",
"initial_state": {
"position": { "x": 0, "y": 20, "z": 0 },
"rotation": { "x": -45, "y": 0, "z": 0 },
"velocity": { "x": 0, "y": 10, "z": 10 }
},
"standard_deviation": {
"position": { "x": 10, "y": 0, "z": 10 },
"velocity": { "x": 5, "y": 0, "z": 1 }
},
"dynamic_config": {
"launch_config": { "launch_time": 0 },
"sensor_config": {
"type": "IDEAL",
"frequency": 100
}
},
"submunitions_config": {
"num_submunitions": 7,
"launch_config": { "launch_time": 4 },
"agent_config": {
"missile_type": "MICROMISSILE",
"initial_state": {
"position": { "x": -171.3253, "y": 683.85236, "z": 846.74677 },
"rotation": { "x": 0, "y": 0, "z": 0 },
"velocity": { "x": -45.325005, "y": 110.16025, "z": 216.10002 }
},
"standard_deviation": {
"position": { "x": 5, "y": 5, "z": 5 },
"velocity": { "x": 0, "y": 0, "z": 0 }
},
"dynamic_config": {
"launch_config": { "launch_time": 0 },
"sensor_config": {
"type": "IDEAL",
"frequency": 100
}
}
}
}
}
},
{
"num_agents": 10,
"agent_config": {
"missile_type": "HYDRA_70",
"target_type": "DRONE",
"initial_state": {
"position": { "x": 200, "y": 20, "z": 0 },
"rotation": { "x": -60, "y": 0, "z": 0 },
"velocity": { "x": 0, "y": 10, "z": 12 }
},
"standard_deviation": {
"position": { "x": 10, "y": 0, "z": 10 },
"velocity": { "x": 5, "y": 0, "z": 1 }
},
"dynamic_config": {
"launch_config": { "launch_time": 10 },
"sensor_config": {
"type": "IDEAL",
"frequency": 100
}
},
"submunitions_config": {
"num_submunitions": 7,
"launch_config": { "launch_time": 12 },
"agent_config": {
"missile_type": "MICROMISSILE",
"initial_state": {
"position": { "x": -3.2042065, "y": 781.2401, "z": 1043.2384 },
"rotation": { "x": 0, "y": 0, "z": 0 },
"velocity": { "x": -72.93396, "y": 249.48598, "z": 385.07947 }
},
"standard_deviation": {
"position": { "x": 5, "y": 5, "z": 5 },
"velocity": { "x": 0, "y": 0, "z": 0 }
},
"dynamic_config": {
"launch_config": { "launch_time": 0 },
"sensor_config": {
"type": "IDEAL",
"frequency": 100
}
}
}
}
}
},
{
"num_agents": 10,
"agent_config": {
"missile_type": "HYDRA_70",
"target_type": "DRONE",
"initial_state": {
"position": { "x": -100, "y": 20, "z": 0 },
"rotation": { "x": -45, "y": 0, "z": 0 },
"velocity": { "x": 0, "y": 10, "z": 10 }
},
"standard_deviation": {
"position": { "x": 10, "y": 0, "z": 10 },
"velocity": { "x": 5, "y": 0, "z": 3 }
},
"dynamic_config": {
"launch_config": { "launch_time": 20 },
"sensor_config": {
"type": "IDEAL",
"frequency": 100
}
},
"submunitions_config": {
"num_submunitions": 7,
"launch_config": { "launch_time": 23 },
"agent_config": {
"missile_type": "MICROMISSILE",
"initial_state": {
"position": { "x": -246.4463, "y": 976.02924, "z": 1081.1262 },
"rotation": { "x": 0, "y": 0, "z": 0 },
"velocity": { "x": -31.540234, "y": 178.44958, "z": 249.32939 }
},
"standard_deviation": {
"position": { "x": 5, "y": 5, "z": 5 },
"velocity": { "x": 0, "y": 0, "z": 0 }
},
"dynamic_config": {
"launch_config": { "launch_time": 0 },
"sensor_config": {
"type": "IDEAL",
"frequency": 100
}
}
}
}
}
}
],
"target_swarm_configs": [
{
"num_agents": 200,
"agent_config": {
"missile_type": "HYDRA_70",
"target_type": "DRONE",
"initial_state": {
"position": { "x": 0, "y": 600, "z": 6000 },
"rotation": { "x": 90, "y": 0, "z": 0 },
"velocity": { "x": 0, "y": 0, "z": -50 }
},
"standard_deviation": {
"position": { "x": 1000, "y": 200, "z": 100 },
"velocity": { "x": 0, "y": 0, "z": 25 }
},
"dynamic_config": {
"launch_config": { "launch_time": 0 },
"sensor_config": {
"type": "IDEAL",
"frequency": 0
}
},
"submunitions_config": {
"num_submunitions": 0,
"launch_config": { "launch_time": 0 },
"agent_config": {
"missile_type": "HYDRA_70",
"initial_state": {
"position": { "x": 0, "y": 0, "z": 0 },
"rotation": { "x": 0, "y": 0, "z": 0 },
"velocity": { "x": 0, "y": 0, "z": 0 }
},
"standard_deviation": {
"position": { "x": 0, "y": 0, "z": 0 },
"velocity": { "x": 0, "y": 0, "z": 0 }
},
"dynamic_config": {
"launch_config": { "launch_time": 0 },
"sensor_config": {
"type": "IDEAL",
"frequency": 0
}
}
}
}
}
}
]
}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 7b6abee0a88d21f45a7acfe8cafd5fbf
guid: 760f5b1ba2c8b6b419d243eb4b49faa9
DefaultImporter:
externalObjects: {}
userData:

8
Assets/Textures.meta Normal file
View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 044c1dd1dd25cad43b94749dfa18ef01
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,40 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!84 &8400000
RenderTexture:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: CameraRenderTexture
m_ImageContentsHash:
serializedVersion: 2
Hash: 00000000000000000000000000000000
m_ForcedFallbackFormat: 4
m_DownscaleFallback: 0
m_IsAlphaChannelOptional: 0
serializedVersion: 5
m_Width: 1920
m_Height: 1080
m_AntiAliasing: 4
m_MipCount: -1
m_DepthStencilFormat: 94
m_ColorFormat: 8
m_MipMap: 0
m_GenerateMips: 1
m_SRGB: 0
m_UseDynamicScale: 1
m_BindMS: 0
m_EnableCompatibleFormat: 1
m_EnableRandomWrite: 0
m_TextureSettings:
serializedVersion: 2
m_FilterMode: 1
m_Aniso: 0
m_MipBias: 0
m_WrapU: 1
m_WrapV: 1
m_WrapW: 1
m_Dimension: 2
m_VolumeDepth: 1
m_ShadowSamplingMode: 2

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d87e520225dd31c4192f2328a207f84e
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 8400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,201 +0,0 @@
step_time: 0.001
missile_configs {
missile_type: HYDRA_70
initial_state {
position {
x: 0
y: 0
z: 0
}
velocity {
x: 1e-3
y: 0
z: 2e-3
}
}
dynamic_config {
launch_config {
launch_time: 0
}
}
plotting_config {
color: BLUE
linestyle: DOTTED
marker: TRIANGLE_UP
}
submunitions_config {
num_submunitions: 7
launch_config {
launch_time: 10
}
agent_config {
missile_type: MICROMISSILE
dynamic_config {
sensor_config {
type: IDEAL
frequency: 100
}
}
plotting_config {
color: BLUE
linestyle: SOLID
marker: TRIANGLE_DOWN
}
}
}
}
missile_configs {
missile_type: HYDRA_70
initial_state {
position {
x: 0
y: 0
z: 0
}
velocity {
x: 1e-3
y: 0
z: 2e-3
}
}
dynamic_config {
launch_config {
launch_time: 0
}
}
plotting_config {
color: BLUE
linestyle: DOTTED
marker: TRIANGLE_UP
}
submunitions_config {
num_submunitions: 7
launch_config {
launch_time: 10
}
agent_config {
missile_type: MICROMISSILE
dynamic_config {
sensor_config {
type: IDEAL
frequency: 100
}
}
plotting_config {
color: BLUE
linestyle: SOLID
marker: TRIANGLE_DOWN
}
}
}
}
missile_configs {
missile_type: HYDRA_70
initial_state {
position {
x: 0
y: 10
z: 0
}
velocity {
x: 1e-3
y: 0
z: 2e-3
}
}
dynamic_config {
launch_config {
launch_time: 5
}
}
plotting_config {
color: GREEN
linestyle: DOTTED
marker: TRIANGLE_UP
}
submunitions_config {
num_submunitions: 7
launch_config {
launch_time: 10
}
agent_config {
missile_type: MICROMISSILE
dynamic_config {
sensor_config {
type: IDEAL
frequency: 100
}
}
plotting_config {
color: GREEN
linestyle: SOLID
marker: TRIANGLE_DOWN
}
}
}
}
missile_configs {
missile_type: HYDRA_70
initial_state {
position {
x: 0
y: 10
z: 0
}
velocity {
x: 1e-3
y: 0
z: 2e-3
}
}
dynamic_config {
launch_config {
launch_time: 5
}
}
plotting_config {
color: GREEN
linestyle: DOTTED
marker: TRIANGLE_UP
}
submunitions_config {
num_submunitions: 7
launch_config {
launch_time: 10
}
agent_config {
missile_type: MICROMISSILE
dynamic_config {
sensor_config {
type: IDEAL
frequency: 100
}
}
plotting_config {
color: GREEN
linestyle: SOLID
marker: TRIANGLE_DOWN
}
}
}
}
target_configs {
target_type: DRONE
initial_state {
position {
x: 10000
y: 0
z: 150
}
velocity {
x: -40
y: -20
z: 0
}
}
plotting_config {
color: RED
linestyle: SOLID
marker: SQUARE
}
}

View File

@ -310,6 +310,7 @@ QualitySettings:
Nintendo Switch: 5
PS4: 5
PS5: 5
Server: 0
Stadia: 5
Standalone: 5
WebGL: 3

View File

@ -0,0 +1,16 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &1
MonoBehaviour:
m_ObjectHideFlags: 53
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a287be6c49135cd4f9b2b8666c39d999, type: 3}
m_Name:
m_EditorClassIdentifier:
assetDefaultFramerate: 60
m_DefaultFrameRate: 60