1- using UnityEngine ;
1+ using UnityEngine ;
22using System . Runtime . InteropServices ;
33using UnityEngine . Diagnostics ;
44
55public class Bugfender : MonoBehaviour {
6+ private const string SDK_TYPE = "unity" ;
7+ private const int SDK_TYPE_VERSION = 30000 ;
68
79 public string APP_KEY ;
810 public bool ENABLE_UI_EVENT_LOGGING = false ;
@@ -15,9 +17,14 @@ public class Bugfender : MonoBehaviour {
1517
1618 public enum LogLevel { Debug , Warning , Error , Trace , Info , Fatal } ;
1719
20+ private const int SDK_VERSION = 20260119 ;
21+
1822#if UNITY_ANDROID && ! UNITY_EDITOR
1923 private static AndroidJavaClass bugfender ;
2024#elif UNITY_IOS && ! UNITY_EDITOR
25+ [ DllImport ( "__Internal" ) ]
26+ private static extern void BugfenderSetSDKType ( string sdkType , int version ) ;
27+
2128 [ DllImport ( "__Internal" ) ]
2229 private static extern void BugfenderActivateLogger ( string key , bool printToConsole , bool hideDeviceName , string apiURL , string baseURL ) ;
2330
@@ -59,11 +66,26 @@ public enum LogLevel { Debug, Warning, Error, Trace, Info, Fatal };
5966
6067 [ DllImport ( "__Internal" ) ]
6168 private static extern void BugfenderForceSendOnce ( ) ;
69+
70+ [ DllImport ( "__Internal" ) ]
71+ private static extern void BugfenderSetSDKType ( string sdkType , int version ) ;
6272#endif
6373
6474 // Automatically called when scene starts
6575 void Start ( )
6676 {
77+ // Optional override from Resources/bugfender_app_key.txt (e.g. for CI or per-build config)
78+ var keyAsset = Resources . Load < TextAsset > ( "bugfender_app_key" ) ;
79+ if ( keyAsset != null && ! string . IsNullOrWhiteSpace ( keyAsset . text ) )
80+ {
81+ APP_KEY = keyAsset . text . Trim ( ) ;
82+ }
83+ // Optional: set Resources/bugfender_print_to_console.txt to "true" to mirror logs to logcat (Android) / Xcode console (iOS)
84+ var printAsset = Resources . Load < TextAsset > ( "bugfender_print_to_console" ) ;
85+ if ( printAsset != null && string . Equals ( printAsset . text . Trim ( ) , "true" , System . StringComparison . OrdinalIgnoreCase ) )
86+ {
87+ PRINT_TO_CONSOLE = true ;
88+ }
6789 Debug . Log ( "[BF] *** INITIALIZING BUGFENDER ***" ) ;
6890#if UNITY_ANDROID && ! UNITY_EDITOR
6991 if ( bugfender == null ) {
@@ -72,6 +94,11 @@ void Start()
7294
7395 bugfender = new AndroidJavaClass ( "com.bugfender.sdk.Bugfender" ) ;
7496 if ( bugfender != null ) {
97+ try {
98+ bugfender . CallStatic ( "setSDKType" , SDK_TYPE , SDK_TYPE_VERSION ) ;
99+ } catch ( AndroidJavaException ) {
100+ Debug . LogWarning ( "[BF] Bugfender.setSDKType is not available in the Android SDK." ) ;
101+ }
75102 if ( HIDE_DEVICE_NAME ) {
76103 bugfender . CallStatic ( "overrideDeviceName" , "Unknown" ) ;
77104 }
@@ -89,12 +116,18 @@ void Start()
89116 if ( ENABLE_CRASH_REPORTING ) {
90117 bugfender . CallStatic ( "enableCrashReporting" ) ;
91118 }
119+ // Optional: set Resources/bugfender_debug.txt to "true" to enable native SDK debug logs (tag BF/DEBUG in logcat)
120+ var debugAsset = Resources . Load < TextAsset > ( "bugfender_debug" ) ;
121+ if ( debugAsset != null && string . Equals ( debugAsset . text . Trim ( ) , "true" , System . StringComparison . OrdinalIgnoreCase ) ) {
122+ try { bugfender . CallStatic ( "setDebugMode" , true ) ; } catch ( AndroidJavaException ) { /* ignore if not available */ }
123+ }
92124 //bugfender.CallStatic ("enableLogcatLogging"); // optional, uncomment if you want it (Android only)
93125 }
94126
95127 }
96128 }
97129#elif UNITY_IOS && ! UNITY_EDITOR
130+ BugfenderSetSDKType ( SDK_TYPE , SDK_TYPE_VERSION ) ;
98131 BugfenderActivateLogger ( APP_KEY , PRINT_TO_CONSOLE , HIDE_DEVICE_NAME , API_URL , BASE_URL ) ;
99132 if ( ENABLE_UI_EVENT_LOGGING ) {
100133 BugfenderEnableUIEventLogging ( ) ;
@@ -273,4 +306,17 @@ public static void ForceSendOnce()
273306#endif
274307 }
275308
276- }
309+ public static void SetSDKType ( string sdkType , int version )
310+ {
311+ #if UNITY_ANDROID && ! UNITY_EDITOR
312+ if ( bugfender != null ) {
313+ bugfender . CallStatic ( "setSDKType" , sdkType , version ) ;
314+ }
315+ #elif UNITY_IOS && ! UNITY_EDITOR
316+ BugfenderSetSDKType ( sdkType , version ) ;
317+ #else
318+ Debug . Log ( "[BF] Set SDK type: " + sdkType + " version: " + version ) ;
319+ #endif
320+ }
321+
322+ }
0 commit comments