Skip to content

Commit 02fe453

Browse files
committed
update GPGS patcher to be UPM
1 parent 6db45dd commit 02fe453

25 files changed

+615
-745
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<dependencies>
2+
<androidPackages>
3+
<androidPackage spec="com.google.android.gms:play-services-games-v2:21.0.0"/>
4+
<androidPackage spec="com.google.android.gms:play-services-nearby:18.5.0"/>
5+
</androidPackages>
6+
</dependencies>

Assets/Public/GooglePlayGames/com.google.play.games/Editor/GooglePlayGamesPlugin.txt.meta renamed to Assets/Public/GooglePlayGames/com.google.play.games/Editor/Dependencies.xml.meta

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Public/GooglePlayGames/com.google.play.games/Editor/GPGSAndroidSetupUI.cs

Lines changed: 49 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ namespace GooglePlayGames.Editor
2424
using UnityEditor;
2525
using UnityEngine;
2626

27+
#if UNITY_2021_2_OR_NEWER
28+
using UnityEditor.Build;
29+
#endif
30+
2731
/// <summary>
2832
/// Google Play Game Services Setup dialog for Android.
2933
/// </summary>
@@ -57,15 +61,14 @@ public class GPGSAndroidSetupUI : EditorWindow
5761
/// <summary>
5862
/// Menus the item for GPGS android setup.
5963
/// </summary>
60-
[MenuItem("Window/Google Play Games/Setup/Android setup...", false, 1)]
64+
[MenuItem("Google/Play Games/Setup/Android setup...", false, 1)]
6165
public static void MenuItemFileGPGSAndroidSetup()
6266
{
63-
EditorWindow window = EditorWindow.GetWindow(
64-
typeof(GPGSAndroidSetupUI), true, GPGSStrings.AndroidSetup.Title);
67+
var window = EditorWindow.GetWindow<GPGSAndroidSetupUI>(true, GPGSStrings.AndroidSetup.Title);
6568
window.minSize = new Vector2(500, 400);
6669
}
6770

68-
[MenuItem("Window/Google Play Games/Setup/Android setup...", true)]
71+
[MenuItem("Google/Play Games/Setup/Android setup...", true)]
6972
public static bool EnableAndroidMenuItem()
7073
{
7174
#if UNITY_ANDROID
@@ -111,8 +114,6 @@ public static bool PerformSetup(
111114
// check the bundle id and set it if needed.
112115
CheckBundleId();
113116

114-
GPGSUtil.CheckAndFixDependencies();
115-
GPGSUtil.CheckAndFixVersionedAssestsPaths();
116117
AssetDatabase.Refresh();
117118

118119
Google.VersionHandler.VerboseLoggingEnabled = true;
@@ -162,26 +163,26 @@ public static bool PerformSetup(string webClientId, string appId, string nearbyS
162163
}
163164
}
164165

165-
// check for valid app id
166-
if (!GPGSUtil.LooksLikeValidAppId(appId) && string.IsNullOrEmpty(nearbySvcId))
167-
{
168-
GPGSUtil.Alert(GPGSStrings.Setup.AppIdError);
169-
return false;
170-
}
171-
172-
if (nearbySvcId != null)
166+
if(string.IsNullOrEmpty(nearbySvcId))
173167
{
174-
#if UNITY_ANDROID
175-
if (!NearbyConnectionUI.PerformSetup(nearbySvcId, true))
168+
// check for valid app id
169+
if (!GPGSUtil.LooksLikeValidAppId(appId))
176170
{
171+
GPGSUtil.Alert(GPGSStrings.Setup.AppIdError);
177172
return false;
178173
}
179-
#endif
180174
}
175+
#if UNITY_ANDROID
176+
else if (!NearbyConnectionUI.PerformSetup(nearbySvcId, true))
177+
{
178+
return false;
179+
}
180+
#endif
181181

182182
GPGSProjectSettings.Instance.Set(GPGSUtil.APPIDKEY, appId);
183183
GPGSProjectSettings.Instance.Set(GPGSUtil.WEBCLIENTIDKEY, webClientId);
184184
GPGSProjectSettings.Instance.Save();
185+
GPGSUtil.PatchAndroidManifest();
185186
GPGSUtil.UpdateGameInfo();
186187

187188
// check that Android SDK is there
@@ -196,7 +197,7 @@ public static bool PerformSetup(string webClientId, string appId, string nearbyS
196197
}
197198

198199
// Generate AndroidManifest.xml
199-
GPGSUtil.GenerateAndroidManifest();
200+
GPGSUtil.UpdateGameInfo();
200201

201202
// refresh assets, and we're done
202203
AssetDatabase.Refresh();
@@ -298,9 +299,8 @@ public void OnGUI()
298299
}
299300
catch (Exception e)
300301
{
301-
GPGSUtil.Alert(
302-
GPGSStrings.Error,
303-
"Invalid classname: " + e.Message);
302+
GPGSUtil.Alert(GPGSStrings.Error,"Invalid classname: " + e.Message);
303+
Debug.LogException(e);
304304
}
305305
}
306306

@@ -355,48 +355,45 @@ public static void CheckBundleId()
355355
string packageName = GPGSProjectSettings.Instance.Get(
356356
GPGSUtil.ANDROIDBUNDLEIDKEY, string.Empty);
357357
string currentId;
358-
#if UNITY_5_6_OR_NEWER
359-
currentId = PlayerSettings.GetApplicationIdentifier(
360-
BuildTargetGroup.Android);
358+
#if UNITY_2021_2_OR_NEWER
359+
currentId = PlayerSettings.GetApplicationIdentifier(NamedBuildTarget.Android);
360+
#elif UNITY_5_6_OR_NEWER
361+
currentId = PlayerSettings.GetApplicationIdentifier(BuildTargetGroup.Android);
361362
#else
362363
currentId = PlayerSettings.bundleIdentifier;
363364
#endif
364-
if (!string.IsNullOrEmpty(packageName))
365+
if (string.IsNullOrEmpty(packageName))
365366
{
366-
if (string.IsNullOrEmpty(currentId) ||
367-
currentId == "com.Company.ProductName")
368-
{
369-
#if UNITY_5_6_OR_NEWER
370-
PlayerSettings.SetApplicationIdentifier(
371-
BuildTargetGroup.Android, packageName);
367+
Debug.Log("NULL package!!");
368+
}
369+
else if (string.IsNullOrEmpty(currentId) || currentId == "com.Company.ProductName")
370+
{
371+
#if UNITY_2021_2_OR_NEWER
372+
PlayerSettings.SetApplicationIdentifier(NamedBuildTarget.Android, packageName);
373+
#elif UNITY_5_6_OR_NEWER
374+
PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, packageName);
372375
#else
373-
PlayerSettings.bundleIdentifier = packageName;
376+
PlayerSettings.bundleIdentifier = packageName;
374377
#endif
375-
}
376-
else if (currentId != packageName)
378+
}
379+
else if (currentId != packageName)
380+
{
381+
if (EditorUtility.DisplayDialog(
382+
"Set Bundle Identifier?",
383+
"The server configuration is using " + packageName +
384+
", but the player settings is set to " + currentId +
385+
".\nSet the Bundle Identifier to " + packageName + "?",
386+
"OK", "Cancel"))
377387
{
378-
if (EditorUtility.DisplayDialog(
379-
"Set Bundle Identifier?",
380-
"The server configuration is using " +
381-
packageName + ", but the player settings is set to " +
382-
currentId + ".\nSet the Bundle Identifier to " +
383-
packageName + "?",
384-
"OK",
385-
"Cancel"))
386-
{
387-
#if UNITY_5_6_OR_NEWER
388-
PlayerSettings.SetApplicationIdentifier(
389-
BuildTargetGroup.Android, packageName);
388+
#if UNITY_2021_2_OR_NEWER
389+
PlayerSettings.SetApplicationIdentifier(NamedBuildTarget.Android, packageName);
390+
#elif UNITY_5_6_OR_NEWER
391+
PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, packageName);
390392
#else
391-
PlayerSettings.bundleIdentifier = packageName;
393+
PlayerSettings.bundleIdentifier = packageName;
392394
#endif
393-
}
394395
}
395396
}
396-
else
397-
{
398-
Debug.Log("NULL package!!");
399-
}
400397
}
401398

402399
/// <summary>

Assets/Public/GooglePlayGames/com.google.play.games/Editor/GPGSDocsUI.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,26 @@ namespace GooglePlayGames.Editor
2121

2222
public class GPGSDocsUI
2323
{
24-
[MenuItem("Window/Google Play Games/Documentation/Plugin Getting Started Guide...", false, 100)]
24+
[MenuItem("Google/Play Games/Documentation/Plugin Getting Started Guide...", false, 100)]
2525
public static void MenuItemGettingStartedGuide()
2626
{
2727
Application.OpenURL(GPGSStrings.ExternalLinks.GettingStartedGuideURL);
2828
}
2929

30-
[MenuItem("Window/Google Play Games/Documentation/Google Play Games API...", false, 101)]
30+
[MenuItem("Google/Play Games/Documentation/Google Play Games API...", false, 101)]
3131
public static void MenuItemPlayGamesServicesAPI()
3232
{
3333
Application.OpenURL(GPGSStrings.ExternalLinks.PlayGamesServicesApiURL);
3434
}
3535

36-
[MenuItem("Window/Google Play Games/About/About the Plugin...", false, 300)]
36+
[MenuItem("Google/Play Games/About/About the Plugin...", false, 300)]
3737
public static void MenuItemAbout()
3838
{
39-
string msg = GPGSStrings.AboutText +
40-
PluginVersion.VersionString + " (" +
41-
string.Format("0x{0:X8}", GooglePlayGames.PluginVersion.VersionInt) + ")";
42-
EditorUtility.DisplayDialog(GPGSStrings.AboutTitle, msg,
43-
GPGSStrings.Ok);
39+
string msg = GPGSStrings.AboutText + PluginVersion.VersionString + " (" + string.Format("0x{0:X8}", GooglePlayGames.PluginVersion.VersionInt) + ")";
40+
EditorUtility.DisplayDialog(GPGSStrings.AboutTitle, msg, GPGSStrings.Ok);
4441
}
4542

46-
[MenuItem("Window/Google Play Games/About/License...", false, 301)]
43+
[MenuItem("Google/Play Games/About/License...", false, 301)]
4744
public static void MenuItemLicense()
4845
{
4946
EditorUtility.DisplayDialog(GPGSStrings.LicenseTitle, GPGSStrings.LicenseText,

Assets/Public/GooglePlayGames/com.google.play.games/Editor/GPGSPostBuild.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
#if UNITY_ANDROID
1818
namespace GooglePlayGames.Editor
1919
{
20-
using System.Collections.Generic;
21-
using System.IO;
22-
using UnityEditor.Callbacks;
20+
using System.Linq;
21+
2322
using UnityEditor;
24-
using UnityEngine;
23+
using UnityEditor.Callbacks;
24+
2525

26-
public static class GPGSPostBuild
26+
public class GPGSPostBuild : AssetPostprocessor
2727
{
2828
[PostProcessBuild(99999)]
2929
public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject)
@@ -37,6 +37,12 @@ public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProj
3737

3838
return;
3939
}
40+
41+
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths, bool didDomainReload)
42+
{
43+
if(didDomainReload || importedAssets.Concat(deletedAssets).Concat(movedAssets).Any((path) => path.EndsWith("AndroidManifest.xml")))
44+
GPGSUtil.PatchAndroidManifest();
45+
}
4046
}
4147
}
4248
#endif //UNITY_ANDROID

Assets/Public/GooglePlayGames/com.google.play.games/Editor/GPGSUpgrader.cs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,13 @@ static GPGSUpgrader()
3838
Debug.Log("GPGSUpgrader start");
3939

4040
GPGSProjectSettings.Instance.Set(GPGSUtil.LASTUPGRADEKEY, PluginVersion.VersionKey);
41-
GPGSProjectSettings.Instance.Set(GPGSUtil.PLUGINVERSIONKEY,
42-
PluginVersion.VersionString);
41+
GPGSProjectSettings.Instance.Set(GPGSUtil.PLUGINVERSIONKEY, PluginVersion.VersionString);
4342
GPGSProjectSettings.Instance.Save();
4443

45-
bool isChanged = false;
46-
// Check that there is a AndroidManifest.xml file
47-
if (!GPGSUtil.AndroidManifestExists())
48-
{
49-
isChanged = true;
50-
GPGSUtil.GenerateAndroidManifest();
51-
}
44+
GPGSUtil.UpdateGameInfo();
45+
46+
AssetDatabase.Refresh();
5247

53-
if (isChanged)
54-
{
55-
AssetDatabase.Refresh();
56-
}
5748
Debug.Log("GPGSUpgrader done");
5849
}
5950
}

0 commit comments

Comments
 (0)