From 16f663ec78ebeefdbb00e2f7f17d4b4548244c58 Mon Sep 17 00:00:00 2001 From: Daniel Lovell Date: Mon, 16 Sep 2024 09:15:45 -0700 Subject: [PATCH 1/3] Work in progress refactor of InputManager, added UI structure --- Assets/Scripts/Managers.meta | 8 + Assets/Scripts/Managers/InputManager.cs | 234 +++++++++ .../{ => Managers}/InputManager.cs.meta | 0 Assets/Scripts/UI.meta | 8 + .../CameraController.cs} | 448 +++++++++++------- Assets/Scripts/UI/CameraController.cs.meta | 11 + Assets/Scripts/UI/Dialogs.meta | 8 + .../Scripts/UI/Dialogs/AgentStatusDialog.cs | 36 ++ .../UI/Dialogs/AgentStatusDialog.cs.meta | 11 + Assets/Scripts/UI/RectTransformExtensions.cs | 23 + .../UI/RectTransformExtensions.cs.meta | 11 + Assets/Scripts/UI/UIBuildButton.cs | 18 + Assets/Scripts/UI/UIBuildButton.cs.meta | 11 + Assets/Scripts/UI/UIDialog.cs | 213 +++++++++ Assets/Scripts/UI/UIDialog.cs.meta | 11 + Assets/Scripts/UI/UIElementDragger.cs | 15 + Assets/Scripts/UI/UIElementDragger.cs.meta | 11 + Assets/Scripts/UI/UIElementMouseCapturer.cs | 21 + .../Scripts/UI/UIElementMouseCapturer.cs.meta | 11 + Assets/Scripts/UI/UIManager.cs | 82 ++++ Assets/Scripts/UI/UIManager.cs.meta | 11 + Assets/Scripts/UI/UISelectableEntry.cs | 119 +++++ Assets/Scripts/UI/UISelectableEntry.cs.meta | 11 + Assets/Scripts/UI/Windows.meta | 8 + Assets/Scripts/UI/Windows/UIWindow.cs | 108 +++++ Assets/Scripts/UI/Windows/UIWindow.cs.meta | 11 + 26 files changed, 1282 insertions(+), 177 deletions(-) create mode 100644 Assets/Scripts/Managers.meta create mode 100644 Assets/Scripts/Managers/InputManager.cs rename Assets/Scripts/{ => Managers}/InputManager.cs.meta (100%) create mode 100644 Assets/Scripts/UI.meta rename Assets/Scripts/{InputManager.cs => UI/CameraController.cs} (55%) create mode 100644 Assets/Scripts/UI/CameraController.cs.meta create mode 100644 Assets/Scripts/UI/Dialogs.meta create mode 100644 Assets/Scripts/UI/Dialogs/AgentStatusDialog.cs create mode 100644 Assets/Scripts/UI/Dialogs/AgentStatusDialog.cs.meta create mode 100644 Assets/Scripts/UI/RectTransformExtensions.cs create mode 100644 Assets/Scripts/UI/RectTransformExtensions.cs.meta create mode 100644 Assets/Scripts/UI/UIBuildButton.cs create mode 100644 Assets/Scripts/UI/UIBuildButton.cs.meta create mode 100644 Assets/Scripts/UI/UIDialog.cs create mode 100644 Assets/Scripts/UI/UIDialog.cs.meta create mode 100644 Assets/Scripts/UI/UIElementDragger.cs create mode 100644 Assets/Scripts/UI/UIElementDragger.cs.meta create mode 100644 Assets/Scripts/UI/UIElementMouseCapturer.cs create mode 100644 Assets/Scripts/UI/UIElementMouseCapturer.cs.meta create mode 100644 Assets/Scripts/UI/UIManager.cs create mode 100644 Assets/Scripts/UI/UIManager.cs.meta create mode 100644 Assets/Scripts/UI/UISelectableEntry.cs create mode 100644 Assets/Scripts/UI/UISelectableEntry.cs.meta create mode 100644 Assets/Scripts/UI/Windows.meta create mode 100644 Assets/Scripts/UI/Windows/UIWindow.cs create mode 100644 Assets/Scripts/UI/Windows/UIWindow.cs.meta diff --git a/Assets/Scripts/Managers.meta b/Assets/Scripts/Managers.meta new file mode 100644 index 0000000..52062cf --- /dev/null +++ b/Assets/Scripts/Managers.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9411e01e9e0fecb45ac53c53b65fa917 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Managers/InputManager.cs b/Assets/Scripts/Managers/InputManager.cs new file mode 100644 index 0000000..c849a75 --- /dev/null +++ b/Assets/Scripts/Managers/InputManager.cs @@ -0,0 +1,234 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using System.Linq; + +public class InputManager : MonoBehaviour +{ + + public static InputManager Instance { get; private set; } + + + + public bool mouseActive = true; + [System.Serializable] + public struct CameraPreset + { + public Vector3 position; + public Quaternion rotation; + } + + public float autoplayCamSpeed = 2f; + public float xAutoRotateTime = 5f; + public float yAutoRotateTime = 5f; + private Coroutine autoplayRoutine; + + + public bool lockUserInput = false; + + private float _yaw = 0.0f; + private float _pitch = 0.0f; + + private float reloadModifier; + + private void Awake() + { + if (Instance == null) { + Instance = this; + DontDestroyOnLoad(gameObject); + } else { + Destroy(gameObject); + } + } + + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + HandleInput(); + } + + + + private void HandleMouseInput() + { + if (Input.GetMouseButton(0)) + { + CameraController.Instance.OrbitCamera(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y")); + + } + else if (Input.GetMouseButton(1)) + { + CameraController.Instance.RotateCamera(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y")); + } + } + + + private void HandleInput() + { + if (!lockUserInput) + { + HandleLockableInput(); + } + HandleNonLockableInput(); + } + + void HandleScrollWheelInput() + { + if (Input.GetAxis("Mouse ScrollWheel") != 0) + { + CameraController.Instance.ZoomCamera(Input.GetAxis("Mouse ScrollWheel") * 500); + } + } + + void HandleLockableInput() + { + + HandleMouseInput(); + if (Input.GetKey(KeyCode.LeftShift)) + { + reloadModifier = -.1f; + _cameraSpeed = _cameraSpeedMax; + } + else + { + reloadModifier = .1f; + _cameraSpeed = _cameraSpeedNormal; + } + + // TRANSLATIONAL MOVEMENT + if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)) + { + CameraController.Instance.TranslateCamera(CameraController.TranslationInput.Forward); + } + if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)) + { + CameraController.Instance.TranslateCamera(CameraController.TranslationInput.Left); + } + if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow)) + { + CameraController.Instance.TranslateCamera(CameraController.TranslationInput.Back); + } + if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)) + { + CameraController.Instance.TranslateCamera(CameraController.TranslationInput.Right); + } + if (Input.GetKey(KeyCode.Q)) + { + CameraController.Instance.TranslateCamera(CameraController.TranslationInput.Up); + } + if (Input.GetKey(KeyCode.E)) + { + CameraController.Instance.TranslateCamera(CameraController.TranslationInput.Down); + } + + } + + void HandleNonLockableInput() + { + HandleScrollWheelInput(); + if (Input.GetKeyDown(KeyCode.I)) + + + if (Input.GetKeyDown(KeyCode.C)) + { + + } + + if (Input.GetKeyDown(KeyCode.Space)) + { + // Pause the time + if (SimManager.Instance.IsSimulationRunning()) { + SimManager.Instance.PauseSimulation(); + } else { + SimManager.Instance.ResumeSimulation(); + } + } + + if (Input.GetKeyDown(KeyCode.P)) + { + autoRotate = !autoRotate; + if (autoRotate) + { + autoplayRoutine = StartCoroutine(AutoPlayRoutine()); + } + else + { + StopCoroutine( autoplayRoutine ); + } + } + + if (Input.GetKeyDown(KeyCode.Alpha1)) + { + // ORIGIN + transform.position = new Vector3(0, 20, -20); + SetCameraRotation(Quaternion.Euler(24f, -0.5f, 0)); + Camera.main.fieldOfView = 45f; + ResetCameraTarget(); + } + + if (Input.GetKeyDown(KeyCode.Alpha2)) + { + transform.position = new Vector3(0, 30, -20); + SetCameraRotation(Quaternion.Euler(36.6f, -0.5f, 0)); + Camera.main.fieldOfView = 60f; + ResetCameraTarget(); + + } + + + if (Input.GetKeyDown(KeyCode.Alpha4)) + { + if (Input.GetKey(KeyCode.LeftShift)) + { + fourPos.position = transform.position; + fourPos.rotation = transform.rotation; + } + else + { + transform.position = fourPos.position; + SetCameraRotation(fourPos.rotation); + ResetCameraTarget(); + } + + } + + if (Input.GetKeyDown(KeyCode.Alpha5)) + { + if (Input.GetKey(KeyCode.LeftShift)) + { + fivePos.position = transform.position; + fivePos.rotation = transform.rotation; + } + else + { + transform.position = fivePos.position; + SetCameraRotation(fivePos.rotation); + ResetCameraTarget(); + } + } + + if (Input.GetKeyDown(KeyCode.Alpha6)) + { + if (Input.GetKey(KeyCode.LeftShift)) + { + sixPos.position = transform.position; + sixPos.rotation = transform.rotation; + } + else + { + transform.position = sixPos.position; + SetCameraRotation(sixPos.rotation); + ResetCameraTarget(); + } + } + + + } + +} diff --git a/Assets/Scripts/InputManager.cs.meta b/Assets/Scripts/Managers/InputManager.cs.meta similarity index 100% rename from Assets/Scripts/InputManager.cs.meta rename to Assets/Scripts/Managers/InputManager.cs.meta diff --git a/Assets/Scripts/UI.meta b/Assets/Scripts/UI.meta new file mode 100644 index 0000000..146c7c1 --- /dev/null +++ b/Assets/Scripts/UI.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c17270294c7dd6d45b8731a468423a83 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/InputManager.cs b/Assets/Scripts/UI/CameraController.cs similarity index 55% rename from Assets/Scripts/InputManager.cs rename to Assets/Scripts/UI/CameraController.cs index 180319f..059a82f 100644 --- a/Assets/Scripts/InputManager.cs +++ b/Assets/Scripts/UI/CameraController.cs @@ -1,16 +1,179 @@ -using System.Collections; +using System.Collections; using System.Collections.Generic; using UnityEngine; -using System.Linq; -public class InputManager : MonoBehaviour +public class CameraController : MonoBehaviour { + #region Singleton - public static InputManager Instance { get; private set; } + /// + /// Singleton instance of the CameraController. + /// + public static CameraController Instance { get; private set; } - + #endregion + #region Camera Settings + + /// + /// Determines if mouse input is active for camera control. + /// public bool mouseActive = true; + + /// + /// Locks user input for camera control. + /// + public bool lockUserInput = false; + + /// + /// Normal speed of camera movement. + /// + [SerializeField] private float _cameraSpeedNormal = 100.0f; + + /// + /// Maximum speed of camera movement. + /// + [SerializeField] private float _cameraSpeedMax = 1000.0f; + + /// + /// Current speed of camera movement. + /// + private float _cameraSpeed; + + /// + /// Horizontal rotation speed. + /// + public float _speedH = 2.0f; + + /// + /// Vertical rotation speed. + /// + public float _speedV = 2.0f; + + /// + /// Current yaw angle of the camera. + /// + private float _yaw = 0.0f; + + /// + /// Current pitch angle of the camera. + /// + private float _pitch = 0.0f; + + #endregion + + #region Orbit Settings + + /// + /// Determines if the camera should auto-rotate. + /// + public bool autoRotate = false; + + /// + /// Target transform for orbit rotation. + /// + public Transform target; + + /// + /// Distance from the camera to the orbit target. + /// + [SerializeField] private float _orbitDistance = 5.0f; + + /// + /// Horizontal orbit rotation speed. + /// + [SerializeField] private float _orbitXSpeed = 120.0f; + + /// + /// Vertical orbit rotation speed. + /// + [SerializeField] private float _orbitYSpeed = 120.0f; + + /// + /// Speed of camera zoom. + /// + [SerializeField] private float _zoomSpeed = 500.0f; + + /// + /// Minimum vertical angle limit for orbit. + /// + public float orbitYMinLimit = -20f; + + /// + /// Maximum vertical angle limit for orbit. + /// + public float orbitYMaxLimit = 80f; + + /// + /// Minimum distance for orbit. + /// + private float _orbitDistanceMin = 10f; + + /// + /// Maximum distance for orbit. + /// + private float _orbitDistanceMax = 10000f; + + /// + /// Current horizontal orbit angle. + /// + private float _orbitX = 0.0f; + + /// + /// Current vertical orbit angle. + /// + private float _orbitY = 0.0f; + + #endregion + + #region Rendering + + /// + /// Renderer for the orbit target. + /// + public Renderer targetRenderer; + + /// + /// Renderer for the floor. + /// + public Renderer floorRenderer; + + /// + /// Alpha value for material transparency. + /// + public float matAlpha; + + #endregion + + #region Autoplay Settings + + /// + /// Speed of camera movement during autoplay. + /// + public float autoplayCamSpeed = 2f; + + /// + /// Duration of horizontal auto-rotation. + /// + public float xAutoRotateTime = 5f; + + /// + /// Duration of vertical auto-rotation. + /// + public float yAutoRotateTime = 5f; + + /// + /// Coroutine for autoplay functionality. + /// + private Coroutine autoplayRoutine; + + #endregion + + #region Camera Presets + + /// + /// Represents a preset camera position and rotation. + /// [System.Serializable] public struct CameraPreset { @@ -18,60 +181,57 @@ public class InputManager : MonoBehaviour public Quaternion rotation; } - public float autoplayCamSpeed = 2f; - public float xAutoRotateTime = 5f; - public float yAutoRotateTime = 5f; - private Coroutine autoplayRoutine; - - - public bool lockUserInput = false; - - private float _cameraSpeed; - public float _cameraSpeedNormal = 5.0f; - public float _cameraSpeedMax = 10.0f; - - public float _speedH = 2.0f; - public float _speedV = 2.0f; - - private float _yaw = 0.0f; - private float _pitch = 0.0f; - - private float reloadModifier; - - // Orbit controller - public bool autoRotate = false; - - public Transform target; - public Renderer targetRenderer; - public Renderer floorRenderer; - public float matAlpha; - public float orbitDistance = 5.0f; - public float orbitXSpeed = 120.0f; - public float orbitYSpeed = 120.0f; - - public float orbitYMinLimit = -20f; - public float orbitYMaxLimit = 80f; - - public float orbitDistanceMin = .5f; - public float orbitDistanceMax = 15f; - - private Rigidbody _rigidbody; - - float x = 0.0f; - float y = 0.0f; - - + /// + /// Preset camera position for key 4. + /// CameraPreset fourPos = new CameraPreset(); + + /// + /// Preset camera position for key 5. + /// CameraPreset fivePos = new CameraPreset(); + + /// + /// Preset camera position for key 6. + /// CameraPreset sixPos = new CameraPreset(); + #endregion + + #region Movement + + /// + /// Mapping of translation inputs to movement vectors. + /// + private Dictionary _translationInputToVectorMap; + + /// + /// Forward movement vector. + /// Vector3 wVector = Vector3.forward; + + /// + /// Left movement vector. + /// Vector3 aVector = Vector3.left; + + /// + /// Backward movement vector. + /// Vector3 sVector = Vector3.back; + + /// + /// Right movement vector. + /// Vector3 dVector = Vector3.right; + /// + /// Angle between forward vector and camera direction. + /// public float forwardToCameraAngle; + #endregion + void SetCameraRotation(Quaternion rotation) { transform.rotation = rotation; @@ -96,6 +256,15 @@ public class InputManager : MonoBehaviour } else { Destroy(gameObject); } + + _translationInputToVectorMap = new Dictionary { + {TranslationInput.Forward, wVector}, + {TranslationInput.Left, aVector}, + {TranslationInput.Back, sVector}, + {TranslationInput.Right, dVector}, + {TranslationInput.Up, Vector3.up}, + {TranslationInput.Down, Vector3.down} + }; } // Start is called before the first frame update @@ -109,18 +278,12 @@ public class InputManager : MonoBehaviour sixPos.rotation = Quaternion.Euler(0, 0, 0); Vector3 angles = transform.eulerAngles; - x = angles.y; - y = angles.x; + _orbitX = angles.y; + _orbitY = angles.x; UpdateTargetAlpha(); } - // Update is called once per frame - void Update() - { - HandleInput(); - } - IEnumerator AutoPlayRoutine() { while (true) @@ -128,32 +291,32 @@ public class InputManager : MonoBehaviour float elapsedTime = 0f; while (elapsedTime <= xAutoRotateTime) { - x += Time.unscaledDeltaTime * autoplayCamSpeed * orbitDistance * 0.02f; - UpdateCamPosition(); + _orbitX += Time.unscaledDeltaTime * autoplayCamSpeed * _orbitDistance * 0.02f; + UpdateCamPosition(_orbitX, _orbitY); elapsedTime += Time.unscaledDeltaTime; yield return null; } elapsedTime = 0f; while (elapsedTime <= yAutoRotateTime) { - y -= Time.unscaledDeltaTime * autoplayCamSpeed * orbitDistance * 0.02f; - UpdateCamPosition(); + _orbitY -= Time.unscaledDeltaTime * autoplayCamSpeed * _orbitDistance * 0.02f; + UpdateCamPosition(_orbitX, _orbitY); elapsedTime += Time.unscaledDeltaTime; yield return null; } elapsedTime = 0f; while (elapsedTime <= xAutoRotateTime) { - x -= Time.unscaledDeltaTime * autoplayCamSpeed * orbitDistance * 0.02f; - UpdateCamPosition(); + _orbitX -= Time.unscaledDeltaTime * autoplayCamSpeed * _orbitDistance * 0.02f; + UpdateCamPosition(_orbitX, _orbitY); elapsedTime += Time.unscaledDeltaTime; yield return null; } elapsedTime = 0f; while (elapsedTime <= yAutoRotateTime) { - y += Time.unscaledDeltaTime * autoplayCamSpeed * orbitDistance * 0.02f; - UpdateCamPosition(); + _orbitY += Time.unscaledDeltaTime * autoplayCamSpeed * _orbitDistance * 0.02f; + UpdateCamPosition(_orbitX, _orbitY); elapsedTime += Time.unscaledDeltaTime; yield return null; } @@ -167,19 +330,19 @@ public class InputManager : MonoBehaviour if(Physics.Raycast(transform.position, transform.forward, out hit, float.MaxValue, LayerMask.GetMask("Floor"), QueryTriggerInteraction.Ignore)) { target.transform.position = hit.point; - orbitDistance = hit.distance; + _orbitDistance = hit.distance; Vector3 angles = transform.eulerAngles; - x = angles.y; - y = angles.x; - UpdateCamPosition(); + _orbitX = angles.y; + _orbitY = angles.x; + UpdateCamPosition(_orbitX, _orbitY); } else { target.transform.position = transform.position + (transform.forward * 100); - orbitDistance = 100; + _orbitDistance = 100; Vector3 angles = transform.eulerAngles; - x = angles.y; - y = angles.x; + _orbitX = angles.y; + _orbitY = angles.x; //UpdateCamPosition(); } } @@ -188,44 +351,34 @@ public class InputManager : MonoBehaviour public void EnableFloorGridRenderer(bool enable) { floorRenderer.enabled = enable; } - private void HandleMouseInput() - { - // Orbit + + public void OrbitCamera(float xOrbit, float yOrbit) { if (target) { - if (Input.GetMouseButton(0)) - { - x += Input.GetAxis("Mouse X") * orbitXSpeed * orbitDistance * 0.02f; - y -= Input.GetAxis("Mouse Y") * orbitYSpeed * orbitDistance * 0.02f; - - y = ClampAngle(y, orbitYMinLimit, orbitYMaxLimit); - UpdateCamPosition(); - - } - // Rotate - else if (Input.GetMouseButton(1)) - { - _yaw += _speedH * Input.GetAxis("Mouse X"); - _pitch -= _speedV * Input.GetAxis("Mouse Y"); - - transform.eulerAngles = new Vector3(_pitch, _yaw, 0.0f); - } + _orbitX += xOrbit * _orbitXSpeed * _orbitDistance * 0.02f; + _orbitY -= yOrbit * _orbitYSpeed * _orbitDistance * 0.02f; + _orbitY = ClampAngle(_orbitY, orbitYMinLimit, orbitYMaxLimit); + UpdateCamPosition(_orbitX, _orbitY); } - - } - private void UpdateCamPosition() + public void RotateCamera(float xRotate, float yRotate) { + _yaw += xRotate * _speedH; + _pitch -= yRotate * _speedV; + transform.eulerAngles = new Vector3(_pitch, _yaw, 0.0f); + } + + private void UpdateCamPosition(float x, float y) { Quaternion rotation = Quaternion.Euler(y, x, 0); RaycastHit hit; //Debug.DrawLine(target.position, transform.position, Color.red); if (Physics.Linecast(target.position, transform.position, out hit, ~LayerMask.GetMask("Floor"), QueryTriggerInteraction.Ignore)) { - orbitDistance -= hit.distance; + _orbitDistance -= hit.distance; } - Vector3 negDistance = new Vector3(0.0f, 0.0f, -orbitDistance); + Vector3 negDistance = new Vector3(0.0f, 0.0f, -_orbitDistance); Vector3 position = rotation * negDistance + target.position; UpdateTargetAlpha(); @@ -233,27 +386,16 @@ public class InputManager : MonoBehaviour transform.position = position; } - private void HandleInput() - { - if (!lockUserInput) - { - HandleLockableInput(); - } - HandleNonLockableInput(); - } - void HandleScrollWheelInput() + public void ZoomCamera(float zoom) { - if (Input.GetAxis("Mouse ScrollWheel") != 0) - { - orbitDistance = Mathf.Clamp(orbitDistance - Input.GetAxis("Mouse ScrollWheel") * 500, orbitDistanceMin, orbitDistanceMax); - UpdateCamPosition(); - } + _orbitDistance = Mathf.Clamp(_orbitDistance - zoom * _zoomSpeed, _orbitDistanceMin, _orbitDistanceMax); + UpdateCamPosition(_orbitX, _orbitY); } void UpdateTargetAlpha() { - matAlpha = (orbitDistance - orbitDistanceMin) / (orbitDistanceMax - orbitDistanceMin); + matAlpha = (_orbitDistance - _orbitDistanceMin) / (_orbitDistanceMax - _orbitDistanceMin); matAlpha = Mathf.Max(Mathf.Sqrt(matAlpha) - 0.5f, 0); Color matColor = targetRenderer.material.color; matColor.a = matAlpha; @@ -297,88 +439,40 @@ public class InputManager : MonoBehaviour } + public enum TranslationInput { + Forward, + Left, + Back, + Right, + Up, + Down + } + + + + public void TranslateCamera(TranslationInput input) { + UpdateDirectionVectors(); + target.Translate(_translationInputToVectorMap[input] * Time.unscaledDeltaTime * _cameraSpeed); + UpdateCamPosition(_orbitX, _orbitY); + } + void HandleLockableInput() { - HandleMouseInput(); if (Input.GetKey(KeyCode.LeftShift)) { - reloadModifier = -.1f; _cameraSpeed = _cameraSpeedMax; } else { - reloadModifier = .1f; _cameraSpeed = _cameraSpeedNormal; } - // TRANSLATIONAL MOVEMENT - if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)) - { - UpdateDirectionVectors(); - //transform.Translate(Vector3.forward * Time.deltaTime * _cameraSpeed); - target.Translate(wVector * Time.unscaledDeltaTime * _cameraSpeed); - UpdateCamPosition(); - } - if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)) - { - UpdateDirectionVectors(); - //transform.Translate(Vector3.left * Time.deltaTime * _cameraSpeed); - target.Translate(aVector * Time.unscaledDeltaTime * _cameraSpeed); - UpdateCamPosition(); - } - if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow)) - { - UpdateDirectionVectors(); - //transform.Translate(Vector3.back * Time.deltaTime * _cameraSpeed); - target.Translate(sVector * Time.unscaledDeltaTime * _cameraSpeed); - UpdateCamPosition(); - } - if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)) - { - UpdateDirectionVectors(); - //transform.Translate(Vector3.right * Time.deltaTime * _cameraSpeed); - target.Translate(dVector * Time.unscaledDeltaTime * _cameraSpeed); - UpdateCamPosition(); - } - if (Input.GetKey(KeyCode.Q)) - { - //transform.Translate(Vector3.up * Time.deltaTime * _cameraSpeed); - target.Translate(Vector3.up * Time.unscaledDeltaTime * _cameraSpeed); - - UpdateCamPosition(); - } - if (Input.GetKey(KeyCode.E)) - { - //transform.Translate(Vector3.down * Time.deltaTime * _cameraSpeed); - target.Translate(Vector3.down * Time.unscaledDeltaTime * _cameraSpeed); - - UpdateCamPosition(); - } - + } void HandleNonLockableInput() { - HandleScrollWheelInput(); - if (Input.GetKeyDown(KeyCode.I)) - - - if (Input.GetKeyDown(KeyCode.C)) - { - - } - - if (Input.GetKeyDown(KeyCode.Space)) - { - // Pause the time - if (SimManager.Instance.IsSimulationRunning()) { - SimManager.Instance.PauseSimulation(); - } else { - SimManager.Instance.ResumeSimulation(); - } - } - if (Input.GetKeyDown(KeyCode.P)) { autoRotate = !autoRotate; diff --git a/Assets/Scripts/UI/CameraController.cs.meta b/Assets/Scripts/UI/CameraController.cs.meta new file mode 100644 index 0000000..b5d307d --- /dev/null +++ b/Assets/Scripts/UI/CameraController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b9e222cf9df32df4196f08036d68d740 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/UI/Dialogs.meta b/Assets/Scripts/UI/Dialogs.meta new file mode 100644 index 0000000..e2446ca --- /dev/null +++ b/Assets/Scripts/UI/Dialogs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 27829404610ae9a479fd6f44c6da81ca +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/UI/Dialogs/AgentStatusDialog.cs b/Assets/Scripts/UI/Dialogs/AgentStatusDialog.cs new file mode 100644 index 0000000..224a330 --- /dev/null +++ b/Assets/Scripts/UI/Dialogs/AgentStatusDialog.cs @@ -0,0 +1,36 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class BotStatusDialog : UIDialog +{ + // Start is called before the first frame update + public override void Start() + { + base.Start(); + + + UISelectableEntry missiles = CreateSelectableEntry(); + missiles.SetTextContent(new List(new string[] { "Missiles" })); + missiles.SetIsSelectable(false); + + UISelectableEntry submunitions = CreateSelectableEntry(); + submunitions.SetTextContent(new List(new string[] { "Submunitions" })); + submunitions.SetIsSelectable(false); + + UISelectableEntry targets = CreateSelectableEntry(); + targets.SetTextContent(new List(new string[] { "Targets" })); + targets.SetIsSelectable(false); + + SetDialogEntries(new List(new UISelectableEntry[] { missiles, submunitions, targets })); + + AddDialogTab("All", () => { }); + + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/Assets/Scripts/UI/Dialogs/AgentStatusDialog.cs.meta b/Assets/Scripts/UI/Dialogs/AgentStatusDialog.cs.meta new file mode 100644 index 0000000..cfa323d --- /dev/null +++ b/Assets/Scripts/UI/Dialogs/AgentStatusDialog.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a404f59a5c2ba814a9c1ca121b596df9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/UI/RectTransformExtensions.cs b/Assets/Scripts/UI/RectTransformExtensions.cs new file mode 100644 index 0000000..b68ddc5 --- /dev/null +++ b/Assets/Scripts/UI/RectTransformExtensions.cs @@ -0,0 +1,23 @@ + using UnityEngine; + public static class RectTransformExtensions + { + public static void SetLeft(this RectTransform rt, float left) + { + rt.offsetMin = new Vector2(left, rt.offsetMin.y); + } + + public static void SetRight(this RectTransform rt, float right) + { + rt.offsetMax = new Vector2(-right, rt.offsetMax.y); + } + + public static void SetTop(this RectTransform rt, float top) + { + rt.offsetMax = new Vector2(rt.offsetMax.x, -top); + } + + public static void SetBottom(this RectTransform rt, float bottom) + { + rt.offsetMin = new Vector2(rt.offsetMin.x, bottom); + } + } \ No newline at end of file diff --git a/Assets/Scripts/UI/RectTransformExtensions.cs.meta b/Assets/Scripts/UI/RectTransformExtensions.cs.meta new file mode 100644 index 0000000..1d18e42 --- /dev/null +++ b/Assets/Scripts/UI/RectTransformExtensions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c991d4191b4586742a5d8dfc8ece23bb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/UI/UIBuildButton.cs b/Assets/Scripts/UI/UIBuildButton.cs new file mode 100644 index 0000000..88b4745 --- /dev/null +++ b/Assets/Scripts/UI/UIBuildButton.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class UIBuildButton : MonoBehaviour +{ + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/Assets/Scripts/UI/UIBuildButton.cs.meta b/Assets/Scripts/UI/UIBuildButton.cs.meta new file mode 100644 index 0000000..cd65090 --- /dev/null +++ b/Assets/Scripts/UI/UIBuildButton.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 56ea3cedd2ebcbc42a98ea19ebc61632 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/UI/UIDialog.cs b/Assets/Scripts/UI/UIDialog.cs new file mode 100644 index 0000000..da53a3c --- /dev/null +++ b/Assets/Scripts/UI/UIDialog.cs @@ -0,0 +1,213 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using TMPro; +using System; +using UnityEngine.UI; + +public class UIDialog : MonoBehaviour +{ + [SerializeField] + private string dialogTitle; + + [SerializeField] + private TextMeshProUGUI dialogTitleHandle; + [SerializeField] + private RectTransform contentHandle; + + /// TABS + [SerializeField] + private float tabWidth = 50f; + [SerializeField] + private float tabHeight = 16f; + // List of dialog tabs + private List dialogTabs; + + /// ENTRIES + private List entries; + + private float entryHeight = 20f; + private float entryIndentWidth= 10f; + + private List cleanupPool; + + + private bool isOpen; + + + + + // Start is called before the first frame update + public virtual void Start() + { + dialogTitleHandle.text = dialogTitle; + dialogTitleHandle.font = UIManager.Instance.Font; + isOpen = gameObject.activeSelf; + dialogTabs = new List(); + entries = new List(); + cleanupPool = new List(); + } + + internal RectTransform GetContentHandle() + { + return contentHandle; + } + + public bool IsOpen() + { + return isOpen; + } + + protected virtual void OnEnable() { isOpen = true; } + protected virtual void OnDisable() { isOpen = false; } + + public float GetTabWidth() { return tabWidth; } + public float GetTabHeight() { return tabHeight; } + + /// + /// Returns the height of the dialog title bar + /// + public float GetTitleBarHeight() { return dialogTitleHandle.rectTransform.sizeDelta.y; } + + /// + /// Adds a new tab to the dialog, when clicked it will call the given callback + /// + public void AddDialogTab(string tabName, Action onClick) + { + dialogTabs.Add(AddTabButton(tabName, onClick)); + } + + /// + /// Add the tab button to the right of the existing tabs + /// + private GameObject AddTabButton(string tabName, Action onClick) + { + GameObject tabButton = new GameObject("TabButton", typeof(RectTransform)); + tabButton.transform.SetParent(transform); // worldPositionStays ? + // RectTransform anchors to the right of the content handle + RectTransform rTransform = tabButton.GetComponent(); + rTransform.anchorMin = new Vector2(0, 1); + rTransform.anchorMax = new Vector2(0, 1); + rTransform.pivot = new Vector2(0, 1); + rTransform.sizeDelta = new Vector2(tabWidth, tabHeight); + // Count tabs * tabSize to get the position from the left + rTransform.anchoredPosition = new Vector2(tabWidth * dialogTabs.Count, -(GetTitleBarHeight())); + + // Add the onClick callback to the button + Button button = tabButton.AddComponent