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 ;
@@ -20,6 +22,9 @@ public enum LogLevel { Debug, Warning, Error, Trace, Info, Fatal };
2022#if UNITY_ANDROID && ! UNITY_EDITOR
2123 private static AndroidJavaClass bugfender ;
2224#elif UNITY_IOS && ! UNITY_EDITOR
25+ [ DllImport ( "__Internal" ) ]
26+ private static extern void BugfenderSetSDKType ( string sdkType , int version ) ;
27+
2328 [ DllImport ( "__Internal" ) ]
2429 private static extern void BugfenderActivateLogger ( string key , bool printToConsole , bool hideDeviceName , string apiURL , string baseURL ) ;
2530
@@ -69,6 +74,18 @@ public enum LogLevel { Debug, Warning, Error, Trace, Info, Fatal };
6974 // Automatically called when scene starts
7075 void Start ( )
7176 {
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+ }
7289 Debug . Log ( "[BF] *** INITIALIZING BUGFENDER ***" ) ;
7390#if UNITY_ANDROID && ! UNITY_EDITOR
7491 if ( bugfender == null ) {
@@ -77,8 +94,11 @@ void Start()
7794
7895 bugfender = new AndroidJavaClass ( "com.bugfender.sdk.Bugfender" ) ;
7996 if ( bugfender != null ) {
80- // Set SDK type before initialization
81- bugfender . CallStatic ( "setSDKType" , "unity" , SDK_VERSION ) ;
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+ }
82102 if ( HIDE_DEVICE_NAME ) {
83103 bugfender . CallStatic ( "overrideDeviceName" , "Unknown" ) ;
84104 }
@@ -96,14 +116,18 @@ void Start()
96116 if ( ENABLE_CRASH_REPORTING ) {
97117 bugfender . CallStatic ( "enableCrashReporting" ) ;
98118 }
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+ }
99124 //bugfender.CallStatic ("enableLogcatLogging"); // optional, uncomment if you want it (Android only)
100125 }
101126
102127 }
103128 }
104129#elif UNITY_IOS && ! UNITY_EDITOR
105- // Set SDK type before initialization
106- BugfenderSetSDKType ( "unity" , SDK_VERSION ) ;
130+ BugfenderSetSDKType ( SDK_TYPE , SDK_TYPE_VERSION ) ;
107131 BugfenderActivateLogger ( APP_KEY , PRINT_TO_CONSOLE , HIDE_DEVICE_NAME , API_URL , BASE_URL ) ;
108132 if ( ENABLE_UI_EVENT_LOGGING ) {
109133 BugfenderEnableUIEventLogging ( ) ;
@@ -295,4 +319,4 @@ public static void SetSDKType(string sdkType, int version)
295319#endif
296320 }
297321
298- }
322+ }
0 commit comments