Skip to content

Commit 6f84b65

Browse files
authored
Merge pull request #7 from betahub-io/dev
Dev
2 parents c5488c2 + c869f17 commit 6f84b65

File tree

3 files changed

+217
-108
lines changed

3 files changed

+217
-108
lines changed

Documentation.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ <h3>Configuration</h3>
112112
<ul>
113113
<li><strong>Frame Rate</strong>: Default is 30. Higher rates may increase file size and resource usage.</li>
114114
<li><strong>Recording Duration</strong>: Default is 60 seconds.</li>
115+
<li><strong>Downscale Video</strong>: <em>Off by default.</em> If enabled, the video will be downscaled to a maximum resolution (default: 1920x1080) if your game runs at a higher resolution. This helps reduce CPU usage and file size when recording on high-resolution displays. Enable this option in the inspector if you notice high CPU usage or stuttering during recording at large resolutions.</li>
115116
</ul>
116117
</li>
117118
</ul>

Runtime/Scripts/BugReportUI.cs

Lines changed: 102 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Collections;
77
using UnityEngine.Events;
88
using System.Collections.Generic;
9+
using UnityEngine.Serialization;
910
#if ENABLE_INPUT_SYSTEM
1011
using UnityEngine.InputSystem;
1112
#endif
@@ -26,56 +27,76 @@ public enum MediaUploadType
2627

2728
public class BugReportUI : MonoBehaviour
2829
{
29-
private static BugReportUI instance;
30+
private static BugReportUI _instance;
3031

31-
public GameObject bugReportPanel;
32-
public TMP_InputField descriptionField;
33-
public TMP_InputField stepsField;
32+
[FormerlySerializedAs("bugReportPanel")]
33+
public GameObject BugReportPanel;
34+
35+
[FormerlySerializedAs("descriptionField")]
36+
public TMP_InputField DescriptionField;
37+
38+
[FormerlySerializedAs("stepsField")]
39+
public TMP_InputField StepsField;
3440

3541
public Toggle IncludeVideoToggle;
3642
public Toggle IncludeScreenshotToggle;
3743
public Toggle IncludePlayerLogToggle;
3844

39-
public Button submitButton;
40-
public Button closeButton;
45+
[FormerlySerializedAs("submitButton")]
46+
public Button SubmitButton;
47+
48+
[FormerlySerializedAs("closeButton")]
49+
public Button CloseButton;
4150

42-
public GameObject messagePanel;
51+
[FormerlySerializedAs("messagePanel")]
52+
public GameObject MessagePanel;
4353

44-
public MessagePanelUI messagePanelUI;
54+
[FormerlySerializedAs("messagePanelUI")]
55+
public MessagePanelUI MessagePanelUI;
4556

4657
[Tooltip("Upload in background : The media will be uploaded in the background without blocking the process" +
4758
" \n Wait for upload : The process will wait until the media has finished uploading before continuing")]
48-
public MediaUploadType mediaUploadType;
59+
[FormerlySerializedAs("mediaUploadType")]
60+
public MediaUploadType MediaUploadType;
4961

50-
public ReportSubmittedUI reportSubmittedUI;
62+
[FormerlySerializedAs("reportSubmittedUI")]
63+
public ReportSubmittedUI ReportSubmittedUI;
5164

52-
public string submitEndpoint = "https://app.betahub.io";
65+
[FormerlySerializedAs("submitEndpoint")]
66+
public string SubmitEndpoint = "https://app.betahub.io";
5367

54-
public string projectID;
68+
[FormerlySerializedAs("projectID")]
69+
public string ProjectID;
5570

56-
public string authToken;
71+
[FormerlySerializedAs("authToken")]
72+
public string AuthToken;
5773

5874
// If set, this email address will be used as the default email address of the reporter.
5975
// This is a hidden field since it's purpose is to be pre-filled programmatically by the developer if the user is somehow already logged in with a specific email address.
60-
[HideInInspector]
61-
public string defaultEmailAddress;
76+
[HideInInspector, FormerlySerializedAs("defaultEmailAddress")]
77+
public string DefaultEmailAddress;
6278

6379
#if ENABLE_INPUT_SYSTEM
64-
public InputAction shortcutAction = new InputAction("BugReportShortcut", binding: "<Keyboard>/f12");
80+
[FormerlySerializedAs("shortcutAction")]
81+
public InputAction ShortcutAction = new InputAction("BugReportShortcut", binding: "<Keyboard>/f12");
6582
#else
66-
public KeyCode shortcutKey = KeyCode.F12;
83+
[FormerlySerializedAs("shortcutKey")]
84+
public KeyCode ShortcutKey = KeyCode.F12;
6785
#endif
6886

69-
public bool includePlayerLog = true;
70-
public bool includeVideo = true;
87+
[FormerlySerializedAs("includePlayerLog")]
88+
public bool IncludePlayerLog = true;
89+
90+
[FormerlySerializedAs("includeVideo")]
91+
public bool IncludeVideo = true;
7192

7293
public UnityEvent OnBugReportWindowShown;
7394
public UnityEvent OnBugReportWindowHidden;
7495

7596
private List<Issue.ScreenshotFileReference> _screenshots = new List<Issue.ScreenshotFileReference>();
7697
private List<Issue.LogFileReference> _logFiles = new List<Issue.LogFileReference>();
7798

78-
private static Logger logger;
99+
private static Logger _logger;
79100
private bool _cursorStateChanged;
80101
private CursorLockMode _previousCursorLockMode;
81102

@@ -84,17 +105,19 @@ public class BugReportUI : MonoBehaviour
84105
// we keep track of the issues to not record the video when any of the issues are being uploaded
85106
private List<Issue> _issues = new List<Issue>();
86107

108+
private bool _uiWasVisible = false;
109+
87110
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
88111
private static void InitializeLogger()
89112
{
90-
logger = new Logger();
113+
_logger = new Logger();
91114
}
92115

93116
void Awake()
94117
{
95-
if (instance == null)
118+
if (_instance == null)
96119
{
97-
instance = this;
120+
_instance = this;
98121
}
99122
else
100123
{
@@ -107,8 +130,8 @@ void OnEnable()
107130
#if ENABLE_INPUT_SYSTEM
108131
if (IsNewInputSystemEnabled())
109132
{
110-
shortcutAction.Enable();
111-
shortcutAction.performed += OnShortcutActionPerformed;
133+
ShortcutAction.Enable();
134+
ShortcutAction.performed += OnShortcutActionPerformed;
112135
}
113136
#endif
114137
}
@@ -118,8 +141,8 @@ void OnDisable()
118141
#if ENABLE_INPUT_SYSTEM
119142
if (IsNewInputSystemEnabled())
120143
{
121-
shortcutAction.performed -= OnShortcutActionPerformed;
122-
shortcutAction.Disable();
144+
ShortcutAction.performed -= OnShortcutActionPerformed;
145+
ShortcutAction.Disable();
123146
}
124147
#endif
125148
}
@@ -128,25 +151,25 @@ void Start()
128151
{
129152
_gameRecorder = GetComponent<GameRecorder>();
130153

131-
bugReportPanel.SetActive(false);
132-
submitButton.onClick.AddListener(SubmitBugReport);
133-
closeButton.onClick.AddListener(() =>
154+
BugReportPanel.SetActive(false);
155+
SubmitButton.onClick.AddListener(SubmitBugReport);
156+
CloseButton.onClick.AddListener(() =>
134157
{
135-
bugReportPanel.SetActive(false);
158+
BugReportPanel.SetActive(false);
136159
});
137160

138-
if (string.IsNullOrEmpty(projectID))
161+
if (string.IsNullOrEmpty(ProjectID))
139162
{
140163
Debug.LogError("Project ID is not set. I won't be able to submit bug reports.");
141164
}
142165

143-
if (string.IsNullOrEmpty(authToken))
166+
if (string.IsNullOrEmpty(AuthToken))
144167
{
145168
Debug.LogError("Auth token is not set. I won't be able to submit bug reports.");
146169
}
147170

148171
// auth token must start with tkn-
149-
if (!authToken.StartsWith("tkn-"))
172+
if (!AuthToken.StartsWith("tkn-"))
150173
{
151174
Debug.LogError("Auth token must start with tkn-. I won't be able to submit bug reports.");
152175
}
@@ -190,17 +213,27 @@ void Update()
190213
}
191214
}
192215

193-
if (bugReportPanel.activeSelf && !_cursorStateChanged)
216+
if (UiIsVisible())
194217
{
195-
ModifyCursorState();
218+
if (!_uiWasVisible)
219+
{
220+
OnBugReportWindowShown?.Invoke();
221+
ModifyCursorState();
222+
}
223+
_uiWasVisible = true;
196224
}
197-
else if (!bugReportPanel.activeSelf && !messagePanelUI.gameObject.activeSelf && _cursorStateChanged)
225+
else if (!UiIsVisible())
198226
{
199-
RestoreCursorState();
227+
if (_uiWasVisible)
228+
{
229+
OnBugReportWindowHidden?.Invoke();
230+
RestoreCursorState();
231+
}
232+
_uiWasVisible = false;
200233
}
201234

202235
#if !ENABLE_INPUT_SYSTEM
203-
if (shortcutKey != KeyCode.None && Input.GetKeyDown(shortcutKey))
236+
if (ShortcutKey != KeyCode.None && Input.GetKeyDown(ShortcutKey))
204237
{
205238
StartCoroutine(CaptureScreenshotAndShowUI());
206239
}
@@ -210,7 +243,12 @@ void Update()
210243
private bool SholdBeRecordingVideo()
211244
{
212245
// if true, the report is being uploaded, some processes should be paused
213-
return includeVideo && !bugReportPanel.activeSelf && !_issues.Exists(issue => !issue.IsMediaUploadComplete);
246+
return IncludeVideo && !UiIsVisible() && !_issues.Exists(issue => !issue.IsMediaUploadComplete);
247+
}
248+
249+
private bool UiIsVisible()
250+
{
251+
return BugReportPanel.activeSelf || MessagePanelUI.gameObject.activeSelf || ReportSubmittedUI.gameObject.activeSelf;
214252
}
215253

216254
private void ModifyCursorState()
@@ -221,7 +259,6 @@ private void ModifyCursorState()
221259
_previousCursorLockMode = Cursor.lockState;
222260
Cursor.lockState = CursorLockMode.None;
223261
Cursor.visible = true;
224-
OnBugReportWindowShown?.Invoke();
225262
}
226263
}
227264

@@ -232,7 +269,6 @@ private void RestoreCursorState()
232269
Cursor.lockState = _previousCursorLockMode;
233270
Cursor.visible = false;
234271
_cursorStateChanged = false;
235-
OnBugReportWindowHidden?.Invoke();
236272
}
237273
}
238274

@@ -261,20 +297,20 @@ IEnumerator CaptureScreenshotAndShowUI()
261297
yield return null;
262298

263299
// reset the fields
264-
descriptionField.text = "";
265-
stepsField.text = "";
300+
DescriptionField.text = "";
301+
StepsField.text = "";
266302
IncludeVideoToggle.isOn = true;
267303
IncludeScreenshotToggle.isOn = true;
268304
IncludePlayerLogToggle.isOn = true;
269305

270306
#if BETAHUB_DEBUG
271307
Debug.Log("BETAHUB_DEBUG: Prefilling description and steps for reproduce for faster testing");
272308
// prefill the description and steps for reproduce for faster testing
273-
descriptionField.text = "The game is crashing when I press the sounds setting button. It happens on the main menu and on the settings menu.";
274-
stepsField.text = "1. Go to the main menu\n2. Press the settings button\n3. Press the sounds button\n4. Crash the game";
309+
DescriptionField.text = "The game is crashing when I press the sounds setting button. It happens on the main menu and on the settings menu.";
310+
StepsField.text = "1. Go to the main menu\n2. Press the settings button\n3. Press the sounds button\n4. Crash the game";
275311
#endif
276312

277-
bugReportPanel.SetActive(true);
313+
BugReportPanel.SetActive(true);
278314
}
279315

280316
// Sets screenshot path to be uploaded. Useful on manual invocation of bug report UI.
@@ -290,8 +326,8 @@ public void AddLogFile(string path, bool removeAfterUpload)
290326

291327
void SubmitBugReport()
292328
{
293-
string description = descriptionField.text;
294-
string steps = stepsField.text;
329+
string description = DescriptionField.text;
330+
string steps = StepsField.text;
295331

296332
// Filter screenshots and logs based on toggle state
297333
List<Issue.ScreenshotFileReference> screenshots = null;
@@ -309,45 +345,45 @@ void SubmitBugReport()
309345
logFiles = new List<Issue.LogFileReference>(_logFiles);
310346

311347
// Add logger log file if it exists
312-
if (includePlayerLog && !string.IsNullOrEmpty(logger.LogPath) && File.Exists(logger.LogPath))
348+
if (IncludePlayerLog && !string.IsNullOrEmpty(_logger.LogPath) && File.Exists(_logger.LogPath))
313349
{
314350
// skip if size over 200MB
315-
if (new FileInfo(logger.LogPath).Length < 200 * 1024 * 1024)
351+
if (new FileInfo(_logger.LogPath).Length < 200 * 1024 * 1024)
316352
{
317-
logFiles.Add(new Issue.LogFileReference { path = logger.LogPath, removeAfterUpload = false });
353+
logFiles.Add(new Issue.LogFileReference { path = _logger.LogPath, removeAfterUpload = false });
318354
}
319355
}
320356
}
321357

322-
if (includeVideo && IncludeVideoToggle.isOn)
358+
if (IncludeVideo && IncludeVideoToggle.isOn)
323359
{
324360
gameRecorder = _gameRecorder;
325361
}
326362

327363
// Create Issue instance and post it
328-
Issue issue = new Issue(submitEndpoint, projectID, authToken, messagePanelUI, reportSubmittedUI, gameRecorder);
364+
Issue issue = new Issue(SubmitEndpoint, ProjectID, AuthToken, MessagePanelUI, ReportSubmittedUI, gameRecorder);
329365
_issues.Add(issue);
330366

331367

332368
Action<ErrorMessage> onIssueError = (ErrorMessage errorMessage) =>
333369
{
334370
try {
335371
// error, get ready to try again
336-
submitButton.interactable = true;
337-
submitButton.GetComponentInChildren<TMP_Text>().text = "Submit";
372+
SubmitButton.interactable = true;
373+
SubmitButton.GetComponentInChildren<TMP_Text>().text = "Submit";
338374

339375
if (errorMessage.exception != null)
340376
{
341377
Debug.LogError("Error submitting bug report: " + errorMessage.exception);
342-
messagePanelUI.ShowMessagePanel("Error", "Error submitting bug report. Please try again later.");
378+
MessagePanelUI.ShowMessagePanel("Error", "Error submitting bug report. Please try again later.");
343379
}
344380
else if (!string.IsNullOrEmpty(errorMessage.error))
345381
{
346-
messagePanelUI.ShowMessagePanel("Error", errorMessage.error);
382+
MessagePanelUI.ShowMessagePanel("Error", errorMessage.error);
347383
}
348384
else
349385
{
350-
messagePanelUI.ShowMessagePanel("Error", "Unknown error submitting bug report. Please try again later.");
386+
MessagePanelUI.ShowMessagePanel("Error", "Unknown error submitting bug report. Please try again later.");
351387
}
352388
}
353389
catch (Exception e)
@@ -361,20 +397,20 @@ void SubmitBugReport()
361397
issue.PostIssue(description, steps, screenshots, logFiles, false,
362398
(issueId) => // successful post
363399
{
364-
submitButton.interactable = true;
365-
submitButton.GetComponentInChildren<TMP_Text>().text = "Submit";
400+
SubmitButton.interactable = true;
401+
SubmitButton.GetComponentInChildren<TMP_Text>().text = "Submit";
366402

367403
// Clear lists after successful upload
368404
_screenshots.Clear();
369405
_logFiles.Clear();
370406

371407
// show the report submitted UI
372-
reportSubmittedUI.Show(issue, defaultEmailAddress);
408+
ReportSubmittedUI.Show(issue, DefaultEmailAddress);
373409

374410
// hide bug report panel
375-
bugReportPanel.SetActive(false);
411+
BugReportPanel.SetActive(false);
376412
},
377-
mediaUploadType,
413+
MediaUploadType,
378414
(error) =>
379415
{
380416
onIssueError(new ErrorMessage { error = error });
@@ -388,8 +424,8 @@ void SubmitBugReport()
388424
}
389425
});
390426

391-
submitButton.interactable = false;
392-
submitButton.GetComponentInChildren<TMP_Text>().text = "Submitting...";
427+
SubmitButton.interactable = false;
428+
SubmitButton.GetComponentInChildren<TMP_Text>().text = "Submitting...";
393429
}
394430

395431
class ErrorMessage {

0 commit comments

Comments
 (0)