diff --git a/Assets/PolygonPrototype/URP_ExtractMe.unitypackage.meta b/Assets/PolygonPrototype/URP_ExtractMe.unitypackage.meta new file mode 100644 index 00000000..3db8a6a1 --- /dev/null +++ b/Assets/PolygonPrototype/URP_ExtractMe.unitypackage.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 35e2ac7db1165da40aad559f01021327 +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/GameScene.unity b/Assets/Scenes/GameScene.unity index 797cbed9..dece3425 100644 --- a/Assets/Scenes/GameScene.unity +++ b/Assets/Scenes/GameScene.unity @@ -38,7 +38,7 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 0} - m_IndirectSpecularColor: {r: 0.17838746, g: 0.22335976, b: 0.30537635, a: 1} + m_IndirectSpecularColor: {r: 0.17838776, g: 0.22336027, b: 0.30537742, a: 1} m_UseRadianceAmbientProbe: 0 --- !u!157 &3 LightmapSettings: @@ -450,7 +450,7 @@ MonoBehaviour: m_EditorClassIdentifier: moveSpeed: 10 rotationSpeed: 100 - zoomAmount: 1 + zoomIncreaseAmount: 1 zoomSpeed: 1 cinemachineVirtualCamera: {fileID: 598754948} --- !u!1001 &323133488 @@ -10683,6 +10683,50 @@ PrefabInstance: m_AddedGameObjects: [] m_AddedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 1c577f9fe0c6219a992900cb942290f8, type: 3} +--- !u!1 &1835055189 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1835055191} + - component: {fileID: 1835055190} + m_Layer: 0 + m_Name: InputManager + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1835055190 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1835055189} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 6509c009d33d26763b221dd193b4ed0b, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!4 &1835055191 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1835055189} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 1 + m_Children: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1848247809 GameObject: m_ObjectHideFlags: 0 @@ -12041,3 +12085,4 @@ SceneRoots: - {fileID: 7995715121813558043} - {fileID: 2118659100} - {fileID: 361322554} + - {fileID: 1835055191} diff --git a/Assets/Scripts/Actions/UnitActionSystem.cs b/Assets/Scripts/Actions/UnitActionSystem.cs index 669dc172..f57e870f 100644 --- a/Assets/Scripts/Actions/UnitActionSystem.cs +++ b/Assets/Scripts/Actions/UnitActionSystem.cs @@ -6,11 +6,12 @@ using UnityEngine.Serialization; namespace Actions { public class UnitActionSystem : MonoBehaviour { - [FormerlySerializedAs("UnitsLayerMask")] [SerializeField] private LayerMask unitsLayerMask; - + [FormerlySerializedAs("UnitsLayerMask")] [SerializeField] + private LayerMask unitsLayerMask; + [SerializeField] private Unit selectedUnit; - private BaseAction selectedAction; private bool isBusy; + private BaseAction selectedAction; public static UnitActionSystem Instance { get; private set; } @@ -59,7 +60,7 @@ namespace Actions { } private void HandleSelectedAction() { - if (!Input.GetMouseButtonDown(0)) return; + if (!InputManager.Instance.IsMouseButtonDown(0)) return; GridPosition mouseGridPosition = LevelGrid.Instance.GetGridPosition(MouseWorld.GetPosition()); if (!SelectedAction.IsValidActionGridPosition(mouseGridPosition)) return; if (!selectedUnit.TrySpendActionPointsToTakeAction(SelectedAction)) return; @@ -78,12 +79,12 @@ namespace Actions { public event EventHandler OnActionStarted; private bool TryHandleUnitSelection() { - if (!Input.GetMouseButtonDown(0)) return false; - if (!Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out RaycastHit raycastHit, float.MaxValue, unitsLayerMask)) return false; + if (!InputManager.Instance.IsMouseButtonDown(0)) return false; + if (!Physics.Raycast(Camera.main.ScreenPointToRay(InputManager.Instance.GetMouseScreenPosition()), out RaycastHit raycastHit, float.MaxValue, unitsLayerMask)) return false; if (!raycastHit.transform.TryGetComponent(out Unit unit) || unit is null) return false; if (unit == selectedUnit) return false; if (unit.IsEnemy) return false; - + SetSelectedUnit(unit); return true; } diff --git a/Assets/Scripts/Objects/Barrel.cs b/Assets/Scripts/Barrel.cs similarity index 100% rename from Assets/Scripts/Objects/Barrel.cs rename to Assets/Scripts/Barrel.cs diff --git a/Assets/Scripts/Objects/Barrel.cs.meta b/Assets/Scripts/Barrel.cs.meta similarity index 100% rename from Assets/Scripts/Objects/Barrel.cs.meta rename to Assets/Scripts/Barrel.cs.meta diff --git a/Assets/Scripts/CameraController.cs b/Assets/Scripts/CameraController.cs index 8613f02f..1ff80239 100644 --- a/Assets/Scripts/CameraController.cs +++ b/Assets/Scripts/CameraController.cs @@ -5,11 +5,22 @@ using UnityEngine.Serialization; public class CameraController : MonoBehaviour { private const float minFollowYOffset = 2f; private const float maxFollowYOffset = 12f; - [FormerlySerializedAs("MoveSpeed")] [SerializeField] private float moveSpeed = 10f; - [FormerlySerializedAs("RotationSpeed")] [SerializeField] private float rotationSpeed = 100f; - [FormerlySerializedAs("ZoomAmount")] [SerializeField] private float zoomAmount = 1f; - [FormerlySerializedAs("ZoomSpeed")] [SerializeField] private float zoomSpeed = 5f; - [FormerlySerializedAs("CinemachineVirtualCamera")] [SerializeField] private CinemachineVirtualCamera cinemachineVirtualCamera; + + [FormerlySerializedAs("MoveSpeed")] [SerializeField] + private float moveSpeed = 10f; + + [FormerlySerializedAs("RotationSpeed")] [SerializeField] + private float rotationSpeed = 100f; + + [FormerlySerializedAs("zoomAmount")] [FormerlySerializedAs("ZoomAmount")] [SerializeField] + private float zoomIncreaseAmount = 1f; + + [FormerlySerializedAs("ZoomSpeed")] [SerializeField] + private float zoomSpeed = 5f; + + [FormerlySerializedAs("CinemachineVirtualCamera")] [SerializeField] + private CinemachineVirtualCamera cinemachineVirtualCamera; + private CinemachineTransposer cinemachineTransposer; private Vector3 targetFollowOffset; @@ -24,31 +35,17 @@ public class CameraController : MonoBehaviour { } private void HandleMovement() { - Vector3 inputMoveDir = new(); - if (Input.GetKey(KeyCode.W)) inputMoveDir.z = +1f; - if (Input.GetKey(KeyCode.S)) inputMoveDir.z = -1f; - if (Input.GetKey(KeyCode.A)) inputMoveDir.x = -1f; - if (Input.GetKey(KeyCode.D)) inputMoveDir.x = +1f; - transform.position += Time.deltaTime * moveSpeed * (transform.forward * inputMoveDir.z + transform.right * inputMoveDir.x); + Vector2 inputMoveDir = InputManager.Instance.GetCameraMoveVector(); + transform.position += Time.deltaTime * moveSpeed * (transform.forward * inputMoveDir.y + transform.right * inputMoveDir.x); } private void HandleRotation() { - Vector3 rotationVector = new(); - if (Input.GetKey(KeyCode.Q)) rotationVector.y = +1f; - if (Input.GetKey(KeyCode.E)) rotationVector.y = -1f; + Vector3 rotationVector = new() { y = InputManager.Instance.GetCameraRotateAmount() }; transform.eulerAngles += Time.deltaTime * rotationSpeed * rotationVector; } private void HandleZoom() { - switch (Input.mouseScrollDelta.y) { - case > 0: - targetFollowOffset.y -= zoomAmount; - break; - case < 0: - targetFollowOffset.y += zoomAmount; - break; - } - + targetFollowOffset.y += InputManager.Instance.GetCameraZoomAmount() * zoomIncreaseAmount; targetFollowOffset.y = Mathf.Clamp(targetFollowOffset.y, minFollowYOffset, maxFollowYOffset); cinemachineTransposer.m_FollowOffset = Vector3.Lerp(cinemachineTransposer.m_FollowOffset, targetFollowOffset, zoomSpeed * Time.deltaTime); } diff --git a/Assets/Scripts/Objects/Crate.cs b/Assets/Scripts/Crate.cs similarity index 100% rename from Assets/Scripts/Objects/Crate.cs rename to Assets/Scripts/Crate.cs diff --git a/Assets/Scripts/Objects/Crate.cs.meta b/Assets/Scripts/Crate.cs.meta similarity index 100% rename from Assets/Scripts/Objects/Crate.cs.meta rename to Assets/Scripts/Crate.cs.meta diff --git a/Assets/Scripts/Objects/Door.cs b/Assets/Scripts/Door.cs similarity index 100% rename from Assets/Scripts/Objects/Door.cs rename to Assets/Scripts/Door.cs diff --git a/Assets/Scripts/Objects/Door.cs.meta b/Assets/Scripts/Door.cs.meta similarity index 100% rename from Assets/Scripts/Objects/Door.cs.meta rename to Assets/Scripts/Door.cs.meta diff --git a/Assets/Scripts/Interfaces/IDestructable.cs b/Assets/Scripts/IDestructable.cs similarity index 100% rename from Assets/Scripts/Interfaces/IDestructable.cs rename to Assets/Scripts/IDestructable.cs diff --git a/Assets/Scripts/Interfaces/IDestructable.cs.meta b/Assets/Scripts/IDestructable.cs.meta similarity index 100% rename from Assets/Scripts/Interfaces/IDestructable.cs.meta rename to Assets/Scripts/IDestructable.cs.meta diff --git a/Assets/Scripts/Interfaces/IInteractable.cs b/Assets/Scripts/IInteractable.cs similarity index 100% rename from Assets/Scripts/Interfaces/IInteractable.cs rename to Assets/Scripts/IInteractable.cs diff --git a/Assets/Scripts/Interfaces/IInteractable.cs.meta b/Assets/Scripts/IInteractable.cs.meta similarity index 100% rename from Assets/Scripts/Interfaces/IInteractable.cs.meta rename to Assets/Scripts/IInteractable.cs.meta diff --git a/Assets/Scripts/InputManager.cs b/Assets/Scripts/InputManager.cs new file mode 100644 index 00000000..80109fe3 --- /dev/null +++ b/Assets/Scripts/InputManager.cs @@ -0,0 +1,41 @@ +using UnityEngine; + +public class InputManager : MonoBehaviour { + public static InputManager Instance { get; private set; } + + private void Awake() { + if (Instance is not null) { + Debug.LogError($"There is more than one InputManager! {transform} - {Instance}"); + Destroy(gameObject); + return; + } + + Instance = this; + } + + public Vector2 GetMouseScreenPosition() => Input.mousePosition; + public bool IsMouseButtonDown(int button) => Input.GetMouseButtonDown(button); + + public Vector2 GetCameraMoveVector() { + Vector2 inputMoveDir = new(); + if (Input.GetKey(KeyCode.W)) inputMoveDir.y = +1f; + if (Input.GetKey(KeyCode.S)) inputMoveDir.y = -1f; + if (Input.GetKey(KeyCode.A)) inputMoveDir.x = -1f; + if (Input.GetKey(KeyCode.D)) inputMoveDir.x = +1f; + return inputMoveDir; + } + + public float GetCameraRotateAmount() { + float rotateAmount = 0f; + if (Input.GetKey(KeyCode.Q)) rotateAmount = +1f; + if (Input.GetKey(KeyCode.E)) rotateAmount = -1f; + return rotateAmount; + } + + public float GetCameraZoomAmount() => + Input.mouseScrollDelta.y switch { + > 0 => -1f, + < 0 => +1f, + _ => 0f + }; +} \ No newline at end of file diff --git a/Assets/Scripts/InputManager.cs.meta b/Assets/Scripts/InputManager.cs.meta new file mode 100644 index 00000000..c2f126ab --- /dev/null +++ b/Assets/Scripts/InputManager.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 6509c009d33d26763b221dd193b4ed0b \ No newline at end of file diff --git a/Assets/Scripts/Interfaces.meta b/Assets/Scripts/Interfaces.meta deleted file mode 100644 index ef483a72..00000000 --- a/Assets/Scripts/Interfaces.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 3fff90bc61614efb8c72f30ea2a7dde0 -timeCreated: 1687177480 \ No newline at end of file diff --git a/Assets/Scripts/MouseWorld.cs b/Assets/Scripts/MouseWorld.cs index efe40806..b1a48e3a 100644 --- a/Assets/Scripts/MouseWorld.cs +++ b/Assets/Scripts/MouseWorld.cs @@ -4,12 +4,13 @@ using UnityEngine.Serialization; public class MouseWorld : MonoBehaviour { private static MouseWorld instance; - [FormerlySerializedAs("MousePlaneLayerMask")] [SerializeField] private LayerMask mousePlaneLayerMask; + [FormerlySerializedAs("MousePlaneLayerMask")] [SerializeField] + private LayerMask mousePlaneLayerMask; private void Awake() => instance = this; public static Vector3 GetPosition() { - Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); + Ray ray = Camera.main.ScreenPointToRay(InputManager.Instance.GetMouseScreenPosition()); Physics.Raycast(ray, out RaycastHit raycastHit, float.MaxValue, instance.mousePlaneLayerMask); return raycastHit.point; } diff --git a/Assets/Scripts/Objects.meta b/Assets/Scripts/Objects.meta deleted file mode 100644 index f5a60763..00000000 --- a/Assets/Scripts/Objects.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 60942cbd7232459a86ab359a808e2e92 -timeCreated: 1687177514 \ No newline at end of file diff --git a/Assets/Scripts/Testing.cs b/Assets/Scripts/Testing.cs index ad0e79cf..e49f8794 100644 --- a/Assets/Scripts/Testing.cs +++ b/Assets/Scripts/Testing.cs @@ -1,13 +1,11 @@ -using System.Collections.Generic; -using Grid; using UnityEngine; using UnityEngine.Serialization; public class Testing : MonoBehaviour { - [FormerlySerializedAs("Unit")] [SerializeField] private Unit unit; + [FormerlySerializedAs("Unit")] [SerializeField] + private Unit unit; private void Update() { - if (Input.GetKeyDown(KeyCode.T)) { - } + if (Input.GetKeyDown(KeyCode.T)) { } } } \ No newline at end of file