Skip to content
Open
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
108 changes: 80 additions & 28 deletions Runtime/Scripts/BugReportUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ namespace BetaHub
public class BugReportUI : MonoBehaviour
{
private static BugReportUI instance;

public GameObject bugReportPanel;
public TMP_InputField descriptionField;
public TMP_InputField stepsField;

public Toggle IncludeVideoToggle;
public Toggle IncludeScreenshotToggle;
public Toggle IncludePlayerLogToggle;
Expand All @@ -35,18 +35,17 @@ public class BugReportUI : MonoBehaviour

public string projectID;

#if ENABLE_INPUT_SYSTEM
#if ENABLE_INPUT_SYSTEM
public InputAction shortcutAction = new InputAction("BugReportShortcut", binding: "<Keyboard>/f12");
#else
#else
public KeyCode shortcutKey = KeyCode.F12;
#endif

public bool includePlayerLog = true;
public bool includeVideo = true;
#endif

public UnityEvent OnBugReportWindowShown;
public UnityEvent OnBugReportWindowHidden;

private bool includePlayerLog = true;
private bool includeVideo = true;
private List<ScreenshotFileReference> _screenshots = new List<ScreenshotFileReference>();
private List<LogFileReference> _logFiles = new List<LogFileReference>();

Expand All @@ -59,12 +58,14 @@ public class BugReportUI : MonoBehaviour
// if true, the report is being uploaded, some processes should be paused
private bool _uploadingReport = false;

private DefaultSettings _defaultSettings;

[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
private static void InitializeLogger()
{
logger = new Logger();
}

void Awake()
{
if (instance == null)
Expand All @@ -75,34 +76,38 @@ void Awake()
{
Destroy(gameObject);
}


messagePanel.SetActive(false);
SaveDefaultValue();
}

void OnEnable()
{
#if ENABLE_INPUT_SYSTEM
#if ENABLE_INPUT_SYSTEM
if (IsNewInputSystemEnabled())
{
shortcutAction.Enable();
shortcutAction.performed += OnShortcutActionPerformed;
}
#endif
#endif
}

void OnDisable()
{
#if ENABLE_INPUT_SYSTEM
#if ENABLE_INPUT_SYSTEM
if (IsNewInputSystemEnabled())
{
shortcutAction.performed -= OnShortcutActionPerformed;
shortcutAction.Disable();
}
#endif
#endif
}

void Start()
{
_gameRecorder = GetComponent<GameRecorder>();

bugReportPanel.SetActive(false);
submitButton.onClick.AddListener(SubmitBugReport);
closeButton.onClick.AddListener(() =>
Expand Down Expand Up @@ -163,13 +168,13 @@ void Update()
{
RestoreCursorState();
}
#if !ENABLE_INPUT_SYSTEM

#if !ENABLE_INPUT_SYSTEM
if (shortcutKey != KeyCode.None && Input.GetKeyDown(shortcutKey))
{
StartCoroutine(CaptureScreenshotAndShowUI());
}
#endif
#endif
}

private bool SholdBeRecordingVideo()
Expand Down Expand Up @@ -201,7 +206,7 @@ private void RestoreCursorState()
}
}

#if ENABLE_INPUT_SYSTEM
#if ENABLE_INPUT_SYSTEM
void OnShortcutActionPerformed(InputAction.CallbackContext context)
{
StartCoroutine(CaptureScreenshotAndShowUI());
Expand All @@ -212,22 +217,40 @@ bool IsNewInputSystemEnabled()
// Check if the new input system is enabled
return InputSystem.settings != null;
}
#endif
#endif

IEnumerator CaptureScreenshotAndShowUI()
{
// Capture screenshot
// Wait for the end of the frame to ensure the screen is fully rendered
yield return new WaitForEndOfFrame();

// Capture the screenshot as a texture after the frame has been rendered
Texture2D texture = ScreenCapture.CaptureScreenshotAsTexture();

// Apply the filters (including DrawBox) to the RenderTexture
Texture2D screenshot = ApplyFiltersToScreenshot(texture);

// Save the screenshot to a file
string screenshotPath = Application.persistentDataPath + "/screenshot.png";
ScreenCapture.CaptureScreenshot(screenshotPath);
File.WriteAllBytes(screenshotPath, screenshot.EncodeToPNG());

AddScreenshot(screenshotPath, true);

// wait for another frame
yield return null;

bugReportPanel.SetActive(true);
}

// Method to apply filters (DrawBox or others) to the screenshot
private Texture2D ApplyFiltersToScreenshot(Texture2D texture)
{
// Use the TextureFilterManager to apply filters, including DrawBox
_gameRecorder.TextureFilterManager.ApplyFilters(new TexturePainter(texture));

return texture;
}

// Sets screenshot path to be uploaded. Useful on manual invocation of bug report UI.
public void AddScreenshot(string path, bool removeAfterUpload)
{
Expand Down Expand Up @@ -274,7 +297,7 @@ IEnumerator PostIssue(string description, string steps)
{
url += "/";
}

url += "projects/" + projectID + "/issues.json";

using (UnityWebRequest www = UnityWebRequest.Post(url, form))
Expand All @@ -295,6 +318,10 @@ IEnumerator PostIssue(string description, string steps)
ErrorMessage message = JsonUtility.FromJson<ErrorMessage>(www.downloadHandler.text);
messagePanelUI.ShowMessagePanel("Error", message.error);
}
else
{
messagePanelUI.ShowMessagePanel("Error", "An unexpected error occurred. Please try again later.");
}
}
else
{
Expand All @@ -307,6 +334,7 @@ IEnumerator PostIssue(string description, string steps)
bugReportPanel.SetActive(false);
});

ResetToDefaultValue();
yield return UploadAdditionalFiles(issueId);
}
}
Expand Down Expand Up @@ -361,7 +389,7 @@ IEnumerator UploadAdditionalFiles(string issueId)

_logFiles.Clear();
}

// // Upload performance samples (if any)
// string samplesFile = Application.persistentDataPath + "/samples.csv";
// GetComponent<BH_PerformanceSampler>().SaveSamplesToFile(samplesFile);
Expand All @@ -370,7 +398,7 @@ IEnumerator UploadAdditionalFiles(string issueId)
// yield return StartCoroutine(UploadFile(issueId, "log_files", "log_file[file]", samplesFile, "text/csv"));
// File.Delete(samplesFile);
// }

// Upload video file
if (includeVideo && IncludeVideoToggle.isOn)
{
Expand Down Expand Up @@ -418,12 +446,36 @@ IEnumerator UploadFile(string issueId, string endpoint, string fieldName, string
}
}

class ErrorMessage {
// Method to save the current values as defaults
void SaveDefaultValue()
{
_defaultSettings = new DefaultSettings(
descriptionField.text,
stepsField.text,
IncludeVideoToggle.isOn,
IncludeScreenshotToggle.isOn,
IncludePlayerLogToggle.isOn
);
}

// Method to reset fields to their default values
void ResetToDefaultValue()
{
descriptionField.text = _defaultSettings.description;
stepsField.text = _defaultSettings.steps;
IncludeVideoToggle.isOn = _defaultSettings.includeVideo;
IncludeScreenshotToggle.isOn = _defaultSettings.includeScreenshot;
IncludePlayerLogToggle.isOn = _defaultSettings.includePlayerLog;
}

class ErrorMessage
{
public string error;
public string status;
}

class IssueResponse {
class IssueResponse
{
public string id;
}

Expand Down
26 changes: 26 additions & 0 deletions Runtime/Scripts/DefaultSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#if ENABLE_INPUT_SYSTEM
using UnityEngine.InputSystem;
#endif

namespace BetaHub
{
[System.Serializable]
public class DefaultSettings
{
public string description;
public string steps;
public bool includeVideo;
public bool includeScreenshot;
public bool includePlayerLog;

// Constructor to initialize default values
public DefaultSettings(string description, string steps, bool includeVideo, bool includeScreenshot, bool includePlayerLog)
{
this.description = description;
this.steps = steps;
this.includeVideo = includeVideo;
this.includeScreenshot = includeScreenshot;
this.includePlayerLog = includePlayerLog;
}
}
}
11 changes: 11 additions & 0 deletions Runtime/Scripts/DefaultSettings.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions Runtime/Scripts/Drawbox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using UnityEngine;

namespace BetaHub
{
public class DrawBox : ITextureFilter
{
// DrawBox settings
private int xPosition;
private int yPosition;
private int boxWidth;
private int boxHeight;
private Color boxColor;

// Constructor to initialize DrawBox filter
public DrawBox(int x, int y, int width, int height, Color color)
{
if (width <= 0 || height <= 0)
{
throw new System.ArgumentException("Width and height must be positive values.");
}

xPosition = x;
yPosition = y;
boxWidth = width;
boxHeight = height;
boxColor = color;
}

public DrawBox(Vector2Int position, Vector2Int size, Color color)
: this(position.x, position.y, size.x, size.y, color) { }

// Apply the filter on the texture
public void ApplyFilter(TexturePainter texture)
{
if (texture == null)
{
throw new System.ArgumentNullException(nameof(texture), "TexturePainter cannot be null.");
}

// Draw the rectangle on the texture
texture.DrawRectangle(xPosition, yPosition, boxWidth, boxHeight, boxColor);
}

}
}
11 changes: 11 additions & 0 deletions Runtime/Scripts/Drawbox.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Runtime/Scripts/GameRecorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class GameRecorder : MonoBehaviour
private float fps;
private float deltaTime = 0.0f;

public TextureFilterManager TextureFilterManager => _textureFilterManager;
private TextureFilterManager _textureFilterManager = new TextureFilterManager();

void Start()
{
// Adjust the game resolution to be divisible by 2
Expand Down Expand Up @@ -125,6 +128,8 @@ private IEnumerator CaptureFrames()
// texturePainter.DrawNumber(50, 10, (int) fps, Color.white, 4);
texturePainter.DrawNumber(5, 5, (int)fps, Color.white, 2);

_textureFilterManager.ApplyFilters(texturePainter);

byte[] frameData = screenShot.GetRawTextureData();
videoEncoder.AddFrame(frameData);
}
Expand Down
8 changes: 8 additions & 0 deletions Runtime/Scripts/ITextureFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace BetaHub
{
public interface ITextureFilter
{
// Now it applies the filter on the given texture
public void ApplyFilter(TexturePainter texture);
}
}
11 changes: 11 additions & 0 deletions Runtime/Scripts/ITextureFilter.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading