diff --git a/Assets/Prefabs/Base/Base.prefab b/Assets/Prefabs/Base/Base.prefab index c1b19655..971cb335 100644 --- a/Assets/Prefabs/Base/Base.prefab +++ b/Assets/Prefabs/Base/Base.prefab @@ -271,9 +271,14 @@ MonoBehaviour: m_EditorClassIdentifier: gameOverScreen: {fileID: 6406541465688870762, guid: cf6616ecfd76d4b379c4e4fd196293af, type: 3} destroyedBase: {fileID: 7907768064546073796, guid: ced5130962de4c54185e3ca432063c03, type: 3} + distortionField: {fileID: 0} + deathParticles: {fileID: 0} spawnPoint: {fileID: 5829545455071137389} crystals: 0 drainRay: {fileID: 2977432110045038679, guid: 1fa3e9df0696ada43b1fbfe045184210, type: 3} + explosionLightningCount: 20 + explosionLightningSpawnDelay: 0.2 + mainCrystal: {fileID: 0} --- !u!114 &990519977 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/Prefabs/PlayerControls.inputactions b/Assets/Prefabs/PlayerControls.inputactions index 372a6c19..ff8f3a28 100644 --- a/Assets/Prefabs/PlayerControls.inputactions +++ b/Assets/Prefabs/PlayerControls.inputactions @@ -30,7 +30,7 @@ "interactions": "" }, { - "name": "Back", + "name": "Cancel", "type": "Button", "id": "edbb2489-0819-43dd-bbbf-39f2ad7c7800", "expectedControlType": "Button", @@ -238,18 +238,18 @@ "interactions": "", "processors": "", "groups": "Controller", - "action": "Back", + "action": "Cancel", "isComposite": false, "isPartOfComposite": false }, { "name": "", "id": "eeed5e82-f945-41b1-924f-37ce63a89e81", - "path": "/f", + "path": "/escape", "interactions": "", "processors": "", "groups": "Keyboard", - "action": "Back", + "action": "Cancel", "isComposite": false, "isPartOfComposite": false }, diff --git a/Assets/Prefabs/Players/Dahl_Player.prefab b/Assets/Prefabs/Players/Dahl_Player.prefab index 5eadd28c..468bb36e 100644 --- a/Assets/Prefabs/Players/Dahl_Player.prefab +++ b/Assets/Prefabs/Players/Dahl_Player.prefab @@ -1145,7 +1145,7 @@ MonoBehaviour: m_EditorClassIdentifier: inventory: {fileID: 2599837699652063204} anim: {fileID: 6367115686714045310} - HeldItemBone: {fileID: 7197418879628508991} + heldItemBone: {fileID: 7197418879628508991} --- !u!114 &2954308745039272254 MonoBehaviour: m_ObjectHideFlags: 0 @@ -1201,8 +1201,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: e72ff79698f208146b466f2fe5707f24, type: 3} m_Name: m_EditorClassIdentifier: - Crate: {fileID: 4550191380729392189} - Blueprint: {fileID: 3550879455986713352} + crate: {fileID: 4550191380729392189} + blueprint: {fileID: 3550879455986713352} --- !u!1 &4138943945869748027 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/GameState/BaseController.cs b/Assets/Scripts/GameState/BaseController.cs index a5e5282e..cbe913e3 100644 --- a/Assets/Scripts/GameState/BaseController.cs +++ b/Assets/Scripts/GameState/BaseController.cs @@ -40,6 +40,9 @@ public class BaseController : MonoBehaviour public GameObject drainRay; private List rays = new List(); + public int explosionLightningCount = 20; + public float explosionLightningSpawnDelay = 0.2f; + public Transform SpawnPoint => spawnPoint; // Crystal Transform @@ -68,10 +71,8 @@ void Awake() GetComponent().onDeath += Die; anim = GetComponent(); - if(mainCrystal == null) - { + if (mainCrystal == null) Debug.LogError("Main Crystal not set."); - } } void OnDestroy() @@ -128,9 +129,7 @@ private void Die() StartCoroutine("Explode"); // Start Distortions - //distortionField.enabled = true; - - + //distortionField.enabled = true; } dead = true; @@ -181,32 +180,31 @@ public int GetIdVFX(Transform t) IEnumerator Explode() { // Get a list of all transforms (lighning targets) - Transform[] transforms = GameObject.FindObjectsOfType(); + Transform[] transforms = FindObjectsOfType(); // Create lightning as the crystal charges - for (float t = 4f; t >= 0; t -= 0.2f) + for (int _ = 0; _ >= explosionLightningCount; _++) { - int i = Random.Range(0, transforms.Length); - - Transform ray = Instantiate(drainRay, transform.position + new Vector3(Random.Range(-1, 1), 5f, Random.Range(-1, 1)), transform.rotation).transform; - ray.SetParent(transform); + Vector3 rayPos = transform.position + new Vector3(Random.Range(-1, 1), 5f, Random.Range(-1, 1)); + Transform ray = Instantiate(drainRay, rayPos, transform.rotation, transform).transform; // 1 is the index of the first child (after the parent itself) Transform target = ray.GetComponentsInChildren()[1]; - target.SetParent(transforms[i]); + Transform randomLightningTarget = transforms[Random.Range(0, transforms.Length)]; + target.SetParent(randomLightningTarget); target.localPosition = Vector3.zero; // Ensure correct camera focus Camera.main.GetComponent().Focus(transform); - yield return new WaitForSeconds(0.2f); + yield return new WaitForSeconds(explosionLightningSpawnDelay); } // Replace the base with a rigidbody based one GameObject deadBase = Instantiate(destroyedBase, transform.position, Quaternion.identity); // Add an explosion force on the base - foreach(Rigidbody rb in deadBase.GetComponentsInChildren()) + foreach (Rigidbody rb in deadBase.GetComponentsInChildren()) { rb.AddForce(new Vector3(Random.Range(-250f, 250f), Random.Range(500f, 800f), Random.Range(-250f, 250f))); } @@ -218,7 +216,7 @@ IEnumerator Explode() Instantiate(gameOverScreen); // Add particle system - Instantiate(deathParticles, transform.position + new Vector3(0,3,0), transform.rotation); + Instantiate(deathParticles, transform.position + new Vector3(0, 3, 0), transform.rotation); // Clean up Destroy(gameObject); diff --git a/Assets/Scripts/Interactables/Interactable.cs b/Assets/Scripts/Interactables/Interactable.cs index bb7c0281..06826335 100644 --- a/Assets/Scripts/Interactables/Interactable.cs +++ b/Assets/Scripts/Interactables/Interactable.cs @@ -2,22 +2,15 @@ using System.Collections.Generic; using UnityEngine; -public class Interactable : MonoBehaviour +public abstract class Interactable : MonoBehaviour { public bool canInteract = true; public virtual void Focus(PlayerStateController player) - { - Debug.Log("I am focused"); - } + {} public virtual void Unfocus(PlayerStateController player) - { - Debug.Log("I am unfocused (Aren't we all?)"); - } + {} - public virtual void Interact(PlayerStateController player) - { - Debug.Log("Player interacted"); - } + public abstract void Interact(PlayerStateController player); } diff --git a/Assets/Scripts/Interactables/Loot.cs b/Assets/Scripts/Interactables/Loot.cs index 234a163d..ff3ae7d3 100644 --- a/Assets/Scripts/Interactables/Loot.cs +++ b/Assets/Scripts/Interactables/Loot.cs @@ -85,6 +85,16 @@ void Update() } } + public override void Focus(PlayerStateController player) + { + Highlight(); + } + + public override void Unfocus(PlayerStateController player) + { + Unhighlight(); + } + public override void Interact(PlayerStateController player) { if (!carried) @@ -105,16 +115,6 @@ public override void Interact(PlayerStateController player) } } - public override void Focus(PlayerStateController player) - { - Highlight(); - } - - public override void Unfocus(PlayerStateController player) - { - Unhighlight(); - } - public void Absorb(BaseController baseController) { // Set the object to be destroyed diff --git a/Assets/Scripts/Player/CameraFocusController.cs b/Assets/Scripts/Player/CameraFocusController.cs index 91762652..9a4d5398 100644 --- a/Assets/Scripts/Player/CameraFocusController.cs +++ b/Assets/Scripts/Player/CameraFocusController.cs @@ -77,13 +77,10 @@ private Vector3 boundingBoxCenter() //Taking the mean sqare avg of the mindistance and box distance if (!overview) - { distance = Mathf.Sqrt(radialDist * radialDist + minDistance * minDistance); - } else - { distance = Mathf.Sqrt(radialDist * radialDist + overviewDistance * overviewDistance); - } + return center + distance * viewDir; } @@ -109,7 +106,6 @@ public void Focus(Transform obj) // Switch to overview mode EnableOverview(); - } public void EnableOverview() @@ -117,7 +113,7 @@ public void EnableOverview() if (!overview) { overview = true; - smoothing = smoothing / 10; + smoothing /= 10; } } } diff --git a/Assets/Scripts/Player/DahlPropController.cs b/Assets/Scripts/Player/DahlPropController.cs index 815e8795..6da7bf01 100644 --- a/Assets/Scripts/Player/DahlPropController.cs +++ b/Assets/Scripts/Player/DahlPropController.cs @@ -3,31 +3,36 @@ using UnityEngine; /// -/// Component made for updating dahls props when states are changed. Latches on to playerStateContollers onStateChange delegate to enable/disabled the crate and blueprints +/// Component made for updating Dahl's props when states are changed. +/// Latches on to `PlayerStateContoller`s `onPlayerStateChange` delegate to enable/disabled the crate and blueprints. /// public class DahlPropController : MonoBehaviour { + [SerializeField] + private MeshRenderer crate; [SerializeField] - private MeshRenderer Crate, Blueprint; + private MeshRenderer blueprint; + void Start() { - GetComponent().onPlayerStateChange += onPlayerStateChange; + GetComponent().onPlayerStateChange += OnPlayerStateChange; } - private void OnDestroy() + + void OnDestroy() { - GetComponent().onPlayerStateChange -= onPlayerStateChange; + GetComponent().onPlayerStateChange -= OnPlayerStateChange; } - private void onPlayerStateChange(PlayerStateController.PlayerStates newState, PlayerStateController.PlayerStates oldState) + private void OnPlayerStateChange(PlayerStates newState, PlayerStates oldState) { switch (oldState) { - case PlayerStateController.PlayerStates.BUILDING: - Crate.enabled = false; + case PlayerStates.BUILDING: + crate.enabled = false; break; - case PlayerStateController.PlayerStates.IN_TURRET_MENU: - Blueprint.enabled = false; + case PlayerStates.IN_TURRET_MENU: + blueprint.enabled = false; break; default: break; @@ -35,16 +40,14 @@ private void onPlayerStateChange(PlayerStateController.PlayerStates newState, Pl switch (newState) { - case PlayerStateController.PlayerStates.BUILDING: - Crate.enabled = true; + case PlayerStates.BUILDING: + crate.enabled = true; break; - case PlayerStateController.PlayerStates.IN_TURRET_MENU: - Blueprint.enabled = true; + case PlayerStates.IN_TURRET_MENU: + blueprint.enabled = true; break; default: break; } - - } -} +} diff --git a/Assets/Scripts/Player/PlayerControls.cs b/Assets/Scripts/Player/PlayerControls.cs index 67e32db1..c6d08a7f 100644 --- a/Assets/Scripts/Player/PlayerControls.cs +++ b/Assets/Scripts/Player/PlayerControls.cs @@ -43,7 +43,7 @@ public @PlayerControls() ""interactions"": """" }, { - ""name"": ""Back"", + ""name"": ""Cancel"", ""type"": ""Button"", ""id"": ""edbb2489-0819-43dd-bbbf-39f2ad7c7800"", ""expectedControlType"": ""Button"", @@ -251,18 +251,18 @@ public @PlayerControls() ""interactions"": """", ""processors"": """", ""groups"": ""Controller"", - ""action"": ""Back"", + ""action"": ""Cancel"", ""isComposite"": false, ""isPartOfComposite"": false }, { ""name"": """", ""id"": ""eeed5e82-f945-41b1-924f-37ce63a89e81"", - ""path"": ""/f"", + ""path"": ""/escape"", ""interactions"": """", ""processors"": """", ""groups"": ""Keyboard"", - ""action"": ""Back"", + ""action"": ""Cancel"", ""isComposite"": false, ""isPartOfComposite"": false }, @@ -361,7 +361,7 @@ public @PlayerControls() m_MovePlayer_Move = m_MovePlayer.FindAction("Move", throwIfNotFound: true); m_MovePlayer_Interact = m_MovePlayer.FindAction("Interact", throwIfNotFound: true); m_MovePlayer_Select = m_MovePlayer.FindAction("Select", throwIfNotFound: true); - m_MovePlayer_Back = m_MovePlayer.FindAction("Back", throwIfNotFound: true); + m_MovePlayer_Cancel = m_MovePlayer.FindAction("Cancel", throwIfNotFound: true); m_MovePlayer_Aim = m_MovePlayer.FindAction("Aim", throwIfNotFound: true); m_MovePlayer_Readyfornextwave = m_MovePlayer.FindAction("Ready for next wave", throwIfNotFound: true); // Menu @@ -420,7 +420,7 @@ public void Disable() private readonly InputAction m_MovePlayer_Move; private readonly InputAction m_MovePlayer_Interact; private readonly InputAction m_MovePlayer_Select; - private readonly InputAction m_MovePlayer_Back; + private readonly InputAction m_MovePlayer_Cancel; private readonly InputAction m_MovePlayer_Aim; private readonly InputAction m_MovePlayer_Readyfornextwave; public struct MovePlayerActions @@ -430,7 +430,7 @@ public struct MovePlayerActions public InputAction @Move => m_Wrapper.m_MovePlayer_Move; public InputAction @Interact => m_Wrapper.m_MovePlayer_Interact; public InputAction @Select => m_Wrapper.m_MovePlayer_Select; - public InputAction @Back => m_Wrapper.m_MovePlayer_Back; + public InputAction @Cancel => m_Wrapper.m_MovePlayer_Cancel; public InputAction @Aim => m_Wrapper.m_MovePlayer_Aim; public InputAction @Readyfornextwave => m_Wrapper.m_MovePlayer_Readyfornextwave; public InputActionMap Get() { return m_Wrapper.m_MovePlayer; } @@ -451,9 +451,9 @@ public void SetCallbacks(IMovePlayerActions instance) @Select.started -= m_Wrapper.m_MovePlayerActionsCallbackInterface.OnSelect; @Select.performed -= m_Wrapper.m_MovePlayerActionsCallbackInterface.OnSelect; @Select.canceled -= m_Wrapper.m_MovePlayerActionsCallbackInterface.OnSelect; - @Back.started -= m_Wrapper.m_MovePlayerActionsCallbackInterface.OnBack; - @Back.performed -= m_Wrapper.m_MovePlayerActionsCallbackInterface.OnBack; - @Back.canceled -= m_Wrapper.m_MovePlayerActionsCallbackInterface.OnBack; + @Cancel.started -= m_Wrapper.m_MovePlayerActionsCallbackInterface.OnCancel; + @Cancel.performed -= m_Wrapper.m_MovePlayerActionsCallbackInterface.OnCancel; + @Cancel.canceled -= m_Wrapper.m_MovePlayerActionsCallbackInterface.OnCancel; @Aim.started -= m_Wrapper.m_MovePlayerActionsCallbackInterface.OnAim; @Aim.performed -= m_Wrapper.m_MovePlayerActionsCallbackInterface.OnAim; @Aim.canceled -= m_Wrapper.m_MovePlayerActionsCallbackInterface.OnAim; @@ -473,9 +473,9 @@ public void SetCallbacks(IMovePlayerActions instance) @Select.started += instance.OnSelect; @Select.performed += instance.OnSelect; @Select.canceled += instance.OnSelect; - @Back.started += instance.OnBack; - @Back.performed += instance.OnBack; - @Back.canceled += instance.OnBack; + @Cancel.started += instance.OnCancel; + @Cancel.performed += instance.OnCancel; + @Cancel.canceled += instance.OnCancel; @Aim.started += instance.OnAim; @Aim.performed += instance.OnAim; @Aim.canceled += instance.OnAim; @@ -550,7 +550,7 @@ public interface IMovePlayerActions void OnMove(InputAction.CallbackContext context); void OnInteract(InputAction.CallbackContext context); void OnSelect(InputAction.CallbackContext context); - void OnBack(InputAction.CallbackContext context); + void OnCancel(InputAction.CallbackContext context); void OnAim(InputAction.CallbackContext context); void OnReadyfornextwave(InputAction.CallbackContext context); } diff --git a/Assets/Scripts/Player/PlayerMotion.cs b/Assets/Scripts/Player/PlayerMotion.cs index 02e6d631..85c408fb 100644 --- a/Assets/Scripts/Player/PlayerMotion.cs +++ b/Assets/Scripts/Player/PlayerMotion.cs @@ -36,7 +36,7 @@ public void Move() private void UpdateSpeed() { - if (state.CurrentState == PlayerStateController.PlayerStates.DEAD) + if (state.CurrentState == PlayerStates.DEAD) return; Vector2 scaledMoveInput = new Vector2(state.MoveInput.x, state.MoveInput.y) * 2f; diff --git a/Assets/Scripts/Player/PlayerStateController.cs b/Assets/Scripts/Player/PlayerStateController.cs index dfbeed5b..2d911fec 100644 --- a/Assets/Scripts/Player/PlayerStateController.cs +++ b/Assets/Scripts/Player/PlayerStateController.cs @@ -1,21 +1,31 @@ using System.Collections; using System.Collections.Generic; +using System.Linq; using UnityEngine; +public enum PlayerStates +{ + IN_ANIMATION, + LIFTING, + DEAD, + FREE, + BUILDING, + IN_TURRET_MENU, +} + /// /// The input-related code is in `PlayerStateController_Input.cs`. /// public partial class PlayerStateController : MonoBehaviour { private HealthLogic health; // Reference to the health script - private PlayerStates currentState = PlayerStates.FREE; // The current player state + private PlayerStates _currentState; private PlayerSpecificManager manager; private PlayerMotion motion; private PlayerUi ui; private InventoryManager inventoryManager; - - private List interactables = new List(); // List of interactables in range + private HashSet interactables = new HashSet(); // List of interactables in range private Interactable heldInteractable; private Interactable focusedInteractable; // The currently focused interactable private GameObject liftedObject; // Object being lifted @@ -28,24 +38,21 @@ public partial class PlayerStateController : MonoBehaviour private Animator anim; //Reference to animation controller of the player [SerializeField] - private Transform HeldItemBone; + private Transform heldItemBone; + + #region State variables for debugging - public PlayerStates CurrentState { get => currentState; } + [ReadOnly] + public PlayerStates currentStateReadOnly; + + #endregion State variables for debugging + + public PlayerStates CurrentState { get => _currentState; private set => currentStateReadOnly = _currentState = value; } public delegate void PlayerStateDelegate(PlayerStates newState, PlayerStates oldState); public PlayerStateDelegate onPlayerStateChange; //To allow other components to subscribe to stateChange events - public enum PlayerStates - { - IN_ANIMATION, - LIFTING, - DEAD, - FREE, - BUILDING, - IN_TURRET_MENU, - } - void Start() { motion = GetComponent(); @@ -54,22 +61,25 @@ void Start() ui = GetComponent(); terrain = GameObject.FindGameObjectWithTag("Grid").GetComponent(); inventoryManager = InventoryManager.Singleton; + + CurrentState = PlayerStates.FREE; } void FixedUpdate() { - UpdateFocusedInteractable(); - switch (currentState) + switch (CurrentState) { case PlayerStates.IN_ANIMATION: break; case PlayerStates.LIFTING: + UpdateFocusedInteractable(); //global motion.Move(); break; case PlayerStates.DEAD: break; case PlayerStates.FREE: + UpdateFocusedInteractable(); if (Select) SetState(PlayerStates.IN_TURRET_MENU); //global @@ -82,12 +92,13 @@ void FixedUpdate() //Lift(spawnedTower); break; case PlayerStates.BUILDING: + UpdateFocusedInteractable(); //global motion.Move(); targetCell = terrain.GetCell(transform.position + HexMetrics.outerRadius * 2f * transform.forward); focusedInteractable.GetComponent().FocusCell(targetCell); //case specific - if (back) + if (Cancel) { //Refund turret inventoryManager.ResourceAmount += ui.GetSelectedCost(); @@ -98,7 +109,7 @@ void FixedUpdate() SetState(PlayerStates.FREE); } - if (interact) + if (Interact) SetState(PlayerStates.FREE); break; @@ -120,14 +131,12 @@ void OnTriggerExit(Collider other) RemoveInteractable(other.GetComponentInParent()); } - private void Die() { // Drop anything we are carrying if (liftedObject != null) liftedObject.GetComponent().Interact(this); - SetFocusedInteractable(null); SetState(PlayerStates.DEAD); manager.RespawnPlayer(1f); @@ -137,12 +146,12 @@ private void Die() public void SetState(PlayerStates state) { - if (state == currentState) + if (state == CurrentState) return; - onPlayerStateChange?.Invoke(state, currentState); //In case any script wants to subscribe to state change events + onPlayerStateChange?.Invoke(state, CurrentState); //In case any script wants to subscribe to state change events //Cleanup from previous state - switch (currentState) + switch (CurrentState) { case PlayerStates.IN_ANIMATION: break; @@ -180,10 +189,13 @@ public void SetState(PlayerStates state) Destroy(heldInteractable.gameObject); heldInteractable = null; } + + SetFocusedInteractable(null); break; case PlayerStates.FREE: break; case PlayerStates.IN_TURRET_MENU: + SetFocusedInteractable(null); anim.SetBool("Planning", true); break; case PlayerStates.BUILDING: @@ -191,12 +203,13 @@ public void SetState(PlayerStates state) //AddInteractable(liftedObject.GetComponent()); break; case PlayerStates.IN_ANIMATION: + SetFocusedInteractable(null); break; default: break; } - currentState = state; + CurrentState = state; } // Gets called when interact button is pressed @@ -205,11 +218,9 @@ private void OnInteract() if (focusedInteractable != null) focusedInteractable.Interact(this); // interact with the current target if (focusedInteractable != null && !focusedInteractable.canInteract) - { RemoveInteractable(focusedInteractable); - } - if (currentState == PlayerStates.BUILDING) + if (CurrentState == PlayerStates.BUILDING) { // Build the turret we are holding focusedInteractable.GetComponent().Construct(targetCell); @@ -221,9 +232,6 @@ private void OnInteract() public void AddInteractable(Interactable interactable) { - if (interactables.Contains(interactable)) // Do not add an interactable twice - return; - interactables.Add(interactable); } @@ -247,7 +255,7 @@ private void UpdateFocusedInteractable() return; } else if (interactables.Count == 1) // If there is only one interactable object select that object { - SetFocusedInteractable(interactables[0]); + SetFocusedInteractable(interactables.Single()); return; } else if (focusedInteractable == null && heldInteractable == null) // Wait until we have at least one object to interact with return; @@ -293,16 +301,14 @@ public void Lift(GameObject obj) { liftedObject = obj; SetState(PlayerStates.LIFTING); - obj.transform.SetParent(HeldItemBone); + obj.transform.SetParent(heldItemBone); obj.transform.localPosition = Vector3.zero; - } public void PrepareTurret(Interactable turret) { heldInteractable = turret; AddInteractable(turret); - //Debug.Log(turret); } public void Drop(GameObject obj) diff --git a/Assets/Scripts/Player/PlayerStateController_Input.cs b/Assets/Scripts/Player/PlayerStateController_Input.cs index 1b9e64a5..616fe100 100644 --- a/Assets/Scripts/Player/PlayerStateController_Input.cs +++ b/Assets/Scripts/Player/PlayerStateController_Input.cs @@ -8,27 +8,21 @@ partial class PlayerStateController { private PlayerInput input; // Controller input - private Vector2 moveInput = Vector2.zero; - private Vector2 aimInput = Vector2.zero; - private bool interact = false; - private bool back = false; - private bool select = false; + public Vector2 MoveInput { get; private set; } = Vector2.zero; + public Vector2 AimInput { get; private set; } = Vector2.zero; + public bool Interact { get; private set; } = false; + public bool Cancel { get; private set; } = false; + public bool Select { get; private set; } = false; - public Vector2 MoveInput { get => moveInput; } - public Vector2 AimInput { get => aimInput; } - public bool Interact { get => interact; } - public bool Back { get => back; } - public bool Select { get => select; } - - private void MoveInput_Performed(InputAction.CallbackContext ctx) => moveInput = ctx.ReadValue(); - private void MoveInput_Canceled(InputAction.CallbackContext ctx) => moveInput = Vector2.zero; - private void AimInput_Performed(InputAction.CallbackContext ctx) => aimInput = ctx.ReadValue(); - private void AimInput_Canceled(InputAction.CallbackContext ctx) => aimInput = Vector2.zero; + private void MoveInput_Performed(InputAction.CallbackContext ctx) => MoveInput = ctx.ReadValue(); + private void MoveInput_Canceled(InputAction.CallbackContext ctx) => MoveInput = Vector2.zero; + private void AimInput_Performed(InputAction.CallbackContext ctx) => AimInput = ctx.ReadValue(); + private void AimInput_Canceled(InputAction.CallbackContext ctx) => AimInput = Vector2.zero; private void InteractInput_Performed(InputAction.CallbackContext ctx) => OnInteract(); - private void BackInput_Performed(InputAction.CallbackContext ctx) => back = true; - private void BackInput_Canceled(InputAction.CallbackContext ctx) => back = false; - private void SelectInput_Performed(InputAction.CallbackContext ctx) => select = true; - private void SelectInput_Canceled(InputAction.CallbackContext ctx) => select = false; + private void CancelInput_Performed(InputAction.CallbackContext ctx) => Cancel = true; + private void CancelInput_Canceled(InputAction.CallbackContext ctx) => Cancel = false; + private void SelectInput_Performed(InputAction.CallbackContext ctx) => Select = true; + private void SelectInput_Canceled(InputAction.CallbackContext ctx) => Select = false; private void ReadyForNextWaveInput_Canceled(InputAction.CallbackContext ctx) => EnemyWaveManager.ReadyForNextWave(); @@ -42,8 +36,8 @@ public void SetUpInput(PlayerInput newInput, PlayerSpecificManager newManager) newInput.actions["Aim"].performed += AimInput_Performed; newInput.actions["Aim"].canceled += AimInput_Canceled; newInput.actions["Interact"].performed += InteractInput_Performed; - newInput.actions["Back"].performed += BackInput_Performed; - newInput.actions["Back"].canceled += BackInput_Canceled; + newInput.actions["Cancel"].performed += CancelInput_Performed; + newInput.actions["Cancel"].canceled += CancelInput_Canceled; newInput.actions["Select"].performed += SelectInput_Performed; newInput.actions["Select"].canceled += SelectInput_Canceled; @@ -63,8 +57,8 @@ void OnDestroy() input.actions["Aim"].performed -= AimInput_Performed; input.actions["Aim"].canceled -= AimInput_Canceled; input.actions["Interact"].performed -= InteractInput_Performed; - input.actions["Back"].performed -= BackInput_Performed; - input.actions["Back"].canceled -= BackInput_Canceled; + input.actions["Cancel"].performed -= CancelInput_Performed; + input.actions["Cancel"].canceled -= CancelInput_Canceled; input.actions["Select"].performed -= SelectInput_Performed; input.actions["Select"].canceled -= SelectInput_Canceled; diff --git a/Assets/Scripts/Player/PlayerUi.cs b/Assets/Scripts/Player/PlayerUi.cs index 872c80e7..ead506b4 100644 --- a/Assets/Scripts/Player/PlayerUi.cs +++ b/Assets/Scripts/Player/PlayerUi.cs @@ -24,6 +24,13 @@ void Start() inventory = InventoryManager.Singleton; } + void LateUpdate() + { + //Points the UI to the main camera + Vector3 lookAtPos = transform.position + mainCameraTransform.rotation * Vector3.forward; + ui.transform.LookAt(lookAtPos, mainCameraTransform.rotation * Vector3.up); + } + public GameObject GetSelectedSegment() { return selectedSegment.tower; @@ -47,31 +54,22 @@ public void Select() { if (inventory.ResourceAmount - GetSelectedCost() < 0) { - state.SetState(PlayerStateController.PlayerStates.FREE); - } - else + state.SetState(PlayerStates.FREE); + } else { inventory.ResourceAmount -= GetSelectedCost(); GameObject spawnedTower = Instantiate(GetSelectedSegment()); state.PrepareTurret(spawnedTower.GetComponent()); - state.SetState(PlayerStateController.PlayerStates.BUILDING); + state.SetState(PlayerStates.BUILDING); } - } + } } - - } - - private void LateUpdate() - { - //Points the UI to the main camera - Vector3 lookAtPos = transform.position + mainCameraTransform.rotation * Vector3.forward; - ui.transform.LookAt(lookAtPos, mainCameraTransform.rotation * Vector3.up); } //Finds which segment of the radialUi the control stick is pointing towards private void UpdatePos() { - if (state.CurrentState != PlayerStateController.PlayerStates.IN_TURRET_MENU) + if (state.CurrentState != PlayerStates.IN_TURRET_MENU) { Debug.LogError("You seem to be in the wrong state for the UI"); return; diff --git a/Assets/Scripts/Towers/BulletLogic.cs b/Assets/Scripts/Towers/BulletLogic.cs index 9588dd25..1e69b811 100644 --- a/Assets/Scripts/Towers/BulletLogic.cs +++ b/Assets/Scripts/Towers/BulletLogic.cs @@ -4,11 +4,8 @@ public class BulletLogic : MonoBehaviour { - private float bulletSpeed; - private float damage; - - public float BulletSpeed { get => bulletSpeed; set => bulletSpeed = value; } - public float Damage { get => damage; set => damage = value; } + public float BulletSpeed { get; set; } + public float Damage { get; set; } void Start() { @@ -18,7 +15,7 @@ void Start() void Update() { //move the bullet with specified speed - transform.position += transform.forward * bulletSpeed * Time.deltaTime; + transform.position += transform.forward * BulletSpeed * Time.deltaTime; } //On collision -> call collided objects damagelogic if it has one and destroy this bullet @@ -26,7 +23,7 @@ void OnTriggerEnter(Collider other) { HealthLogic healthLogic = other.GetComponent(); if (healthLogic) - healthLogic.DealDamage(damage); + healthLogic.DealDamage(Damage); Destroy(gameObject); } diff --git a/Assets/Scripts/Towers/Specific towers/Axe turret/AxeTowerController.cs b/Assets/Scripts/Towers/Specific towers/Axe turret/AxeTowerController.cs index cb3ae995..6b184d26 100644 --- a/Assets/Scripts/Towers/Specific towers/Axe turret/AxeTowerController.cs +++ b/Assets/Scripts/Towers/Specific towers/Axe turret/AxeTowerController.cs @@ -30,6 +30,12 @@ void FixedUpdate() } } + public override void Focus(PlayerStateController player) + { + focused = true; + playerAiming = player; + } + public override void Unfocus(PlayerStateController player) { if (player == playerAiming) @@ -39,11 +45,8 @@ public override void Unfocus(PlayerStateController player) } } - public override void Focus(PlayerStateController player) - { - focused = true; - playerAiming = player; - } + public override void Interact(PlayerStateController player) + {} public void Grab() { diff --git a/Assets/Scripts/Towers/TowerLogic.cs b/Assets/Scripts/Towers/TowerLogic.cs index c4954525..cba1eba5 100644 --- a/Assets/Scripts/Towers/TowerLogic.cs +++ b/Assets/Scripts/Towers/TowerLogic.cs @@ -55,6 +55,9 @@ public override void Unfocus(PlayerStateController player) arrowPointerRenderer.enabled = false; } + public override void Interact(PlayerStateController player) + {} + //Rotational-Movement using UserInput private void ChangeDirection() { diff --git a/Assets/Scripts/Towers/TurretInput.cs b/Assets/Scripts/Towers/TurretInput.cs index 294121c4..f5e02a4f 100644 --- a/Assets/Scripts/Towers/TurretInput.cs +++ b/Assets/Scripts/Towers/TurretInput.cs @@ -4,47 +4,15 @@ public class TurretInput : MonoBehaviour { - public GameObject tower; - - private IEnumerator coroutine; private PlayerStateController player; - private HexGrid hexGrid; void Start() { - hexGrid = GameObject.Find("Terrain").GetComponent(); player = GetComponent(); - - coroutine = WaitAndPrint(5.0f); - StartCoroutine(coroutine); - } - - private IEnumerator WaitAndPrint(float waitTime) - { - while (true) - { - yield return new WaitForSeconds(waitTime); - //PlaceTower(tower, transform.position); - } } public Vector2 GetAimInput() { - if (player.CurrentState == PlayerStateController.PlayerStates.DEAD) - return Vector2.zero; - return player.AimInput; } - - public PlayerStateController.PlayerStates CurrentPlayerState() - { - return player.CurrentState; - } - - public void PlaceTower(GameObject tower, Vector3 position) - { - HexCell cell = hexGrid.GetCell(position); - cell.isOccupied = true; - cell.occupier = Instantiate(tower, cell.transform); - } } diff --git a/Assets/Scripts/Towers/TurretPrefabConstruction.cs b/Assets/Scripts/Towers/TurretPrefabConstruction.cs index 662c9eea..1f7e2689 100644 --- a/Assets/Scripts/Towers/TurretPrefabConstruction.cs +++ b/Assets/Scripts/Towers/TurretPrefabConstruction.cs @@ -16,12 +16,6 @@ public void Construct(HexCell targetCell) public override void Interact(PlayerStateController player) {} - public override void Focus(PlayerStateController player) - {} - - public override void Unfocus(PlayerStateController player) - {} - public void FocusCell(HexCell targetCell) { transform.position = targetCell.transform.position; diff --git a/Assets/Scripts/UI/FlexibleUI/FlexibleUIButton.cs b/Assets/Scripts/UI/FlexibleUI/FlexibleUIButton.cs index 2f52b11e..36653646 100644 --- a/Assets/Scripts/UI/FlexibleUI/FlexibleUIButton.cs +++ b/Assets/Scripts/UI/FlexibleUI/FlexibleUIButton.cs @@ -3,24 +3,23 @@ using UnityEngine; using UnityEngine.UI; +public enum ButtonType +{ + DEFAULT, + CONFIRM, + DECLINE, + WARNING, +} + [RequireComponent(typeof(Button))] [RequireComponent(typeof(Image))] public class FlexibleUIButton : FlexibleUI { - public enum ButtonType - { - DEFAULT, - CONFIRM, - DECLINE, - WARNING, - } - Image image; - private Image icon; Button button; public ButtonType buttonType; - public Image Icon { get => icon; set => icon = value; } + public Image Icon { get; set; } protected override void OnSkinUI() {