Skip to content

Commit 5cb679d

Browse files
committed
breadcrumbs on button clicks
1 parent a83b0bc commit 5cb679d

File tree

5 files changed

+101
-13
lines changed

5 files changed

+101
-13
lines changed

Directory.Build.props

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,63 @@
4343
<Error Condition="'$(UnityManagedPath)' == ''" Text="'UnityManagedPath' not defined. Can't find UnityEngine.dll."></Error>
4444
<Error Condition="!Exists('$(UnityManagedPath)/UnityEngine.dll')" Text="Couldn't find UnityEngine at $(UnityManagedPath)/UnityEngine.dll."></Error>
4545
<ItemGroup>
46+
<!-- <Reference Include="UnityEngine">-->
47+
<!-- <HintPath>$(UnityManagedPath)/UnityEngine.dll</HintPath>-->
48+
<!-- <Private>false</Private>-->
49+
<!-- </Reference>-->
4650
<Reference Include="UnityEngine">
47-
<HintPath>$(UnityManagedPath)/UnityEngine.dll</HintPath>
51+
<HintPath>$(UnityManagedPath)/UnityEngine/UnityEngine.dll</HintPath>
4852
<Private>false</Private>
4953
</Reference>
54+
<Reference Include="UnityEngine.CoreModule">
55+
<HintPath>$(UnityManagedPath)/UnityEngine/UnityEngine.CoreModule.dll</HintPath>
56+
<Private>false</Private>
57+
</Reference>
58+
<Reference Include="UnityEngine.IMGUIModule">
59+
<HintPath>$(UnityManagedPath)/UnityEngine/UnityEngine.IMGUIModule.dll</HintPath>
60+
<Private>false</Private>
61+
</Reference>
62+
<Reference Include="UnityEngine.ImageConversionModule">
63+
<HintPath>$(UnityManagedPath)/UnityEngine/UnityEngine.ImageConversionModule.dll</HintPath>
64+
<Private>false</Private>
65+
</Reference>
66+
<Reference Include="UnityEngine.JSONSerializeModule">
67+
<HintPath>$(UnityManagedPath)/UnityEngine/UnityEngine.JSONSerializeModule.dll</HintPath>
68+
<Private>false</Private>
69+
</Reference>
70+
<Reference Include="UnityEngine.ScreenCaptureModule">
71+
<HintPath>$(UnityManagedPath)/UnityEngine/UnityEngine.ScreenCaptureModule.dll</HintPath>
72+
<Private>false</Private>
73+
</Reference>
74+
<Reference Include="UnityEngine.UnityWebRequestModule">
75+
<HintPath>$(UnityManagedPath)/UnityEngine/UnityEngine.UnityWebRequestModule.dll</HintPath>
76+
<Private>false</Private>
77+
</Reference>
78+
79+
<Reference Include="UnityEngine.AndroidJNIModule">
80+
<HintPath>$(UnityManagedPath)/UnityEngine/UnityEngine.AndroidJNIModule.dll</HintPath>
81+
<Private>false</Private>
82+
</Reference>
83+
84+
<Reference Include="UnityEngine.UnityAnalyticsModule">
85+
<HintPath>$(UnityManagedPath)/UnityEngine/UnityEngine.UnityAnalyticsModule.dll</HintPath>
86+
<Private>false</Private>
87+
</Reference>
88+
89+
<Reference Include="UnityEngine.InputLegacyModule">
90+
<HintPath>$(UnityManagedPath)/UnityEngine/UnityEngine.InputLegacyModule.dll</HintPath>
91+
<Private>false</Private>
92+
</Reference>
93+
94+
<Reference Include="UnityEngine.ProfilerModule">
95+
<HintPath>$(UnityManagedPath)/UnityEngine/UnityEngine.ProfilerModule.dll</HintPath>
96+
<Private>false</Private>
97+
</Reference>
98+
99+
<!-- <Reference Include="UnityEngine.UI">-->
100+
<!-- <HintPath>$(UnityTemplateAssemblyPath)/UnityEngine.UI.dll</HintPath>-->
101+
<!-- <Private>false</Private>-->
102+
<!-- </Reference>-->
50103
</ItemGroup>
51104
</Target>
52105
</Project>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using UnityEditor.Build;
2+
using UnityEditor.Build.Reporting;
3+
using UnityEditor.Events;
4+
using UnityEngine.Events;
5+
using UnityEngine.SceneManagement;
6+
using UnityEngine.UI;
7+
8+
namespace Sentry.Unity.Editor
9+
{
10+
public class ButtonInstrumentation : IProcessSceneWithReport
11+
{
12+
public int callbackOrder { get; } = 0;
13+
14+
public void OnProcessScene(Scene scene, BuildReport report)
15+
{
16+
var gameObjects = scene.GetRootGameObjects();
17+
if (gameObjects is { Length: > 0 })
18+
{
19+
var sentryScene = gameObjects[0].AddComponent<SentryScene>();
20+
21+
foreach (var gameObject in gameObjects)
22+
{
23+
var buttons = gameObject.GetComponentsInChildren<Button>();
24+
foreach (var button in buttons)
25+
{
26+
var unityAction = new UnityAction<string>(sentryScene.AddButtonBreadcrumb);
27+
UnityEventTools.AddStringPersistentListener(button.onClick, unityAction, button.gameObject.name);
28+
}
29+
}
30+
}
31+
}
32+
}
33+
}

src/Sentry.Unity.Editor/Sentry.Unity.Editor.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
<HintPath>$(UnityManagedPath)/UnityEditor.dll</HintPath>
2121
<Private>false</Private>
2222
</Reference>
23+
<Reference Include="UnityEngine.UI">
24+
<HintPath>$(UnityTemplateAssemblyPath)/UnityEngine.UI.dll</HintPath>
25+
<Private>false</Private>
26+
</Reference>
2327
</ItemGroup>
2428
</Target>
2529
</Project>

src/Sentry.Unity/SentryScene.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using UnityEngine;
2+
3+
namespace Sentry.Unity
4+
{
5+
public class SentryScene : MonoBehaviour
6+
{
7+
public void AddButtonBreadcrumb(string message)
8+
=> SentrySdk.AddBreadcrumb(message, "unity.ui.button");
9+
}
10+
}

test/Directory.Build.props

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,6 @@
3030
<HintPath>$(UnityTemplateAssemblyPath)/UnityEngine.TestRunner.dll</HintPath>
3131
<Private>false</Private>
3232
</Reference>
33-
34-
<!-- TODO: The parent directory contains a 'UnityEngine.dll' but that one is different? But if that one does not get -->
35-
<!-- referenced here and we just add the CoreModule it leads to 'ambiguous references' and 'Type exists in both -->
36-
<!-- 'UnityEngine.CoreModule and UnityEngine' -->
37-
<Reference Include="UnityEngine">
38-
<HintPath>$(UnityManagedPath)/UnityEngine/UnityEngine.dll</HintPath>
39-
<Private>false</Private>
40-
</Reference>
41-
<Reference Include="UnityEngine.CoreModule">
42-
<HintPath>$(UnityManagedPath)/UnityEngine/UnityEngine.CoreModule.dll</HintPath>
43-
<Private>false</Private>
44-
</Reference>
4533
</ItemGroup>
4634
<Error Condition="!Exists('$(UnityTemplateAssemblyPath)/UnityEngine.TestRunner.dll')" Text="TestRunner not found. Expected: $(UnityTemplateAssemblyPath)/UnityEngine.TestRunner.dll"></Error>
4735
</Target>

0 commit comments

Comments
 (0)