Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions Assets/Scripts/Characters/Arrow.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
using UnityEngine;
using UnityEngine.InputSystem;

public class Arrow : MonoBehaviour
{
[SerializeField] private bool _forceEnable;

private void Awake()
{
if (_forceEnable)
{
return;
}

if (Application.platform != RuntimePlatform.Android &&
Application.platform != RuntimePlatform.IPhonePlayer)
{
gameObject.SetActive(false);
}

// Show arrow on mobile platforms or when a gamepad is connected
bool shouldShowArrow = Application.platform == RuntimePlatform.Android ||
Application.platform == RuntimePlatform.IPhonePlayer ||
Gamepad.current != null;

gameObject.SetActive(shouldShowArrow);
Comment on lines +16 to +20
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The arrow's visibility is set once in Awake() based on gamepad presence and never updates, causing the UI to be missing if a controller is connected mid-game.
Severity: MEDIUM

Suggested Fix

To ensure the arrow's visibility reflects the current input device, subscribe to the InputSystem.onDeviceChange event. In the event handler, check for gamepad presence and update the arrow's active state accordingly. Remember to unsubscribe from the event in OnDestroy() to prevent memory leaks. Alternatively, move the check into the Update() method for continuous polling.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: Assets/Scripts/Characters/Arrow.cs#L16-L20

Potential issue: The arrow's visibility is determined by checking `Gamepad.current !=
null` only once within the `Awake()` method and is never updated again. If a player
connects a gamepad after the scene has loaded, the arrow UI indicator will remain
hidden, even though other game systems correctly switch to gamepad input. This creates
an inconsistent user experience where the aiming system recognizes the controller, but
the associated visual aid does not appear.

Did we get this right? 👍 / 👎 to inform future reviews.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, also thought about this while adding the one-time-check; but since we're gonna run the demo on handheld consoles, if the controller disconnects that must mean the console itself was destroyed.. IMO this is not something we need to fix right away, but can be opened as a new issue to show we're aware of this.

}
}
6 changes: 6 additions & 0 deletions Assets/Scripts/SceneManagers/BattleSceneManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,12 @@ private void SetCurrentLevel(int level)

public void OnPause()
{
// Don't allow pausing if the level up UI is active (it already pauses the game)
if (_levelUpUI.activeSelf)
{
return;
}

if (_gameState == GameState.Playing)
{
PauseGame();
Expand Down
32 changes: 23 additions & 9 deletions Assets/Scripts/SceneManagers/HUDManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,20 @@ private void Awake()
_navigateAction = InputSystem.actions.FindAction("Navigate");
_submitAction = InputSystem.actions.FindAction("Submit");

// Subscribe to the performed callback only
// Subscribe to input events
_navigateAction.performed += OnNavigatePerformed;
_submitAction.performed += OnSubmitPerformed;

_tryAgainHighlighter = tryAgainButton.GetComponent<Highlighter>();
_quitHighlighter = quitButton.GetComponent<Highlighter>();
}

private void OnDestroy()
{
// Unsubscribe from input events
_navigateAction.performed -= OnNavigatePerformed;
_submitAction.performed -= OnSubmitPerformed;
}

private void OnSubmitPerformed(InputAction.CallbackContext context)
{
Expand All @@ -37,10 +45,14 @@ private void OnSubmitPerformed(InputAction.CallbackContext context)
return;
}

_highlightedButton?.GetComponent<Button>().onClick.Invoke();
// Only invoke if the highlighted button is actually active
if (_highlightedButton != null && _highlightedButton.activeSelf)
{
_highlightedButton.GetComponent<Button>().onClick.Invoke();
}
}

public void OnNavigate()
private void OnNavigatePerformed(InputAction.CallbackContext context)
{
if (!gameObject.activeSelf)
{
Expand All @@ -52,12 +64,7 @@ public void OnNavigate()
return;
}

if (!_navigateAction.WasPressedThisFrame())
{
return;
}

var direction = _navigateAction.ReadValue<Vector2>();
var direction = context.ReadValue<Vector2>();

// Simple navigation between try again and quit buttons
if (_highlightedButton == null)
Expand Down Expand Up @@ -92,5 +99,12 @@ public void SetHighlightedButton(Highlighter highlighted)
highlighted.Highlight();
_highlightedButton = highlighted.gameObject;
}

public void ClearHighlightedButton()
{
_tryAgainHighlighter.Highlight(false);
_quitHighlighter.Highlight(false);
_highlightedButton = null;
}
}
}
8 changes: 8 additions & 0 deletions Assets/Scripts/UI/HUD/HUD.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Runtime.InteropServices;
using SceneManagers;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
Expand All @@ -16,6 +17,7 @@ public class HUD : MonoBehaviour
[SerializeField] private ScorePoster _scorePoster;
[SerializeField] private GameObject _tryAgain;
[SerializeField] private GameObject _quit;
[SerializeField] private HUDManager _hudManager;

private DemoConfiguration _demoConfig;
private XpBar _xpBar;
Expand Down Expand Up @@ -78,6 +80,12 @@ public void HidePause()
_gameOverText.enabled = false;
_tryAgain.SetActive(false);
_quit.SetActive(false);

// Clear the highlighted button to prevent accidental clicks
if (_hudManager != null)
{
_hudManager.ClearHighlightedButton();
}
}

public void ShowGameOver()
Expand Down
29 changes: 15 additions & 14 deletions Assets/Scripts/Upgrades/LevelUpUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ private void OnEnable()
InputSystem.actions.FindActionMap("Player").Disable();
InputSystem.actions.FindActionMap("UI").Enable();

// Subscribe to input events
_navigateAction.performed += OnNavigatePerformed;
_submitAction.performed += OnSubmitPerformed;

// Pause the game
Time.timeScale = 0;

Expand All @@ -75,6 +79,9 @@ private void OnEnable()

_option1Button.onClick.AddListener(() => SelectUpgrade(upgradeChoice1));
_option2Button.onClick.AddListener(() => SelectUpgrade(upgradeChoice2));

// Set initial highlighted button to option 1
SetHighlightedButton(_option1Button);

if (_demoConfig != null && _demoConfig.AutoPlay)
{
Expand Down Expand Up @@ -107,19 +114,14 @@ private IEnumerator SelectSomething()
_highlightedButton?.GetComponent<Button>().onClick.Invoke();
}

public void OnNavigate()
private void OnNavigatePerformed(InputAction.CallbackContext context)
{
if (!gameObject.activeSelf)
{
return;
}

if (!_navigateAction.WasPressedThisFrame())
{
return;
}

var direction = _navigateAction.ReadValue<Vector2>();
var direction = context.ReadValue<Vector2>();
if (direction.x < 0)
{
SetHighlightedButton(_option1Button);
Expand All @@ -130,19 +132,14 @@ public void OnNavigate()
}
}

public void OnSubmit()
private void OnSubmitPerformed(InputAction.CallbackContext context)
{
if (!gameObject.activeSelf)
{
return;
}

if (!_submitAction.IsPressed())
{
return;
}

_highlightedButton?.GetComponent<Button>().onClick.Invoke();
_highlightedButton?.onClick.Invoke();
}

public void SetHighlightedButton(Button button)
Expand All @@ -156,6 +153,10 @@ public void SetHighlightedButton(Button button)

private void OnDisable()
{
// Unsubscribe from input events
_navigateAction.performed -= OnNavigatePerformed;
_submitAction.performed -= OnSubmitPerformed;

_option1Button.onClick.RemoveAllListeners();
_option2Button.onClick.RemoveAllListeners();
}
Expand Down
63 changes: 59 additions & 4 deletions Assets/Settings/InputSystem_Actions.inputactions
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
{
"name": "",
"id": "516ec204-3b9e-43d6-b1fe-a3b649c01b88",
"path": "<GXDKGamepad>/select",
"path": "<GXDKGamepad>/start",
"interactions": "",
"processors": "",
"groups": ";Gamepad",
Expand All @@ -231,7 +231,29 @@
{
"name": "",
"id": "a57c8beb-ff4b-48af-b12b-39a9b69277f8",
"path": "<XInputController>/select",
"path": "<XInputController>/start",
"interactions": "",
"processors": "",
"groups": ";Gamepad",
"action": "Pause",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "d1e2f3a4-b5c6-7d8e-9f0a-1b2c3d4e5f6a",
"path": "<DualShockGamepad>/start",
"interactions": "",
"processors": "",
"groups": ";Gamepad",
"action": "Pause",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "a1b2c3d4-e5f6-7a8b-9c0d-1e2f3a4b5c6e",
"path": "<SwitchProControllerHID>/start",
"interactions": "",
"processors": "",
"groups": ";Gamepad",
Expand Down Expand Up @@ -723,7 +745,7 @@
{
"name": "",
"id": "4f2f6db6-f487-4f7b-819c-50fda21f90d7",
"path": "<GXDKGamepad>/select",
"path": "<GXDKGamepad>/start",
"interactions": "",
"processors": "",
"groups": ";Gamepad",
Expand All @@ -745,7 +767,29 @@
{
"name": "",
"id": "2b76180b-bc1b-4768-ae01-060e98b1d64a",
"path": "<XInputController>/select",
"path": "<XInputController>/start",
"interactions": "",
"processors": "",
"groups": ";Gamepad",
"action": "Pause",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "e1f2a3b4-c5d6-7e8f-9a0b-1c2d3e4f5a6b",
"path": "<DualShockGamepad>/start",
"interactions": "",
"processors": "",
"groups": ";Gamepad",
"action": "Pause",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "b2c3d4e5-f6a7-8b9c-0d1e-2f3a4b5c6d7f",
"path": "<SwitchProControllerHID>/start",
"interactions": "",
"processors": "",
"groups": ";Gamepad",
Expand All @@ -764,6 +808,17 @@
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "a1b2c3d4-5e6f-7a8b-9c0d-1e2f3a4b5c6d",
"path": "<Keyboard>/space",
"interactions": "",
"processors": "",
"groups": "Keyboard&Mouse",
"action": "Submit",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "82627dcc-3b13-4ba9-841d-e4b746d6553e",
Expand Down