Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Breadcrumbs on button clicks #864

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
55 changes: 54 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,63 @@
<Error Condition="'$(UnityManagedPath)' == ''" Text="'UnityManagedPath' not defined. Can't find UnityEngine.dll."></Error>
<Error Condition="!Exists('$(UnityManagedPath)/UnityEngine.dll')" Text="Couldn't find UnityEngine at $(UnityManagedPath)/UnityEngine.dll."></Error>
<ItemGroup>
<!-- <Reference Include="UnityEngine">-->
<!-- <HintPath>$(UnityManagedPath)/UnityEngine.dll</HintPath>-->
Copy link
Contributor Author

Choose a reason for hiding this comment

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

That here needs some cleaning up but the gist of it is: ManagedPath/UnityEngine.dll on the managed root contains all the type forwarders to the modules inside of ManagedPath/UnityEngine/. This does not seem to work 100% of the time like with LogAssert in the test projs. Instead, we could just reference the individual modules.

<!-- <Private>false</Private>-->
<!-- </Reference>-->
<Reference Include="UnityEngine">
<HintPath>$(UnityManagedPath)/UnityEngine.dll</HintPath>
<HintPath>$(UnityManagedPath)/UnityEngine/UnityEngine.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>$(UnityManagedPath)/UnityEngine/UnityEngine.CoreModule.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="UnityEngine.IMGUIModule">
<HintPath>$(UnityManagedPath)/UnityEngine/UnityEngine.IMGUIModule.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="UnityEngine.ImageConversionModule">
<HintPath>$(UnityManagedPath)/UnityEngine/UnityEngine.ImageConversionModule.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="UnityEngine.JSONSerializeModule">
<HintPath>$(UnityManagedPath)/UnityEngine/UnityEngine.JSONSerializeModule.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="UnityEngine.ScreenCaptureModule">
<HintPath>$(UnityManagedPath)/UnityEngine/UnityEngine.ScreenCaptureModule.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="UnityEngine.UnityWebRequestModule">
<HintPath>$(UnityManagedPath)/UnityEngine/UnityEngine.UnityWebRequestModule.dll</HintPath>
<Private>false</Private>
</Reference>

<Reference Include="UnityEngine.AndroidJNIModule">
<HintPath>$(UnityManagedPath)/UnityEngine/UnityEngine.AndroidJNIModule.dll</HintPath>
<Private>false</Private>
</Reference>

<Reference Include="UnityEngine.UnityAnalyticsModule">
<HintPath>$(UnityManagedPath)/UnityEngine/UnityEngine.UnityAnalyticsModule.dll</HintPath>
<Private>false</Private>
</Reference>

<Reference Include="UnityEngine.InputLegacyModule">
<HintPath>$(UnityManagedPath)/UnityEngine/UnityEngine.InputLegacyModule.dll</HintPath>
<Private>false</Private>
</Reference>

<Reference Include="UnityEngine.ProfilerModule">
<HintPath>$(UnityManagedPath)/UnityEngine/UnityEngine.ProfilerModule.dll</HintPath>
<Private>false</Private>
</Reference>

<!-- <Reference Include="UnityEngine.UI">-->
<!-- <HintPath>$(UnityTemplateAssemblyPath)/UnityEngine.UI.dll</HintPath>-->
<!-- <Private>false</Private>-->
<!-- </Reference>-->
</ItemGroup>
</Target>
</Project>
33 changes: 33 additions & 0 deletions src/Sentry.Unity.Editor/ButtonInstrumentation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEditor.Events;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

namespace Sentry.Unity.Editor
{
public class ButtonInstrumentation : IProcessSceneWithReport
{
public int callbackOrder { get; } = 0;

public void OnProcessScene(Scene scene, BuildReport report)
{
var gameObjects = scene.GetRootGameObjects();
if (gameObjects is { Length: > 0 })
{
var sentryScene = gameObjects[0].AddComponent<SentryScene>();

foreach (var gameObject in gameObjects)
{
var buttons = gameObject.GetComponentsInChildren<Button>();
foreach (var button in buttons)
{
var unityAction = new UnityAction<string>(sentryScene.AddButtonBreadcrumb);
UnityEventTools.AddStringPersistentListener(button.onClick, unityAction, button.gameObject.name);
}
}
}
}
}
}
4 changes: 4 additions & 0 deletions src/Sentry.Unity.Editor/Sentry.Unity.Editor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
<HintPath>$(UnityManagedPath)/UnityEditor.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>$(UnityTemplateAssemblyPath)/UnityEngine.UI.dll</HintPath>
<Private>false</Private>
</Reference>
</ItemGroup>
</Target>
</Project>
10 changes: 10 additions & 0 deletions src/Sentry.Unity/SentryScene.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using UnityEngine;

namespace Sentry.Unity
{
public class SentryScene : MonoBehaviour
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding a callback to a button relies on a MonoBehaviour being a permanent part of the scene. SentryMonoBehaviour get created during runtime and the callback would fail.

{
public void AddButtonBreadcrumb(string message)
=> SentrySdk.AddBreadcrumb(message, "unity.ui.button");
}
}
12 changes: 0 additions & 12 deletions test/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,6 @@
<HintPath>$(UnityTemplateAssemblyPath)/UnityEngine.TestRunner.dll</HintPath>
<Private>false</Private>
</Reference>

<!-- TODO: The parent directory contains a 'UnityEngine.dll' but that one is different? But if that one does not get -->
<!-- referenced here and we just add the CoreModule it leads to 'ambiguous references' and 'Type exists in both -->
<!-- 'UnityEngine.CoreModule and UnityEngine' -->
<Reference Include="UnityEngine">
<HintPath>$(UnityManagedPath)/UnityEngine/UnityEngine.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>$(UnityManagedPath)/UnityEngine/UnityEngine.CoreModule.dll</HintPath>
<Private>false</Private>
</Reference>
</ItemGroup>
<Error Condition="!Exists('$(UnityTemplateAssemblyPath)/UnityEngine.TestRunner.dll')" Text="TestRunner not found. Expected: $(UnityTemplateAssemblyPath)/UnityEngine.TestRunner.dll"></Error>
</Target>
Expand Down