Skip to content

Commit 3b4a6b5

Browse files
authored
Merge pull request #5 from sentry-demos/feat/merge-upstream
2 parents 8213e0a + 0e70a6b commit 3b4a6b5

File tree

20 files changed

+251
-100
lines changed

20 files changed

+251
-100
lines changed

.github/workflows/run-demo.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
Write-Output "Found executable: $($exePath.FullName)"
5454
$startTime = Get-Date
5555
56-
Start-Process -FilePath $exePath -Wait -PassThru -NoNewWindow
56+
Start-Process -FilePath $exePath -ArgumentList "-demo" -Wait -PassThru -NoNewWindow
5757
5858
$endTime = Get-Date
5959
$duration = $endTime - $startTime

Assets/Resources/DemoConfig.asset

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ MonoBehaviour:
1212
m_Script: {fileID: 11500000, guid: dd9ba42fbcfea443dae0540ef0f44176, type: 3}
1313
m_Name: DemoConfig
1414
m_EditorClassIdentifier:
15-
_enabled: 1
16-
_apiUrl: https://sentaur-leaderboard-f7z2cjcdzq-uc.a.run.app
15+
_enabled: 0
16+
_apiUrl:
1717
_user:
18-
Username:
19-
Password:
20-
_autoPlay: 1
21-
_notHotDogParticleEffect: 1
22-
_fetchUpgradeFromServer: 1
23-
_crashOnGameOver: 1
18+
Username:
19+
Password:
20+
_autoPlay: 0
21+
_notHotDogParticleEffect: 0
22+
_fetchUpgradeFromServer: 0
23+
_crashOnGameOver: 0

Assets/Scripts/Characters/Arrow.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
using UnityEngine;
2+
using UnityEngine.InputSystem;
23

34
public class Arrow : MonoBehaviour
45
{
56
[SerializeField] private bool _forceEnable;
7+
68
private void Awake()
79
{
810
if (_forceEnable)
911
{
1012
return;
1113
}
12-
13-
if (Application.platform != RuntimePlatform.Android &&
14-
Application.platform != RuntimePlatform.IPhonePlayer)
15-
{
16-
gameObject.SetActive(false);
17-
}
14+
15+
// Show arrow on mobile platforms or when a gamepad is connected
16+
bool shouldShowArrow = Application.platform == RuntimePlatform.Android ||
17+
Application.platform == RuntimePlatform.IPhonePlayer ||
18+
Gamepad.current != null;
19+
20+
gameObject.SetActive(shouldShowArrow);
1821
}
1922
}

Assets/Scripts/Characters/DemoPlayerController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class DemoPlayerController : MonoBehaviour
1515

1616
private void Awake()
1717
{
18-
_demoConfig = Resources.Load("DemoConfig") as DemoConfiguration;
18+
_demoConfig = DemoConfiguration.Load();
1919
}
2020

2121
private void OnEnable()

Assets/Scripts/Config/ArgumentReader.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,15 @@ public static string GetCommandLineArg(string name)
1414
}
1515
return null;
1616
}
17+
18+
public static bool HasCommandLineFlag(string name)
19+
{
20+
var args = Environment.GetCommandLineArgs();
21+
for (var i = 0; i < args.Length; i++)
22+
{
23+
if (args[i] == "-" + name)
24+
return true;
25+
}
26+
return false;
27+
}
1728
}

Assets/Scripts/Config/DemoConfiguration.cs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,45 @@ public class DemoConfiguration : ScriptableObject
1616
[SerializeField] private bool _notHotDogParticleEffect;
1717
[SerializeField] private bool _fetchUpgradeFromServer;
1818
[SerializeField] private bool _crashOnGameOver;
19-
19+
20+
private bool _overridesApplied;
21+
2022
public bool Enabled => _enabled;
2123
public string ApiUrl => _apiUrl;
2224
public User User => _user;
23-
25+
2426
public bool AutoPlay => _enabled && _autoPlay;
2527
public bool NotHotDogParticleEffect => _enabled && _notHotDogParticleEffect;
2628
public bool FetchUpgradeFromServer => _enabled && _fetchUpgradeFromServer;
2729
public bool CrashOnGameOver => _enabled && _crashOnGameOver;
30+
31+
public void ApplyRuntimeOverrides()
32+
{
33+
if (_overridesApplied)
34+
return;
35+
_overridesApplied = true;
36+
37+
if (ArgumentReader.HasCommandLineFlag("demo"))
38+
{
39+
_enabled = true;
40+
_autoPlay = true;
41+
_crashOnGameOver = true;
42+
_notHotDogParticleEffect = true;
43+
_fetchUpgradeFromServer = true;
44+
}
45+
}
46+
47+
private static DemoConfiguration _instance;
48+
49+
public static DemoConfiguration Load()
50+
{
51+
if (_instance == null)
52+
{
53+
_instance = Resources.Load("DemoConfig") as DemoConfiguration;
54+
_instance?.ApplyRuntimeOverrides();
55+
}
56+
return _instance;
57+
}
2858
}
2959

3060
[Serializable]

Assets/Scripts/Pickups/NotHotDogPickup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class NotHotDogPickup : PickupBase
99

1010
private void Awake()
1111
{
12-
_demoConfig = Resources.Load("DemoConfig") as DemoConfiguration;
12+
_demoConfig = DemoConfiguration.Load();
1313
}
1414

1515
protected override void OnCollect(Player player)

Assets/Scripts/SceneManagers/BattleSceneManager.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ private enum GameState
215215

216216
private void Awake()
217217
{
218-
_demoConfig = Resources.Load("DemoConfig") as DemoConfiguration;
218+
_demoConfig = DemoConfiguration.Load();
219219

220220
InputSystem.actions.FindActionMap("Player").Enable();
221221
InputSystem.actions.FindActionMap("UI").Disable();
@@ -463,6 +463,12 @@ private void SetCurrentLevel(int level)
463463

464464
public void OnPause()
465465
{
466+
// Don't allow pausing if the level up UI is active (it already pauses the game)
467+
if (_levelUpUI.activeSelf)
468+
{
469+
return;
470+
}
471+
466472
if (_gameState == GameState.Playing)
467473
{
468474
PauseGame();

Assets/Scripts/SceneManagers/HUDManager.cs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,20 @@ private void Awake()
2323
_navigateAction = InputSystem.actions.FindAction("Navigate");
2424
_submitAction = InputSystem.actions.FindAction("Submit");
2525

26-
// Subscribe to the performed callback only
26+
// Subscribe to input events
27+
_navigateAction.performed += OnNavigatePerformed;
2728
_submitAction.performed += OnSubmitPerformed;
2829

2930
_tryAgainHighlighter = tryAgainButton.GetComponent<Highlighter>();
3031
_quitHighlighter = quitButton.GetComponent<Highlighter>();
3132
}
33+
34+
private void OnDestroy()
35+
{
36+
// Unsubscribe from input events
37+
_navigateAction.performed -= OnNavigatePerformed;
38+
_submitAction.performed -= OnSubmitPerformed;
39+
}
3240

3341
private void OnSubmitPerformed(InputAction.CallbackContext context)
3442
{
@@ -37,10 +45,14 @@ private void OnSubmitPerformed(InputAction.CallbackContext context)
3745
return;
3846
}
3947

40-
_highlightedButton?.GetComponent<Button>().onClick.Invoke();
48+
// Only invoke if the highlighted button is actually active
49+
if (_highlightedButton != null && _highlightedButton.activeSelf)
50+
{
51+
_highlightedButton.GetComponent<Button>().onClick.Invoke();
52+
}
4153
}
4254

43-
public void OnNavigate()
55+
private void OnNavigatePerformed(InputAction.CallbackContext context)
4456
{
4557
if (!gameObject.activeSelf)
4658
{
@@ -52,12 +64,7 @@ public void OnNavigate()
5264
return;
5365
}
5466

55-
if (!_navigateAction.WasPressedThisFrame())
56-
{
57-
return;
58-
}
59-
60-
var direction = _navigateAction.ReadValue<Vector2>();
67+
var direction = context.ReadValue<Vector2>();
6168

6269
// Simple navigation between try again and quit buttons
6370
if (_highlightedButton == null)
@@ -92,5 +99,12 @@ public void SetHighlightedButton(Highlighter highlighted)
9299
highlighted.Highlight();
93100
_highlightedButton = highlighted.gameObject;
94101
}
102+
103+
public void ClearHighlightedButton()
104+
{
105+
_tryAgainHighlighter.Highlight(false);
106+
_quitHighlighter.Highlight(false);
107+
_highlightedButton = null;
108+
}
95109
}
96110
}

Assets/Scripts/SceneManagers/TitleSceneManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class TitleSceneManager : MonoBehaviour
2424

2525
private void Awake()
2626
{
27-
_demoConfig = Resources.Load("DemoConfig") as DemoConfiguration;
27+
_demoConfig = DemoConfiguration.Load();
2828
_navigateAction = InputSystem.actions.FindAction("Navigate");
2929
_startHighlighter = startButton.GetComponent<Highlighter>();
3030
_quitHighlighter = quitButton.GetComponent<Highlighter>();

0 commit comments

Comments
 (0)