Skip to content

Copy GA DLL for Windows Build and Play Mode if it exists #1271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
43 changes: 43 additions & 0 deletions editor/app/src/AnalyticsPlayModeSetup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file needs to be added to the editor/app/CMakeLists.txt

using System.IO;
using UnityEditor;
using UnityEngine;

namespace Firebase.Editor {

[InitializeOnLoad]
internal static class AnalyticsPlayModeSetup {
private const string SourceDllPath = "./analytics_win.dll";
private const string DestinationDir = "Assets/Plugins/";
private const string DestinationDllName = "analytics_win.dll";

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(SourceDllPath)) {
try {
Directory.CreateDirectory(DestinationDir);
string destinationDllPath = Path.Combine(DestinationDir, DestinationDllName);
File.Copy(SourceDllPath, destinationDllPath, true);
Debug.Log("Firebase Analytics: Copied " + DestinationDllName + " to " + DestinationDir + " for Play Mode.");
AssetDatabase.Refresh();
} catch (Exception e) {
Debug.LogError("Firebase Analytics: Error copying " + DestinationDllName + " 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 " + SourceDllPath + " not found. Skipping Play Mode setup.");
}
}
}
}
}
}

} // namespace Firebase.Editor
22 changes: 22 additions & 0 deletions editor/app/src/DllLocationPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,28 @@ 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)) {
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.");
}
}
}
}

internal static void CopyLibrary(
string srcFolder, string dstFolder, string prefix, string extension) {
Debug.Log("Post process to patch App." + extension + "'s location");
Expand Down