diff --git a/editor/app/src/AnalyticsPlayModeSetup.cs b/editor/app/src/AnalyticsPlayModeSetup.cs new file mode 100644 index 00000000..83aa55c2 --- /dev/null +++ b/editor/app/src/AnalyticsPlayModeSetup.cs @@ -0,0 +1,49 @@ +using System; +using System.IO; +using UnityEditor; +using UnityEngine; + +namespace Firebase.Editor { + +[InitializeOnLoad] +internal static class AnalyticsPlayModeSetup { + private const string DestinationDir = "./"; + + static AnalyticsPlayModeSetup() { + EditorApplication.playModeStateChanged += OnPlayModeStateChanged; + } + + private static void OnPlayModeStateChanged(PlayModeStateChange state) { + if (state == PlayModeStateChange.EnteredPlayMode) { + if (Application.platform == RuntimePlatform.WindowsEditor) { + Type firebaseAnalyticsType = Type.GetType("Firebase.Analytics.FirebaseAnalytics, Firebase.Analytics"); + if (firebaseAnalyticsType != null) { + if (File.Exists("./analytics_win.dll")) { + string fullSourcePath = Path.GetFullPath("./analytics_win.dll"); + // string destinationDirectory = "./"; // This is DestinationDir + string fullDestinationPath = Path.GetFullPath(Path.Combine(DestinationDir, "analytics_win.dll")); + + if (fullSourcePath.Equals(fullDestinationPath, StringComparison.OrdinalIgnoreCase)) { + Debug.Log("Firebase Analytics: analytics_win.dll is already in the project root. No copy needed for Play Mode."); + return; + } + + try { + Directory.CreateDirectory(DestinationDir); // Should be benign for "./" + string destinationDllPath = Path.Combine(DestinationDir, "analytics_win.dll"); + File.Copy("./analytics_win.dll", destinationDllPath, true); + Debug.Log("Firebase Analytics: Copied analytics_win.dll to project root for Play Mode."); + } catch (Exception e) { + Debug.LogError("Firebase Analytics: Error copying analytics_win.dll for Play Mode: " + e.Message); + } + } else { + // Optional: Log if source DLL is not found, as it might be expected if Analytics is not used. + // Debug.LogWarning("Firebase Analytics: Source DLL ./analytics_win.dll not found. Skipping Play Mode setup."); + } + } + } + } + } +} + +} // namespace Firebase.Editor diff --git a/editor/app/src/DllLocationPatcher.cs b/editor/app/src/DllLocationPatcher.cs index 70687f87..12cf6a05 100644 --- a/editor/app/src/DllLocationPatcher.cs +++ b/editor/app/src/DllLocationPatcher.cs @@ -91,6 +91,32 @@ internal static void OnPostProcessDllLocation( } } + [PostProcessBuildAttribute(BUILD_ORDER_PATCH_PROJECT)] + internal static void OnPostProcessBuildWindowsAnalytics( + BuildTarget buildTarget, string pathToBuiltProject) { + if (buildTarget == BuildTarget.StandaloneWindows || + buildTarget == BuildTarget.StandaloneWindows64) { + Type firebaseAnalyticsType = Type.GetType("Firebase.Analytics.FirebaseAnalytics, Firebase.Analytics"); + if (firebaseAnalyticsType != null) { + string sourceDllPath = "./analytics_win.dll"; + if (System.IO.File.Exists(sourceDllPath)) { + try { + string destinationDirectory = Path.Combine( + Path.GetDirectoryName(pathToBuiltProject), + Path.GetFileNameWithoutExtension(pathToBuiltProject) + "_Data", + "Plugins"); + System.IO.Directory.CreateDirectory(destinationDirectory); + string destinationDllPath = Path.Combine(destinationDirectory, "analytics_win.dll"); + System.IO.File.Copy(sourceDllPath, destinationDllPath, true); + Debug.Log("Firebase Analytics: Copied analytics_win.dll to build plugins directory."); + } catch (System.Exception e) { + Debug.LogError("Firebase Analytics: Error copying analytics_win.dll for build: " + e.Message); + } + } + } + } + } + internal static void CopyLibrary( string srcFolder, string dstFolder, string prefix, string extension) { Debug.Log("Post process to patch App." + extension + "'s location");