Better input and UI control, low FOV render
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user