From dbc9c5510eb3a2ef4aa47893ef83ce5e084e215f Mon Sep 17 00:00:00 2001 From: Thaina Date: Wed, 25 Sep 2024 23:12:59 +0700 Subject: [PATCH] Move google menu + Fix play image loader --- .../Editor/GPGSAndroidSetupUI.cs | 79 ++++--- .../Editor/GPGSDocsUI.cs | 15 +- .../Editor/GPGSPostBuild.cs | 101 ++++++++- .../Editor/GPGSUpgrader.cs | 17 +- .../com.google.play.games/Editor/GPGSUtil.cs | 209 ++---------------- .../Editor/NearbyConnectionUI.cs | 6 +- .../Runtime/Scripts/BasicApi/Player.cs | 33 --- .../Scripts/BasicApi/PlayerProfile.cs.meta | 2 + .../Scripts/BasicApi/RecallAccess.cs.meta | 2 + .../ISocialPlatform/PlayGamesUserProfile.cs | 114 +++++----- .../Runtime/Scripts/OurUtils/PlatformUtils.cs | 3 +- .../Platforms/Android/AndroidClient.cs | 79 +++---- .../Android/AndroidHelperFragment.cs | 30 ++- .../Platforms/Android/AndroidJavaConverter.cs | 16 +- .../Android/AndroidNearbyConnectionClient.cs | 30 +-- .../com.google.play.games/package.json | 4 +- README.md | 14 ++ 17 files changed, 328 insertions(+), 426 deletions(-) delete mode 100644 Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/BasicApi/Player.cs create mode 100644 Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/BasicApi/PlayerProfile.cs.meta create mode 100644 Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/BasicApi/RecallAccess.cs.meta diff --git a/Assets/Public/GooglePlayGames/com.google.play.games/Editor/GPGSAndroidSetupUI.cs b/Assets/Public/GooglePlayGames/com.google.play.games/Editor/GPGSAndroidSetupUI.cs index 84138460d..2802f88f8 100644 --- a/Assets/Public/GooglePlayGames/com.google.play.games/Editor/GPGSAndroidSetupUI.cs +++ b/Assets/Public/GooglePlayGames/com.google.play.games/Editor/GPGSAndroidSetupUI.cs @@ -24,6 +24,10 @@ namespace GooglePlayGames.Editor using UnityEditor; using UnityEngine; +#if UNITY_2021_2_OR_NEWER + using UnityEditor.Build; +#endif + /// /// Google Play Game Services Setup dialog for Android. /// @@ -57,15 +61,14 @@ public class GPGSAndroidSetupUI : EditorWindow /// /// Menus the item for GPGS android setup. /// - [MenuItem("Window/Google Play Games/Setup/Android setup...", false, 1)] + [MenuItem("Google/Play Games/Setup/Android setup...", false, 1)] public static void MenuItemFileGPGSAndroidSetup() { - EditorWindow window = EditorWindow.GetWindow( - typeof(GPGSAndroidSetupUI), true, GPGSStrings.AndroidSetup.Title); + var window = EditorWindow.GetWindow(true, GPGSStrings.AndroidSetup.Title); window.minSize = new Vector2(500, 400); } - [MenuItem("Window/Google Play Games/Setup/Android setup...", true)] + [MenuItem("Google/Play Games/Setup/Android setup...", true)] public static bool EnableAndroidMenuItem() { #if UNITY_ANDROID @@ -111,8 +114,6 @@ public static bool PerformSetup( // check the bundle id and set it if needed. CheckBundleId(); - GPGSUtil.CheckAndFixDependencies(); - GPGSUtil.CheckAndFixVersionedAssestsPaths(); AssetDatabase.Refresh(); Google.VersionHandler.VerboseLoggingEnabled = true; @@ -196,7 +197,7 @@ public static bool PerformSetup(string webClientId, string appId, string nearbyS } // Generate AndroidManifest.xml - GPGSUtil.GenerateAndroidManifest(); + GPGSUtil.UpdateGameInfo(); // refresh assets, and we're done AssetDatabase.Refresh(); @@ -298,9 +299,8 @@ public void OnGUI() } catch (Exception e) { - GPGSUtil.Alert( - GPGSStrings.Error, - "Invalid classname: " + e.Message); + GPGSUtil.Alert(GPGSStrings.Error,"Invalid classname: " + e.Message); + Debug.LogException(e); } } @@ -355,48 +355,45 @@ public static void CheckBundleId() string packageName = GPGSProjectSettings.Instance.Get( GPGSUtil.ANDROIDBUNDLEIDKEY, string.Empty); string currentId; -#if UNITY_5_6_OR_NEWER - currentId = PlayerSettings.GetApplicationIdentifier( - BuildTargetGroup.Android); +#if UNITY_2021_2_OR_NEWER + currentId = PlayerSettings.GetApplicationIdentifier(NamedBuildTarget.Android); +#elif UNITY_5_6_OR_NEWER + currentId = PlayerSettings.GetApplicationIdentifier(BuildTargetGroup.Android); #else currentId = PlayerSettings.bundleIdentifier; #endif - if (!string.IsNullOrEmpty(packageName)) + if (string.IsNullOrEmpty(packageName)) { - if (string.IsNullOrEmpty(currentId) || - currentId == "com.Company.ProductName") - { -#if UNITY_5_6_OR_NEWER - PlayerSettings.SetApplicationIdentifier( - BuildTargetGroup.Android, packageName); + Debug.Log("NULL package!!"); + } + else if (string.IsNullOrEmpty(currentId) || currentId == "com.Company.ProductName") + { +#if UNITY_2021_2_OR_NEWER + PlayerSettings.SetApplicationIdentifier(NamedBuildTarget.Android, packageName); +#elif UNITY_5_6_OR_NEWER + PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, packageName); #else - PlayerSettings.bundleIdentifier = packageName; + PlayerSettings.bundleIdentifier = packageName; #endif - } - else if (currentId != packageName) + } + else if (currentId != packageName) + { + if (EditorUtility.DisplayDialog( + "Set Bundle Identifier?", + "The server configuration is using " + packageName + + ", but the player settings is set to " + currentId + + ".\nSet the Bundle Identifier to " + packageName + "?", + "OK", "Cancel")) { - if (EditorUtility.DisplayDialog( - "Set Bundle Identifier?", - "The server configuration is using " + - packageName + ", but the player settings is set to " + - currentId + ".\nSet the Bundle Identifier to " + - packageName + "?", - "OK", - "Cancel")) - { -#if UNITY_5_6_OR_NEWER - PlayerSettings.SetApplicationIdentifier( - BuildTargetGroup.Android, packageName); +#if UNITY_2021_2_OR_NEWER + PlayerSettings.SetApplicationIdentifier(NamedBuildTarget.Android, packageName); +#elif UNITY_5_6_OR_NEWER + PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, packageName); #else - PlayerSettings.bundleIdentifier = packageName; + PlayerSettings.bundleIdentifier = packageName; #endif - } } } - else - { - Debug.Log("NULL package!!"); - } } /// diff --git a/Assets/Public/GooglePlayGames/com.google.play.games/Editor/GPGSDocsUI.cs b/Assets/Public/GooglePlayGames/com.google.play.games/Editor/GPGSDocsUI.cs index 4d7c39d20..8b294686a 100644 --- a/Assets/Public/GooglePlayGames/com.google.play.games/Editor/GPGSDocsUI.cs +++ b/Assets/Public/GooglePlayGames/com.google.play.games/Editor/GPGSDocsUI.cs @@ -21,29 +21,26 @@ namespace GooglePlayGames.Editor public class GPGSDocsUI { - [MenuItem("Window/Google Play Games/Documentation/Plugin Getting Started Guide...", false, 100)] + [MenuItem("Google/Play Games/Documentation/Plugin Getting Started Guide...", false, 100)] public static void MenuItemGettingStartedGuide() { Application.OpenURL(GPGSStrings.ExternalLinks.GettingStartedGuideURL); } - [MenuItem("Window/Google Play Games/Documentation/Google Play Games API...", false, 101)] + [MenuItem("Google/Play Games/Documentation/Google Play Games API...", false, 101)] public static void MenuItemPlayGamesServicesAPI() { Application.OpenURL(GPGSStrings.ExternalLinks.PlayGamesServicesApiURL); } - [MenuItem("Window/Google Play Games/About/About the Plugin...", false, 300)] + [MenuItem("Google/Play Games/About/About the Plugin...", false, 300)] public static void MenuItemAbout() { - string msg = GPGSStrings.AboutText + - PluginVersion.VersionString + " (" + - string.Format("0x{0:X8}", GooglePlayGames.PluginVersion.VersionInt) + ")"; - EditorUtility.DisplayDialog(GPGSStrings.AboutTitle, msg, - GPGSStrings.Ok); + string msg = GPGSStrings.AboutText + PluginVersion.VersionString + " (" + string.Format("0x{0:X8}", GooglePlayGames.PluginVersion.VersionInt) + ")"; + EditorUtility.DisplayDialog(GPGSStrings.AboutTitle, msg, GPGSStrings.Ok); } - [MenuItem("Window/Google Play Games/About/License...", false, 301)] + [MenuItem("Google/Play Games/About/License...", false, 301)] public static void MenuItemLicense() { EditorUtility.DisplayDialog(GPGSStrings.LicenseTitle, GPGSStrings.LicenseText, diff --git a/Assets/Public/GooglePlayGames/com.google.play.games/Editor/GPGSPostBuild.cs b/Assets/Public/GooglePlayGames/com.google.play.games/Editor/GPGSPostBuild.cs index fb55c4395..2a77314a3 100644 --- a/Assets/Public/GooglePlayGames/com.google.play.games/Editor/GPGSPostBuild.cs +++ b/Assets/Public/GooglePlayGames/com.google.play.games/Editor/GPGSPostBuild.cs @@ -17,13 +17,16 @@ #if UNITY_ANDROID namespace GooglePlayGames.Editor { - using System.Collections.Generic; using System.IO; - using UnityEditor.Callbacks; + using System.Xml; + using System.Linq; + using System.Collections.Generic; + using UnityEditor; - using UnityEngine; + using UnityEditor.Android; + using UnityEditor.Callbacks; - public static class GPGSPostBuild + public class GPGSPostBuild : IPostGenerateGradleAndroidProject { [PostProcessBuild(99999)] public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject) @@ -37,6 +40,96 @@ public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProj return; } + + public int callbackOrder => 999; + + const string androidNamespaceURL = "http://schemas.android.com/apk/res/android"; + public void OnPostGenerateGradleAndroidProject(string path) + { + var manifestPath = Path.Combine(path,"src","main","AndroidManifest.xml"); + if(!File.Exists(manifestPath)) + { + EditorUtility.DisplayDialog("Google Play Games Error","Cannot find AndroidManifest.xml to modified","OK"); + return; + } + + var xmlDoc = new XmlDocument(); + xmlDoc.Load(manifestPath); + + var nsmgr = new XmlNamespaceManager(xmlDoc.NameTable); + nsmgr.AddNamespace("android",androidNamespaceURL); + + var appID = FindOrCreate(xmlDoc,nsmgr,androidNamespaceURL,"manifest/application/meta-data","android:name","com.google.android.gms.games.APP_ID"); + SetAttributeNS(xmlDoc,appID,androidNamespaceURL,"android:value","\\u003" + GPGSProjectSettings.Instance.Get(GPGSUtil.APPIDKEY)); + + var webClientID = FindOrCreate(xmlDoc,nsmgr,androidNamespaceURL,"manifest/application/meta-data","android:name","com.google.android.gms.games.WEB_CLIENT_ID"); + SetAttributeNS(xmlDoc,webClientID,androidNamespaceURL,"android:value",GPGSProjectSettings.Instance.Get(GPGSUtil.WEBCLIENTIDKEY)); + + var version = FindOrCreate(xmlDoc,nsmgr,androidNamespaceURL,"manifest/application/meta-data","android:name","com.google.android.gms.games.unityVersion"); + SetAttributeNS(xmlDoc,version,androidNamespaceURL,"android:value","\\u003" + PluginVersion.VersionString); + + string serviceID = GPGSProjectSettings.Instance.Get(GPGSUtil.SERVICEIDKEY); + if (!string.IsNullOrEmpty(serviceID)) + { + foreach(var permission in new[]{ "BLUETOOTH","BLUETOOTH_ADMIN","ACCESS_WIFI_STATE","CHANGE_WIFI_STATE","ACCESS_COARSE_LOCATION" }) + FindOrCreate(xmlDoc,nsmgr,androidNamespaceURL,"manifest/uses-permission","android:name","android.permission." + permission); + + var service = FindOrCreate(xmlDoc,nsmgr,androidNamespaceURL,"manifest/application/meta-data","android:name","com.google.android.gms.nearby.connection.SERVICE_ID"); + SetAttributeNS(xmlDoc,service,androidNamespaceURL,"android:value",serviceID); + } + + xmlDoc.Save(manifestPath); + } + + static void SetAttributeNS(XmlDocument xmlDoc,XmlElement element,string namespaceURL,string attributeName,string attributeValue) + { + var attr = xmlDoc.CreateAttribute(attributeName,namespaceURL); + attr.Value = attributeValue; + element.SetAttributeNode(attr); + } + + static XmlElement FindOrCreate(XmlDocument xmlDoc,XmlNamespaceManager nsmgr,string attributeNamespace,string path,string attributeName,string attributeValue) + { + var nodes = xmlDoc.SelectNodes($"{path}[@{attributeName}='{attributeValue}']",nsmgr); + if(nodes.Count > 0) + { + int i = 0; + while(i < nodes.Count) + { + if(nodes[i] is XmlElement element) + break; + + i++; + } + + foreach(var node in nodes.OfType().Where((node,n) => i != n)) + node.ParentNode.RemoveChild(node); + + return nodes[i] as XmlElement; + } + else + { + var element = xmlDoc.DocumentElement; + var stack = new Stack(); + while(path.LastIndexOf('/') is int i && i > 0) + { + stack.Push(path.Substring(i + 1)); + path = path.Remove(i); + element = xmlDoc.SelectNodes(path,nsmgr)?.OfType().FirstOrDefault(); + if(element != null) + break; + } + + while(stack.TryPop(out string name)) + { + element = element.AppendChild(xmlDoc.CreateElement(name)) as XmlElement; + } + + SetAttributeNS(xmlDoc,element,attributeNamespace,attributeName,attributeValue); + + return element; + } + } } } #endif //UNITY_ANDROID \ No newline at end of file diff --git a/Assets/Public/GooglePlayGames/com.google.play.games/Editor/GPGSUpgrader.cs b/Assets/Public/GooglePlayGames/com.google.play.games/Editor/GPGSUpgrader.cs index ada7ed1f7..32267fb28 100644 --- a/Assets/Public/GooglePlayGames/com.google.play.games/Editor/GPGSUpgrader.cs +++ b/Assets/Public/GooglePlayGames/com.google.play.games/Editor/GPGSUpgrader.cs @@ -38,22 +38,13 @@ static GPGSUpgrader() Debug.Log("GPGSUpgrader start"); GPGSProjectSettings.Instance.Set(GPGSUtil.LASTUPGRADEKEY, PluginVersion.VersionKey); - GPGSProjectSettings.Instance.Set(GPGSUtil.PLUGINVERSIONKEY, - PluginVersion.VersionString); + GPGSProjectSettings.Instance.Set(GPGSUtil.PLUGINVERSIONKEY, PluginVersion.VersionString); GPGSProjectSettings.Instance.Save(); - bool isChanged = false; - // Check that there is a AndroidManifest.xml file - if (!GPGSUtil.AndroidManifestExists()) - { - isChanged = true; - GPGSUtil.GenerateAndroidManifest(); - } + GPGSUtil.UpdateGameInfo(); + + AssetDatabase.Refresh(); - if (isChanged) - { - AssetDatabase.Refresh(); - } Debug.Log("GPGSUpgrader done"); } } diff --git a/Assets/Public/GooglePlayGames/com.google.play.games/Editor/GPGSUtil.cs b/Assets/Public/GooglePlayGames/com.google.play.games/Editor/GPGSUtil.cs index 4bc78319b..bff31563b 100644 --- a/Assets/Public/GooglePlayGames/com.google.play.games/Editor/GPGSUtil.cs +++ b/Assets/Public/GooglePlayGames/com.google.play.games/Editor/GPGSUtil.cs @@ -101,14 +101,7 @@ public static class GPGSUtil /// /// The game info file path, relative to the plugin root directory. This is a generated file. /// - private const string GameInfoRelativePath = "Runtime/Scripts/GameInfo.cs"; - - /// - /// The manifest path, relative to the plugin root directory. - /// - /// The Games SDK requires additional metadata in the AndroidManifest.xml - /// file. - private const string ManifestRelativePath = "Plugins/Android/GooglePlayGamesManifest.androidlib/AndroidManifest.xml"; + private const string GameInfoRelativePath = "GooglePlayGames/Runtime/Scripts/GameInfo.cs"; private const string RootFolderName = "com.google.play.games"; @@ -138,43 +131,23 @@ public static string RootPath return Directory.GetDirectories(path, RootFolderName + "*", SearchOption.AllDirectories); }).Distinct().ToArray(); + mRootPath = dirs.Select((dir) => SlashesToPlatformSeparator(dir)).FirstOrDefault((dir) => File.Exists(Path.Combine(dir,GameInfoRelativePath))); - switch (dirs.Length) + if (string.IsNullOrEmpty(mRootPath)) { - case 0: - Alert("Plugin error: com.google.play.games folder was renamed"); - throw new Exception("com.google.play.games folder was renamed"); - - case 1: - mRootPath = SlashesToPlatformSeparator(dirs[0]); - break; - - default: - for (int i = 0; i < dirs.Length; i++) - { - if (File.Exists(SlashesToPlatformSeparator(Path.Combine(dirs[i], GameInfoRelativePath)))) - { - mRootPath = SlashesToPlatformSeparator(dirs[i]); - break; - } - } - - if (string.IsNullOrEmpty(mRootPath)) - { - Alert("Plugin error: com.google.play.games folder was renamed"); - throw new Exception("com.google.play.games folder was renamed"); - } - - break; + Alert("Plugin error: com.google.play.games folder was renamed"); + throw new Exception("com.google.play.games folder was renamed"); + } + + // UPM package root path is 'Library/PackageCache/com.google.play.games@.*/ + // where the suffix can be a version number if installed with URS + // or a hash if from disk or tarball + if (mRootPath.Contains(RootFolderName + '@')) + { + mRootPath = mRootPath.Replace("Packages", "Library/PackageCache"); } } - // UPM package root path is 'Library/PackageCache/com.google.play.games@.*/ - // where the suffix can be a version number if installed with URS - // or a hash if from disk or tarball - if (mRootPath.Contains(RootFolderName + '@')) - { - mRootPath = mRootPath.Replace("Packages", "Library/PackageCache"); - } + return mRootPath; } } @@ -187,16 +160,6 @@ private static string GameInfoPath get { return SlashesToPlatformSeparator(Path.Combine("Assets", GameInfoRelativePath)); } } - /// - /// The manifest path. - /// - /// The Games SDK requires additional metadata in the AndroidManifest.xml - /// file. - private static string ManifestPath - { - get { return SlashesToPlatformSeparator(Path.Combine("Assets", ManifestRelativePath)); } - } - /// /// The root path of the Google Play Games plugin /// @@ -228,7 +191,7 @@ private static string ManifestPath /// Path with correct separators. public static string SlashesToPlatformSeparator(string path) { - return path.Replace("/", System.IO.Path.DirectorySeparatorChar.ToString()); + return Path.DirectorySeparatorChar == '/' ? path : path.Replace('/', Path.DirectorySeparatorChar); } /// @@ -497,7 +460,7 @@ public static string GetAndroidSdkPath() public static bool HasAndroidSdk() { string sdkPath = GetAndroidSdkPath(); - return sdkPath != null && sdkPath.Trim() != string.Empty && System.IO.Directory.Exists(sdkPath); + return sdkPath != null && sdkPath.Trim() != string.Empty && Directory.Exists(sdkPath); } /// @@ -522,61 +485,6 @@ public static int GetUnityMajorVersion() #endif } - /// - /// Checks for the android manifest file exsistance. - /// - /// true, if the file exists false otherwise. - public static bool AndroidManifestExists() - { - string destFilename = ManifestPath; - - return File.Exists(destFilename); - } - - /// - /// Generates the android manifest. - /// - public static void GenerateAndroidManifest() - { - string destFilename = ManifestPath; - - // Generate AndroidManifest.xml - string manifestBody = GPGSUtil.ReadEditorTemplate("template-AndroidManifest"); - - Dictionary overrideValues = - new Dictionary(); - - if (!string.IsNullOrEmpty(GPGSProjectSettings.Instance.Get(SERVICEIDKEY))) - { - overrideValues[NEARBY_PERMISSIONS_PLACEHOLDER] = - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n"; - overrideValues[SERVICEID_ELEMENT_PLACEHOLDER] = - " \n" + - " \n"; - } - else - { - overrideValues[NEARBY_PERMISSIONS_PLACEHOLDER] = ""; - overrideValues[SERVICEID_ELEMENT_PLACEHOLDER] = ""; - } - - foreach (KeyValuePair ent in replacements) - { - string value = - GPGSProjectSettings.Instance.Get(ent.Value, overrideValues); - manifestBody = manifestBody.Replace(ent.Key, value); - } - - GPGSUtil.WriteFile(destFilename, manifestBody); - GPGSUtil.UpdateGameInfo(); - } - /// /// Writes the resource identifiers file. This file contains the /// resource ids copied (downloaded?) from the play game app console. @@ -660,91 +568,6 @@ public static void UpdateGameInfo() GPGSUtil.WriteFile(GameInfoPath, fileBody); } - /// - /// Checks the dependencies file and fixes repository paths - /// if they are incorrect (for example if the user moved plugin - /// into some subdirectory). This is a generated file containing - /// the list of dependencies that are needed for the plugin to work. - /// - public static void CheckAndFixDependencies() - { - string depPath = SlashesToPlatformSeparator(Path.Combine("Assets","Editor","GooglePlayGamesPluginDependencies.xml")); - if(!File.Exists(depPath)) - return; - - XmlDocument doc = new XmlDocument(); - doc.Load(depPath); - - XmlNodeList repos = doc.SelectNodes("//androidPackage[contains(@spec,'com.google.games')]//repository"); - foreach (XmlNode repo in repos) - { - if (!Directory.Exists(repo.InnerText)) - { - int pos = repo.InnerText.IndexOf(RootFolderName); - if (pos != -1) - { - repo.InnerText = - Path.Combine(RootPath, repo.InnerText.Substring(pos + RootFolderName.Length + 1)) - .Replace("\\", "/"); - } - } - } - - doc.Save(depPath); - } - - /// - /// Checks the file containing the list of versioned assets and fixes - /// paths to them if they are incorrect (for example if the user moved - /// plugin into some subdirectory). This is a generated file. - /// - public static void CheckAndFixVersionedAssestsPaths() - { - string[] rootPaths = new string[] { "Assets",RootPath }; - string[] foundPaths = rootPaths.Select((rootPath) => { - string editorPath = Path.Combine(rootPath,"Editor"); - if(!Directory.Exists(editorPath)) - return Array.Empty(); - - return Directory.GetFiles(editorPath, "GooglePlayGamesPlugin_v*.txt", SearchOption.AllDirectories); - }).FirstOrDefault((txtFiles) => { - return txtFiles.Length > 0 && File.Exists(txtFiles[0]); - }); - - if (foundPaths?.Length == 1) - { - string tmpFilePath = Path.GetTempFileName(); - - StreamWriter writer = new StreamWriter(tmpFilePath); - using (StreamReader reader = new StreamReader(foundPaths[0])) - { - string assetPath; - while ((assetPath = reader.ReadLine()) != null) - { - int pos = assetPath.IndexOf(RootFolderName); - if (pos != -1) - { - assetPath = Path.Combine(RootPath, assetPath.Substring(pos + RootFolderName.Length + 1)).Replace("\\", "/"); - } - - writer.WriteLine(assetPath); - } - } - - writer.Flush(); - writer.Close(); - - try - { - File.Copy(tmpFilePath, foundPaths[0], true); - } - finally - { - File.Delete(tmpFilePath); - } - } - } - /// /// Ensures the dir exists. /// diff --git a/Assets/Public/GooglePlayGames/com.google.play.games/Editor/NearbyConnectionUI.cs b/Assets/Public/GooglePlayGames/com.google.play.games/Editor/NearbyConnectionUI.cs index f4cc4875e..bf23a9a3f 100644 --- a/Assets/Public/GooglePlayGames/com.google.play.games/Editor/NearbyConnectionUI.cs +++ b/Assets/Public/GooglePlayGames/com.google.play.games/Editor/NearbyConnectionUI.cs @@ -25,7 +25,7 @@ public class NearbyConnectionUI : EditorWindow { private string mNearbyServiceId = string.Empty; - [MenuItem("Window/Google Play Games/Setup/Nearby Connections setup...", false, 3)] + [MenuItem("Google/Play Games/Setup/Nearby Connections setup...", false, 3)] public static void MenuItemNearbySetup() { EditorWindow window = EditorWindow.GetWindow( @@ -33,7 +33,7 @@ public static void MenuItemNearbySetup() window.minSize = new Vector2(400, 200); } - [MenuItem("Window/Google Play Games/Setup/Nearby Connections setup...", true)] + [MenuItem("Google/Play Games/Setup/Nearby Connections setup...", true)] public static bool EnableNearbyMenuItem() { #if UNITY_ANDROID @@ -128,7 +128,7 @@ public static bool PerformSetup(string nearbyServiceId, bool androidBuild) GPGSUtil.EnsureDirExists("Assets/Plugins/Android"); // Generate AndroidManifest.xml - GPGSUtil.GenerateAndroidManifest(); + GPGSUtil.UpdateGameInfo(); GPGSProjectSettings.Instance.Set(GPGSUtil.NEARBYSETUPDONEKEY, true); GPGSProjectSettings.Instance.Save(); diff --git a/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/BasicApi/Player.cs b/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/BasicApi/Player.cs deleted file mode 100644 index 094645f35..000000000 --- a/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/BasicApi/Player.cs +++ /dev/null @@ -1,33 +0,0 @@ -// -// Copyright (C) 2014 Google Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -#if UNITY_ANDROID -namespace GooglePlayGames.BasicApi -{ - /// - /// Represents a player. A player is different from a participant! The participant is - /// an entity that takes part in a particular match; a Player is a real-world person - /// (tied to a Games account). The player exists across matches, the Participant - /// only exists in the context of a particular match. - /// - public class Player : PlayGamesUserProfile - { - internal Player(string displayName, string playerId, string avatarUrl) - : base(displayName, playerId, avatarUrl) - { - } - } -} -#endif diff --git a/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/BasicApi/PlayerProfile.cs.meta b/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/BasicApi/PlayerProfile.cs.meta new file mode 100644 index 000000000..7762f341a --- /dev/null +++ b/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/BasicApi/PlayerProfile.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 8b3a4a6424388914289809c499a7f304 \ No newline at end of file diff --git a/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/BasicApi/RecallAccess.cs.meta b/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/BasicApi/RecallAccess.cs.meta new file mode 100644 index 000000000..c15d7fa18 --- /dev/null +++ b/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/BasicApi/RecallAccess.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 3efc78f4078ecbb4a9946525fbe40a3d \ No newline at end of file diff --git a/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/ISocialPlatform/PlayGamesUserProfile.cs b/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/ISocialPlatform/PlayGamesUserProfile.cs index 62820e448..dc4b415fe 100644 --- a/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/ISocialPlatform/PlayGamesUserProfile.cs +++ b/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/ISocialPlatform/PlayGamesUserProfile.cs @@ -19,8 +19,8 @@ namespace GooglePlayGames { using System; - using System.Collections; - using GooglePlayGames.OurUtils; + using System.Threading.Tasks; + using UnityEngine; #if UNITY_2017_2_OR_NEWER using UnityEngine.Networking; @@ -42,18 +42,11 @@ public class PlayGamesUserProfile : IUserProfile private volatile bool mImageLoading = false; private Texture2D mImage; - internal PlayGamesUserProfile(string displayName, string playerId, - string avatarUrl) + internal PlayGamesUserProfile(string displayName, string playerId,string avatarUrl) : this(displayName,playerId,avatarUrl,false) { - mDisplayName = displayName; - mPlayerId = playerId; - setAvatarUrl(avatarUrl); - mImageLoading = false; - mIsFriend = false; } - internal PlayGamesUserProfile(string displayName, string playerId, string avatarUrl, - bool isFriend) + internal PlayGamesUserProfile(string displayName, string playerId, string avatarUrl,bool isFriend) { mDisplayName = displayName; mPlayerId = playerId; @@ -62,8 +55,7 @@ internal PlayGamesUserProfile(string displayName, string playerId, string avatar mIsFriend = isFriend; } - protected void ResetIdentity(string displayName, string playerId, - string avatarUrl) + protected void ResetIdentity(string displayName, string playerId,string avatarUrl) { mDisplayName = displayName; mPlayerId = playerId; @@ -112,7 +104,53 @@ public Texture2D image { OurUtils.Logger.d("Starting to load image: " + AvatarURL); mImageLoading = true; - PlayGamesHelperObject.RunCoroutine(LoadImage()); + + mImage = new Texture2D(96,96); + + var scheduler = TaskScheduler.FromCurrentSynchronizationContext(); + + using(var currentActivity = Android.AndroidHelperFragment.GetActivity()) + { + currentActivity.Call("runOnUiThread", new AndroidJavaRunnable(() => { + var listener = new OnLoadImageListener(); + + using(var currentActivity = Android.AndroidHelperFragment.GetActivity()) + using(var ImageManager = new AndroidJavaClass("com.google.android.gms.common.images.ImageManager")) + using(var imageManager = ImageManager.CallStatic("create",currentActivity)) + using(var Uri = new AndroidJavaClass("android.net.Uri")) + using(var uri = Uri.CallStatic("parse",AvatarURL)) + { + imageManager.Call("loadImage",listener,uri); + } + + listener.AsTask.ContinueWith((task) => { + Debug.LogFormat("task : {0}",task); + if(!task.IsCompletedSuccessfully) + { + Debug.LogException(task.Exception); + return; + } + + var (uri,drawable,_) = task.Result; + + using(var CompressFormat = new AndroidJavaClass("android.graphics.Bitmap$CompressFormat")) + using(var format = CompressFormat.GetStatic("PNG")) + using(var outputStream = new AndroidJavaObject("java.io.ByteArrayOutputStream")) + using(var bitmap = drawable.Call("getBitmap")) + { + mImage.Reinitialize(bitmap.Call("getWidth"),bitmap.Call("getHeight")); + + bitmap.Call("compress",format,100,outputStream); + var data = outputStream.Call("toByteArray"); + + mImage.LoadImage(System.Runtime.InteropServices.MemoryMarshal.Cast(data).ToArray()); + } + + drawable?.Dispose(); + uri?.Dispose(); + },scheduler); + })); + } } return mImage; @@ -126,50 +164,18 @@ public string AvatarURL get { return mAvatarUrl; } } - /// - /// Loads the local user's image from the url. Loading urls - /// is asynchronous so the return from this call is fast, - /// the image is returned once it is loaded. null is returned - /// up to that point. - /// - internal IEnumerator LoadImage() + class OnLoadImageListener : AndroidJavaProxy { - // the url can be null if the user does not have an - // avatar configured. - if (!string.IsNullOrEmpty(AvatarURL)) - { -#if UNITY_2017_2_OR_NEWER - UnityWebRequest www = UnityWebRequestTexture.GetTexture(AvatarURL); - www.SendWebRequest(); -#else - WWW www = new WWW(AvatarURL); -#endif - while (!www.isDone) - { - yield return null; - } + public Task<(AndroidJavaObject uri,AndroidJavaObject drawable,bool isRequestedDrawable)> AsTask => source.Task; + TaskCompletionSource<(AndroidJavaObject uri,AndroidJavaObject drawable,bool isRequestedDrawable)> source = new TaskCompletionSource<(AndroidJavaObject uri, AndroidJavaObject drawable, bool isRequestedDrawable)>(); - if (www.error == null) - { -#if UNITY_2017_2_OR_NEWER - this.mImage = DownloadHandlerTexture.GetContent(www); -#else - this.mImage = www.texture; -#endif - } - else - { - mImage = Texture2D.blackTexture; - OurUtils.Logger.e("Error downloading image: " + www.error); - } + public OnLoadImageListener() : base("com.google.android.gms.common.images.ImageManager$OnImageLoadedListener") { } - mImageLoading = false; - } - else + public void onImageLoaded(AndroidJavaObject uri, AndroidJavaObject drawable, bool isRequestedDrawable) { - OurUtils.Logger.e("No URL found."); - mImage = Texture2D.blackTexture; - mImageLoading = false; + Debug.Log((uri,drawable,isRequestedDrawable)); + Debug.Log(source); + source.TrySetResult((uri,drawable,isRequestedDrawable)); } } diff --git a/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/OurUtils/PlatformUtils.cs b/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/OurUtils/PlatformUtils.cs index 5fce45bad..d87623457 100644 --- a/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/OurUtils/PlatformUtils.cs +++ b/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/OurUtils/PlatformUtils.cs @@ -41,8 +41,7 @@ public static bool Supported //if the app is installed, no errors. Else, doesn't get past next line try { - launchIntent = - packageManager.Call("getLaunchIntentForPackage", "com.google.android.play.games"); + launchIntent = packageManager.Call("getLaunchIntentForPackage", "com.google.android.play.games"); } catch (Exception) { diff --git a/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/Platforms/Android/AndroidClient.cs b/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/Platforms/Android/AndroidClient.cs index a0c3ad35b..11e6e696c 100644 --- a/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/Platforms/Android/AndroidClient.cs +++ b/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/Platforms/Android/AndroidClient.cs @@ -37,12 +37,11 @@ private enum AuthState private readonly object GameServicesLock = new object(); private readonly object AuthStateLock = new object(); - private readonly static String PlayGamesSdkClassName = - "com.google.android.gms.games.PlayGamesSdk"; + private const string PlayGamesSdkClassName = "com.google.android.gms.games.PlayGamesSdk"; private volatile ISavedGameClient mSavedGameClient; private volatile IEventsClient mEventsClient; - private volatile Player mUser = null; + private volatile PlayGamesUserProfile mUser = null; private volatile AuthState mAuthState = AuthState.Unauthenticated; private IUserProfile[] mFriends = new IUserProfile[0]; private LoadFriendsStatus mLastLoadFriendsStatus = LoadFriendsStatus.Unknown; @@ -97,8 +96,7 @@ private void Authenticate(bool isAutoSignIn, Action callback) OurUtils.Logger.d("Starting Auth using the method " + methodName); using (var client = getGamesSignInClient()) - using ( - var task = client.Call(methodName)) + using (var task = client.Call(methodName)) { AndroidTaskUtils.AddOnSuccessListener(task, authenticationResult => { @@ -179,19 +177,39 @@ private void SignInOnResult(bool isAuthenticated, Action callback) } } - public void RequestServerSideAccess(bool forceRefreshToken, Action callback) + static string appID = null; + public static string AppId { - callback = AsOnGameThreadCallback(callback); + get + { + if(appID == null) + appID = AndroidHelperFragment.CallPackageMetaData("GET_META_DATA","getString","com.google.android.gms.games.APP_ID") ?? ""; - if (!GameInfo.WebClientIdInitialized()) + return appID; + } + } + + static string webClientId = null; + public static string WebClientId + { + get { - throw new InvalidOperationException("Requesting server side access requires web " + - "client id to be configured."); + if(webClientId == null) + webClientId = AndroidHelperFragment.CallPackageMetaData("GET_META_DATA","getString","com.google.android.gms.games.WEB_CLIENT_ID") ?? ""; + + return webClientId; } + } + + public void RequestServerSideAccess(bool forceRefreshToken, Action callback) + { + callback = AsOnGameThreadCallback(callback); + + if (string.IsNullOrEmpty(WebClientId) || !WebClientId.StartsWith(AppId) || !WebClientId.EndsWith(".googleusercontent.com")) + throw new InvalidOperationException("Requesting server side access requires web client id to be configured."); using (var client = getGamesSignInClient()) - using (var task = client.Call("requestServerSideAccess", - GameInfo.WebClientId, forceRefreshToken)) + using (var task = client.Call("requestServerSideAccess", WebClientId, forceRefreshToken)) { AndroidTaskUtils.AddOnSuccessListener( task, @@ -298,11 +316,9 @@ public void LoadFriends(Action callback) LoadAllFriends(mFriendsMaxResults, /* forceReload= */ false, /* loadMore= */ false, callback); } - private void LoadAllFriends(int pageSize, bool forceReload, bool loadMore, - Action callback) + private void LoadAllFriends(int pageSize, bool forceReload, bool loadMore, Action callback) { - LoadFriendsPaginated(pageSize, loadMore, forceReload, result => - { + LoadFriendsPaginated(pageSize, loadMore, forceReload, result => { mLastLoadFriendsStatus = result; switch (result) { @@ -326,8 +342,7 @@ private void LoadAllFriends(int pageSize, bool forceReload, bool loadMore, }); } - public void LoadFriends(int pageSize, bool forceReload, - Action callback) + public void LoadFriends(int pageSize, bool forceReload, Action callback) { LoadFriendsPaginated(pageSize, /* isLoadMore= */ false, /* forceReload= */ forceReload, callback); @@ -339,8 +354,7 @@ public void LoadMoreFriends(int pageSize, Action callback) callback); } - private void LoadFriendsPaginated(int pageSize, bool isLoadMore, bool forceReload, - Action callback) + private void LoadFriendsPaginated(int pageSize, bool isLoadMore, bool forceReload, Action callback) { mFriendsResolutionException = null; using (var playersClient = getPlayersClient()) @@ -393,8 +407,7 @@ private void LoadFriendsPaginated(int pageSize, bool isLoadMore, bool forceReloa } mLastLoadFriendsStatus = LoadFriendsStatus.InternalError; - OurUtils.Logger.e("LoadFriends failed: " + - exception.Call("toString")); + OurUtils.Logger.e("LoadFriends failed: " + exception.Call("toString")); InvokeCallbackOnGameThread(callback, LoadFriendsStatus.InternalError); } }); @@ -422,9 +435,7 @@ public void AskForLoadFriendsResolution(Action callback) "list but there is no intent to trigger the UI. This may be because the user " + "has granted access already or the game has not called loadFriends() before."); using (var playersClient = getPlayersClient()) - using ( - var task = playersClient.Call("loadFriends", /* pageSize= */ 1, - /* forceReload= */ false)) + using (var task = playersClient.Call("loadFriends", /* pageSize= */ 1, /* forceReload= */ false)) { AndroidTaskUtils.AddOnSuccessListener( task, annotatedData => { InvokeCallbackOnGameThread(callback, UIStatus.Valid); }); @@ -452,8 +463,7 @@ public void AskForLoadFriendsResolution(Action callback) } } - OurUtils.Logger.e("LoadFriends failed: " + - exception.Call("toString")); + OurUtils.Logger.e("LoadFriends failed: " + exception.Call("toString")); InvokeCallbackOnGameThread(callback, UIStatus.InternalError); }); }); @@ -461,8 +471,7 @@ public void AskForLoadFriendsResolution(Action callback) } else { - AndroidHelperFragment.AskForLoadFriendsResolution(mFriendsResolutionException, - AsOnGameThreadCallback(callback)); + AndroidHelperFragment.AskForLoadFriendsResolution(mFriendsResolutionException,AsOnGameThreadCallback(callback)); } } @@ -476,12 +485,10 @@ public void ShowCompareProfileWithAlternativeNameHintsUI(string playerId, AsOnGameThreadCallback(callback)); } - public void GetFriendsListVisibility(bool forceReload, - Action callback) + public void GetFriendsListVisibility(bool forceReload, Action callback) { using (var playersClient = getPlayersClient()) - using ( - var task = playersClient.Call("getCurrentPlayer", forceReload)) + using (var task = playersClient.Call("getCurrentPlayer", forceReload)) { AndroidTaskUtils.AddOnSuccessListener(task, annotatedData => { @@ -861,8 +868,7 @@ public void LoadScores(string leaderboardId, LeaderboardStart start, } } - public void LoadMoreScores(ScorePageToken token, int rowCount, - Action callback) + public void LoadMoreScores(ScorePageToken token, int rowCount, Action callback) { using (var client = getLeaderboardsClient()) using (var task = client.Call("loadMoreScores", @@ -983,8 +989,7 @@ public void SubmitScore(string leaderboardId, long score, Action callback) } } - public void SubmitScore(string leaderboardId, long score, string metadata, - Action callback) + public void SubmitScore(string leaderboardId, long score, string metadata, Action callback) { if (!IsAuthenticated()) { diff --git a/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/Platforms/Android/AndroidHelperFragment.cs b/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/Platforms/Android/AndroidHelperFragment.cs index 4b770e14d..6cf561091 100644 --- a/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/Platforms/Android/AndroidHelperFragment.cs +++ b/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/Platforms/Android/AndroidHelperFragment.cs @@ -17,14 +17,14 @@ #if UNITY_ANDROID namespace GooglePlayGames.Android { + using System; + + using UnityEngine; + using GooglePlayGames.BasicApi; using GooglePlayGames.BasicApi.SavedGame; - using OurUtils; - using UnityEngine; - using System; - using System.Collections.Generic; - internal class AndroidHelperFragment + internal static class AndroidHelperFragment { private const string HelperFragmentClass = "com.google.games.bridge.HelperFragment"; @@ -36,6 +36,26 @@ public static AndroidJavaObject GetActivity() } } + public static int PackageManagerFlag(string flagName) + { + using(var PackageManager = new AndroidJavaClass("android.content.pm.PackageManager")) + return PackageManager.GetStatic(flagName); + } + + public static T CallPackageMetaData(string flagName,string methodName, params object[] args) + { + return CallPackageMetaData(PackageManagerFlag(flagName),methodName,args); + } + + public static T CallPackageMetaData(int applicationInfoFlags,string methodName, params object[] args) + { + using (var activity = GetActivity()) + using (var pm = activity.Call("getPackageManager")) + using (var appInfo = pm.Call("getApplicationInfo", activity.Call("getPackageName"), applicationInfoFlags)) + using (var bundle = appInfo.Get("metaData")) + return bundle.Call(methodName,args); + } + public static AndroidJavaObject GetDefaultPopupView() { using (var helperFragment = new AndroidJavaClass(HelperFragmentClass)) diff --git a/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/Platforms/Android/AndroidJavaConverter.cs b/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/Platforms/Android/AndroidJavaConverter.cs index f4bd0674f..7f94157cb 100644 --- a/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/Platforms/Android/AndroidJavaConverter.cs +++ b/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/Platforms/Android/AndroidJavaConverter.cs @@ -75,7 +75,7 @@ internal static int ToPageDirection(ScorePageDirection direction) } } - internal static Player ToPlayer(AndroidJavaObject player) + internal static PlayGamesUserProfile ToPlayer(AndroidJavaObject player) { if (player == null) { @@ -84,8 +84,8 @@ internal static Player ToPlayer(AndroidJavaObject player) string displayName = player.Call("getDisplayName"); string playerId = player.Call("getPlayerId"); - string avatarUrl = player.Call("getIconImageUrl"); - return new Player(displayName, playerId, avatarUrl); + string avatarUrl = player.Call("getIconImageUri").Call("toString"); + return new PlayGamesUserProfile(displayName, playerId, avatarUrl); } internal static PlayerProfile ToPlayerProfile(AndroidJavaObject player) { @@ -93,12 +93,10 @@ internal static PlayerProfile ToPlayerProfile(AndroidJavaObject player) { return null; } - string displayName = player.Call("getDisplayName"); - string playerId = player.Call("getPlayerId"); - string avatarUrl = player.Call("getIconImageUrl"); - bool isFriend = - player.Call("getRelationshipInfo").Call("getFriendStatus") == - 4 /* PlayerFriendStatus.Friend*/; + string displayName = player.Call("getDisplayName"); + string playerId = player.Call("getPlayerId"); + string avatarUrl = player.Call("getIconImageUri").Call("toString"); + bool isFriend = player.Call("getRelationshipInfo").Call("getFriendStatus") == 4 /* PlayerFriendStatus.Friend*/; return new PlayerProfile(displayName, playerId, avatarUrl, isFriend); } diff --git a/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/Platforms/Android/AndroidNearbyConnectionClient.cs b/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/Platforms/Android/AndroidNearbyConnectionClient.cs index 654488cbc..e757f9243 100644 --- a/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/Platforms/Android/AndroidNearbyConnectionClient.cs +++ b/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/Platforms/Android/AndroidNearbyConnectionClient.cs @@ -24,8 +24,7 @@ public AndroidNearbyConnectionClient() NearbyHelperObject.CreateObject(this); using (var nearbyClass = new AndroidJavaClass("com.google.android.gms.nearby.Nearby")) { - mClient = nearbyClass.CallStatic("getConnectionsClient", - AndroidHelperFragment.GetActivity()); + mClient = nearbyClass.CallStatic("getConnectionsClient",AndroidHelperFragment.GetActivity()); } } @@ -292,12 +291,10 @@ public void onDisconnected(string endpointId) private AndroidJavaObject CreateDiscoveryOptions() { - using (var strategy = - new AndroidJavaClass("com.google.android.gms.nearby.connection.Strategy").GetStatic( - "P2P_CLUSTER")) - using (var builder = - new AndroidJavaObject("com.google.android.gms.nearby.connection.DiscoveryOptions$Builder")) - using (builder.Call("setStrategy", strategy)) + using (var builder = new AndroidJavaObject("com.google.android.gms.nearby.connection.DiscoveryOptions$Builder")) + using (var strategy = new AndroidJavaClass("com.google.android.gms.nearby.connection.Strategy")) + using (var flag = strategy.GetStatic("P2P_CLUSTER")) + using (builder.Call("setStrategy", flag)) { return builder.Call("build"); } @@ -413,20 +410,9 @@ public string GetServiceId() private static string ReadServiceId() { - using (var activity = AndroidHelperFragment.GetActivity()) - { - string packageName = activity.Call("getPackageName"); - using (var pm = activity.Call("getPackageManager")) - using (var appInfo = - pm.Call("getApplicationInfo", packageName, ApplicationInfoFlags)) - using (var bundle = appInfo.Get("metaData")) - { - string sysId = bundle.Call("getString", - "com.google.android.gms.nearby.connection.SERVICE_ID"); - OurUtils.Logger.d("SystemId from Manifest: " + sysId); - return sysId; - } - } + var sysId = AndroidHelperFragment.CallPackageMetaData(ApplicationInfoFlags,"getString","com.google.android.gms.nearby.connection.SERVICE_ID"); + OurUtils.Logger.d("SystemId from Manifest: " + sysId); + return sysId; } private static Action ToOnGameThread(Action toConvert) diff --git a/Assets/Public/GooglePlayGames/com.google.play.games/package.json b/Assets/Public/GooglePlayGames/com.google.play.games/package.json index 9f5ccf552..e86273682 100644 --- a/Assets/Public/GooglePlayGames/com.google.play.games/package.json +++ b/Assets/Public/GooglePlayGames/com.google.play.games/package.json @@ -7,5 +7,7 @@ "author": { "name": "Google LLC" }, - "dependencies": {} + "dependencies": { + "com.google.external-dependency-manager": "1.2.170" + } } diff --git a/README.md b/README.md index 55634ca50..4930a96cf 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,17 @@ +## Fork for upgrade package and making UPM compatiable + +```json +{ + "com.google.play.games": "https://github.com/Thaina/play-games-plugin-for-unity.git?path=/Assets/Public/GooglePlayGames/com.google.play.games" +} +``` + +This fork now use gradle post build event to patch androidmanifest + +Also fix the image loader from play service + +Tested and worked in Unity 6. Should be compatible with lower version but not fully tested yet + # Google Play Games plugin for Unity _Copyright (c) 2014 Google Inc. All rights reserved._