|
| 1 | +using System; |
| 2 | +using System.IO; |
| 3 | +using UnityEditor; |
| 4 | +using UnityEngine; |
| 5 | + |
| 6 | +namespace Firebase.Editor { |
| 7 | + |
| 8 | +[InitializeOnLoad] |
| 9 | +internal static class AnalyticsPlayModeSetup { |
| 10 | + private const string SourceDllPath = "./analytics_win.dll"; |
| 11 | + private const string DestinationDir = "Assets/Plugins/"; |
| 12 | + private const string DestinationDllName = "analytics_win.dll"; |
| 13 | + |
| 14 | + static AnalyticsPlayModeSetup() { |
| 15 | + EditorApplication.playModeStateChanged += OnPlayModeStateChanged; |
| 16 | + } |
| 17 | + |
| 18 | + private static void OnPlayModeStateChanged(PlayModeStateChange state) { |
| 19 | + if (state == PlayModeStateChange.EnteredPlayMode) { |
| 20 | + if (Application.platform == RuntimePlatform.WindowsEditor) { |
| 21 | + Type firebaseAnalyticsType = Type.GetType("Firebase.Analytics.FirebaseAnalytics, Firebase.Analytics"); |
| 22 | + if (firebaseAnalyticsType != null) { |
| 23 | + if (File.Exists(SourceDllPath)) { |
| 24 | + try { |
| 25 | + Directory.CreateDirectory(DestinationDir); |
| 26 | + string destinationDllPath = Path.Combine(DestinationDir, DestinationDllName); |
| 27 | + File.Copy(SourceDllPath, destinationDllPath, true); |
| 28 | + Debug.Log("Firebase Analytics: Copied " + DestinationDllName + " to " + DestinationDir + " for Play Mode."); |
| 29 | + AssetDatabase.Refresh(); |
| 30 | + } catch (Exception e) { |
| 31 | + Debug.LogError("Firebase Analytics: Error copying " + DestinationDllName + " for Play Mode: " + e.Message); |
| 32 | + } |
| 33 | + } else { |
| 34 | + // Optional: Log if source DLL is not found, as it might be expected if Analytics is not used. |
| 35 | + // Debug.LogWarning("Firebase Analytics: Source DLL " + SourceDllPath + " not found. Skipping Play Mode setup."); |
| 36 | + } |
| 37 | + } |
| 38 | + } |
| 39 | + } |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +} // namespace Firebase.Editor |
0 commit comments