diff --git a/Assets/Plugins/Android.meta b/Assets/Plugins/Android.meta
deleted file mode 100644
index 6a11e50de..000000000
--- a/Assets/Plugins/Android.meta
+++ /dev/null
@@ -1,5 +0,0 @@
-fileFormatVersion: 2
-guid: b8f0d9a6a7f9240c981894807effddbc
-folderAsset: yes
-DefaultImporter:
- userData:
diff --git a/Assets/Plugins/Android/GooglePlayGamesManifest.androidlib.meta b/Assets/Plugins/Android/GooglePlayGamesManifest.androidlib.meta
deleted file mode 100644
index fa0745149..000000000
--- a/Assets/Plugins/Android/GooglePlayGamesManifest.androidlib.meta
+++ /dev/null
@@ -1,143 +0,0 @@
-fileFormatVersion: 2
-guid: 44f4150f398dc4f22b230f8c74866383
-folderAsset: yes
-timeCreated: 1504033921
-licenseType: Pro
-PluginImporter:
- serializedVersion: 2
- iconMap: {}
- executionOrder: {}
- isPreloaded: 0
- isOverridable: 0
- platformData:
- data:
- first:
- '': Any
- second:
- enabled: 0
- settings:
- Exclude Android: 0
- Exclude Editor: 0
- Exclude Linux: 0
- Exclude Linux64: 0
- Exclude LinuxUniversal: 0
- Exclude OSXIntel: 0
- Exclude OSXIntel64: 0
- Exclude OSXUniversal: 0
- Exclude WebGL: 0
- Exclude Win: 0
- Exclude Win64: 0
- Exclude iOS: 0
- data:
- first:
- '': Editor
- second:
- enabled: 0
- settings:
- CPU: AnyCPU
- OS: AnyOS
- data:
- first:
- Android: Android
- second:
- enabled: 1
- settings:
- CPU: ARMv7
- data:
- first:
- Any:
- second:
- enabled: 1
- settings: {}
- data:
- first:
- Editor: Editor
- second:
- enabled: 1
- settings:
- DefaultValueInitialized: true
- data:
- first:
- Facebook: Win
- second:
- enabled: 0
- settings:
- CPU: AnyCPU
- data:
- first:
- Facebook: Win64
- second:
- enabled: 0
- settings:
- CPU: AnyCPU
- data:
- first:
- Standalone: Linux
- second:
- enabled: 1
- settings:
- CPU: x86
- data:
- first:
- Standalone: Linux64
- second:
- enabled: 1
- settings:
- CPU: x86_64
- data:
- first:
- Standalone: LinuxUniversal
- second:
- enabled: 1
- settings: {}
- data:
- first:
- Standalone: OSXIntel
- second:
- enabled: 1
- settings:
- CPU: AnyCPU
- data:
- first:
- Standalone: OSXIntel64
- second:
- enabled: 1
- settings:
- CPU: AnyCPU
- data:
- first:
- Standalone: OSXUniversal
- second:
- enabled: 1
- settings: {}
- data:
- first:
- Standalone: Win
- second:
- enabled: 1
- settings:
- CPU: AnyCPU
- data:
- first:
- Standalone: Win64
- second:
- enabled: 1
- settings:
- CPU: AnyCPU
- data:
- first:
- WebGL: WebGL
- second:
- enabled: 1
- settings: {}
- data:
- first:
- iPhone: iOS
- second:
- enabled: 1
- settings:
- CompileFlags:
- FrameworkDependencies:
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/Plugins/Android/GooglePlayGamesManifest.androidlib/AndroidManifest.xml.meta b/Assets/Plugins/Android/GooglePlayGamesManifest.androidlib/AndroidManifest.xml.meta
deleted file mode 100644
index a060c97be..000000000
--- a/Assets/Plugins/Android/GooglePlayGamesManifest.androidlib/AndroidManifest.xml.meta
+++ /dev/null
@@ -1,8 +0,0 @@
-fileFormatVersion: 2
-guid: 0a6132672415643e8b1f16585785afe9
-timeCreated: 1504034459
-licenseType: Pro
-TextScriptImporter:
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/Plugins/Android/GooglePlayGamesManifest.androidlib/project.properties b/Assets/Plugins/Android/GooglePlayGamesManifest.androidlib/project.properties
deleted file mode 100644
index f438126c4..000000000
--- a/Assets/Plugins/Android/GooglePlayGamesManifest.androidlib/project.properties
+++ /dev/null
@@ -1,2 +0,0 @@
-target=android-16
-android.library=true
diff --git a/Assets/Plugins/Android/GooglePlayGamesManifest.androidlib/project.properties.meta b/Assets/Plugins/Android/GooglePlayGamesManifest.androidlib/project.properties.meta
deleted file mode 100644
index f43a87ce3..000000000
--- a/Assets/Plugins/Android/GooglePlayGamesManifest.androidlib/project.properties.meta
+++ /dev/null
@@ -1,4 +0,0 @@
-fileFormatVersion: 2
-guid: 6156f0fc2bafa4f0c86d61673c0068d0
-DefaultImporter:
- userData:
diff --git a/Assets/Public/GooglePlayGames/com.google.play.games/Editor/Dependencies.xml b/Assets/Public/GooglePlayGames/com.google.play.games/Editor/Dependencies.xml
new file mode 100644
index 000000000..2fc4e5eeb
--- /dev/null
+++ b/Assets/Public/GooglePlayGames/com.google.play.games/Editor/Dependencies.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/Assets/Public/GooglePlayGames/com.google.play.games/Editor/template-AndroidManifest.txt.meta b/Assets/Public/GooglePlayGames/com.google.play.games/Editor/Dependencies.xml.meta
similarity index 54%
rename from Assets/Public/GooglePlayGames/com.google.play.games/Editor/template-AndroidManifest.txt.meta
rename to Assets/Public/GooglePlayGames/com.google.play.games/Editor/Dependencies.xml.meta
index e777dbe6c..f54f057cd 100644
--- a/Assets/Public/GooglePlayGames/com.google.play.games/Editor/template-AndroidManifest.txt.meta
+++ b/Assets/Public/GooglePlayGames/com.google.play.games/Editor/Dependencies.xml.meta
@@ -1,8 +1,7 @@
fileFormatVersion: 2
-guid: 0e1f3c150256848b1ba98702cfb71220
-timeCreated: 1435699670
-licenseType: Pro
+guid: 934b981265cbf984fa7fc451550eadcc
TextScriptImporter:
+ externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
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 4eadb15ac..bff31563b 100644
--- a/Assets/Public/GooglePlayGames/com.google.play.games/Editor/GPGSUtil.cs
+++ b/Assets/Public/GooglePlayGames/com.google.play.games/Editor/GPGSUtil.cs
@@ -22,6 +22,7 @@ namespace GooglePlayGames.Editor
using System.Collections.Generic;
using System.IO;
using System.Xml;
+ using System.Linq;
using UnityEditor;
using UnityEngine;
@@ -100,15 +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";
@@ -119,55 +112,42 @@ public static string RootPath
{
get
{
- if (string.IsNullOrEmpty(mRootPath))
+ if (string.IsNullOrEmpty(mRootPath) || !Directory.Exists(mRootPath))
{
#if UNITY_2018_4_OR_NEWER
- // Search for root path in plugin locations for both Asset packages and UPM packages
- string[] dirs = Directory.GetDirectories("Packages", RootFolderName, SearchOption.AllDirectories);
- string[] dir1 = Directory.GetDirectories("Assets", RootFolderName, SearchOption.AllDirectories);
- int dirsLength = dirs.Length;
- Array.Resize(ref dirs, dirsLength + dir1.Length);
- Array.Copy(dir1, 0, dirs, dirsLength, dir1.Length);
-#else
- string[] dirs = Directory.GetDirectories("Assets", RootFolderName, SearchOption.AllDirectories);
+ mRootPath = Path.GetFullPath(Path.Combine("Packages",RootFolderName));
+ if(Directory.Exists(mRootPath))
+ return mRootPath;
+#endif
+
+ string[] dirs = new[] {
+#if UNITY_2018_4_OR_NEWER
+ // search for remote UPM installation
+ Path.Join("Library","PackageCache"),
+ "Packages",
#endif
- switch (dirs.Length)
+ "Assets"
+ }.Distinct().SelectMany((path) => {
+ return Directory.GetDirectories(path, RootFolderName + "*", SearchOption.AllDirectories);
+ }).Distinct().ToArray();
+
+ mRootPath = dirs.Select((dir) => SlashesToPlatformSeparator(dir)).FirstOrDefault((dir) => File.Exists(Path.Combine(dir,GameInfoRelativePath)));
+
+ 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;
}
}
@@ -177,17 +157,7 @@ public static string RootPath
///
private static string GameInfoPath
{
- get { return SlashesToPlatformSeparator(Path.Combine(RootPath, GameInfoRelativePath)); }
- }
-
- ///
- /// The manifest path.
- ///
- /// The Games SDK requires additional metadata in the AndroidManifest.xml
- /// file.
- private static string ManifestPath
- {
- get { return SlashesToPlatformSeparator(Path.Combine(RootPath, ManifestRelativePath)); }
+ get { return SlashesToPlatformSeparator(Path.Combine("Assets", GameInfoRelativePath)); }
}
///
@@ -221,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);
}
///
@@ -251,8 +221,7 @@ public static string ReadFile(string filePath)
/// Name of the template in the editor directory.
public static string ReadEditorTemplate(string name)
{
- return ReadFile(
- Path.Combine(RootPath, string.Format("Editor{0}{1}.txt", Path.DirectorySeparatorChar, name)));
+ return ReadFile(Path.Combine(RootPath,"Editor",string.Format("{0}.txt", name)));
}
///
@@ -491,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);
}
///
@@ -516,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.
@@ -654,84 +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(GPGSUtil.RootPath,
- "Editor/GooglePlayGamesPluginDependencies.xml"));
-
- 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[] foundPaths =
- Directory.GetFiles(RootPath, "GooglePlayGamesPlugin_v*.txt", SearchOption.AllDirectories);
-
- 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/Editor/template-AndroidManifest.txt b/Assets/Public/GooglePlayGames/com.google.play.games/Editor/template-AndroidManifest.txt
deleted file mode 100644
index d32616fb6..000000000
--- a/Assets/Public/GooglePlayGames/com.google.play.games/Editor/template-AndroidManifest.txt
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-
-
- __NEARBY_PERMISSIONS__
-
-
-
- __NEARBY_SERVICE_ELEMENT__
-
-
-
-
-
-
-
-
-
-
-
diff --git a/Assets/Public/GooglePlayGames/com.google.play.games/Editor/m2repository.meta b/Assets/Public/GooglePlayGames/com.google.play.games/Proguard.meta
similarity index 80%
rename from Assets/Public/GooglePlayGames/com.google.play.games/Editor/m2repository.meta
rename to Assets/Public/GooglePlayGames/com.google.play.games/Proguard.meta
index b57f75888..4a7d303ba 100644
--- a/Assets/Public/GooglePlayGames/com.google.play.games/Editor/m2repository.meta
+++ b/Assets/Public/GooglePlayGames/com.google.play.games/Proguard.meta
@@ -1,8 +1,6 @@
fileFormatVersion: 2
guid: a1aac54589c4640cd89900056af3a094
folderAsset: yes
-timeCreated: 1515000812
-licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
diff --git a/Assets/Public/GooglePlayGames/com.google.play.games/Proguard/games.txt b/Assets/Public/GooglePlayGames/com.google.play.games/Proguard/games.txt
index 63c7b08cf..62b587d3a 100644
--- a/Assets/Public/GooglePlayGames/com.google.play.games/Proguard/games.txt
+++ b/Assets/Public/GooglePlayGames/com.google.play.games/Proguard/games.txt
@@ -1,8 +1,10 @@
+-keep class com.google.android.gms.games.PlayGames { *; }
-keep class com.google.android.gms.games.leaderboard.** { *; }
-keep class com.google.android.gms.games.snapshot.** { *; }
-keep class com.google.android.gms.games.achievement.** { *; }
-keep class com.google.android.gms.games.event.** { *; }
-keep class com.google.android.gms.games.stats.** { *; }
+-keep class com.google.android.gms.games.video.** { *; }
-keep class com.google.android.gms.games.* { *; }
-keep class com.google.android.gms.common.api.ResultCallback { *; }
-keep class com.google.android.gms.signin.** { *; }
@@ -17,4 +19,5 @@
-keep class com.google.android.gms.common.GooglePlayServicesUtil { *; }
-keep class com.google.android.gms.common.api.** { *; }
-keep class com.google.android.gms.common.data.DataBufferUtils { *; }
+-keep class com.google.android.gms.games.quest.** { *; }
-keep class com.google.android.gms.nearby.** { *; }
diff --git a/Assets/Public/GooglePlayGames/com.google.play.games/Editor/GooglePlayGamesPlugin.txt.meta b/Assets/Public/GooglePlayGames/com.google.play.games/Proguard/games.txt.meta
similarity index 84%
rename from Assets/Public/GooglePlayGames/com.google.play.games/Editor/GooglePlayGamesPlugin.txt.meta
rename to Assets/Public/GooglePlayGames/com.google.play.games/Proguard/games.txt.meta
index 5932b27aa..a511a9780 100644
--- a/Assets/Public/GooglePlayGames/com.google.play.games/Editor/GooglePlayGamesPlugin.txt.meta
+++ b/Assets/Public/GooglePlayGames/com.google.play.games/Proguard/games.txt.meta
@@ -5,6 +5,3 @@ TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant:
-labels:
-- gvh
-- gvh_manifest
diff --git a/Assets/Public/GooglePlayGames/com.google.play.games/Runtime.meta b/Assets/Public/GooglePlayGames/com.google.play.games/Runtime.meta
new file mode 100644
index 000000000..1b4e5aa47
--- /dev/null
+++ b/Assets/Public/GooglePlayGames/com.google.play.games/Runtime.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: fd0ac925755a93f468f9512314445211
+folderAsset: yes
+DefaultImporter:
+ externalObjects: {}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts.meta b/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts.meta
new file mode 100644
index 000000000..05a73186a
--- /dev/null
+++ b/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 59e19e4181908444696b31ddc5d39242
+folderAsset: yes
+DefaultImporter:
+ externalObjects: {}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
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/GameInfo.cs b/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/GameInfo.cs
deleted file mode 100644
index d6a65d680..000000000
--- a/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/GameInfo.cs
+++ /dev/null
@@ -1,72 +0,0 @@
-//
-// Copyright (C) 2015 Google Inc. All Rights Reserved.
-//
-// 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
-{
- ///
- /// This file is automatically generated DO NOT EDIT!
- ///
- /// These are the constants defined in the Play Games Console for Game Services
- /// Resources.
- ///
- ///
- /// File containing information about the game. This is automatically updated by running the
- /// platform-appropriate setup commands in the Unity editor (which does a simple search / replace
- /// on the IDs in the form "__ID__"). We can check whether any particular field has been updated
- /// by checking whether it still retains its initial value - we prevent the constants from being
- /// replaced in the aforementioned search/replace by stripping off the leading and trailing "__".
- ///
- public static class GameInfo
- {
- private const string UnescapedApplicationId = "APP_ID";
- private const string UnescapedWebClientId = "WEB_CLIENTID";
- private const string UnescapedNearbyServiceId = "NEARBY_SERVICE_ID";
-
- public const string ApplicationId = "__APP_ID__"; // Filled in automatically
- public const string WebClientId = "__WEB_CLIENTID__"; // Filled in automatically
- public const string NearbyConnectionServiceId = "__NEARBY_SERVICE_ID__";
-
-
- public static bool ApplicationIdInitialized()
- {
- return !string.IsNullOrEmpty(ApplicationId) &&
- !ApplicationId.Equals(ToEscapedToken(UnescapedApplicationId));
- }
-
- public static bool WebClientIdInitialized()
- {
- return !string.IsNullOrEmpty(WebClientId) && !WebClientId.Equals(ToEscapedToken(UnescapedWebClientId));
- }
-
- public static bool NearbyConnectionsInitialized()
- {
- return !string.IsNullOrEmpty(NearbyConnectionServiceId) &&
- !NearbyConnectionServiceId.Equals(ToEscapedToken(UnescapedNearbyServiceId));
- }
-
- ///
- /// Returns an escaped token (i.e. one flanked with "__") for the passed token
- ///
- /// The escaped token.
- /// The Token
- private static string ToEscapedToken(string token)
- {
- return string.Format("__{0}__", token);
- }
- }
-}
-#endif //UNITY_ANDROID
\ No newline at end of file
diff --git a/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/GameInfo.cs.meta b/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/GameInfo.cs.meta
deleted file mode 100644
index fd031ffb8..000000000
--- a/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/GameInfo.cs.meta
+++ /dev/null
@@ -1,12 +0,0 @@
-fileFormatVersion: 2
-guid: a722d413080904cc1bd07f4db21e1af1
-timeCreated: 1435699550
-licenseType: Pro
-MonoImporter:
- serializedVersion: 2
- defaultReferences: []
- executionOrder: 0
- icon: {instanceID: 0}
- userData:
- assetBundleName:
- assetBundleVariant:
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..0bfe18291 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,9 +19,11 @@
namespace GooglePlayGames
{
using System;
- using System.Collections;
- using GooglePlayGames.OurUtils;
+
using UnityEngine;
+
+ using GooglePlayGames.OurUtils;
+
#if UNITY_2017_2_OR_NEWER
using UnityEngine.Networking;
#endif
@@ -42,18 +44,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 +57,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 +106,42 @@ public Texture2D image
{
OurUtils.Logger.d("Starting to load image: " + AvatarURL);
mImageLoading = true;
- PlayGamesHelperObject.RunCoroutine(LoadImage());
+
+ mImage = new Texture2D(96,96);
+
+ using(var currentActivity = Android.AndroidHelperFragment.GetActivity())
+ {
+ currentActivity.Call("runOnUiThread", new AndroidJavaRunnable(() => {
+ 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",new OnLoadImageListener((result) => {
+ PlayGamesHelperObject.RunOnGameThread(() => {
+ var (uri,drawable,isRequestedDrawable) = 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();
+ });
+ }),uri);
+ }
+ }));
+ }
}
return mImage;
@@ -126,50 +155,17 @@ 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))
+ private Action<(AndroidJavaObject uri, AndroidJavaObject drawable, bool isRequestedDrawable)> mAction;
+ public OnLoadImageListener(Action<(AndroidJavaObject uri, AndroidJavaObject drawable, bool isRequestedDrawable)> action) : base("com.google.android.gms.common.images.ImageManager$OnImageLoadedListener")
{
-#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;
- }
-
- 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);
- }
-
- mImageLoading = false;
+ mAction = action;
}
- else
+
+ public void onImageLoaded(AndroidJavaObject uri, AndroidJavaObject drawable, bool isRequestedDrawable)
{
- OurUtils.Logger.e("No URL found.");
- mImage = Texture2D.blackTexture;
- mImageLoading = false;
+ mAction((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..2eb70ef8f 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;
@@ -85,7 +84,7 @@ private void Authenticate(bool isAutoSignIn, Action callback)
{
// If the user is already authenticated, just fire the callback, we don't need
// any additional work.
- if (mAuthState == AuthState.Authenticated)
+ if (isAutoSignIn && mAuthState == AuthState.Authenticated)
{
OurUtils.Logger.d("Already authenticated.");
InvokeCallbackOnGameThread(callback, SignInStatus.Success);
@@ -97,85 +96,70 @@ 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 =>
- {
+ task.AddOnSuccessListener(authenticationResult => {
bool isAuthenticated = authenticationResult.Call("isAuthenticated");
- SignInOnResult(isAuthenticated, callback);
- });
+ if (!isAuthenticated)
+ {
+ lock (AuthStateLock)
+ {
+ OurUtils.Logger.e("Not authenticated");
+ callback(SignInStatus.Canceled);
+ return;
+ }
+ }
- AndroidTaskUtils.AddOnFailureListener(task, exception =>
- {
+ using (var client = getPlayersClient())
+ using (client.Call("getCurrentPlayer").AddOnSuccessListener((AndroidJavaObject resultObject) => {
+ mUser = AndroidJavaConverter.ToPlayer(resultObject);
+
+ lock (GameServicesLock)
+ {
+ mSavedGameClient = new AndroidSavedGameClient(this);
+ mEventsClient = new AndroidEventsClient();
+ }
+
+ mAuthState = AuthState.Authenticated;
+ InvokeCallbackOnGameThread(callback, SignInStatus.Success);
+ OurUtils.Logger.d("Authentication succeeded");
+ LoadAchievements(ignore => { });
+ }).AddOnFailureListener((exception) => {
+ OurUtils.Logger.e("GetCurrentPlayer failed - " + exception.Call("toString"));
+ callback(SignInStatus.InternalError);
+ }).AddOnCanceledListener(() => {
+ callback(SignInStatus.Canceled);
+ }));
+ }).AddOnFailureListener(exception => {
OurUtils.Logger.e("Authentication failed - " + exception.Call("toString"));
callback(SignInStatus.InternalError);
+ }).AddOnCanceledListener(() => {
+ callback(SignInStatus.Canceled);
});
}
}
- private void SignInOnResult(bool isAuthenticated, Action callback)
+ static string appID = null;
+ public static string AppId
{
- if (isAuthenticated)
+ get
{
- using (var signInTasks = new AndroidJavaObject("java.util.ArrayList"))
- {
- AndroidJavaObject taskGetPlayer =
- getPlayersClient().Call("getCurrentPlayer");
- signInTasks.Call("add", taskGetPlayer);
+ if(appID == null)
+ appID = AndroidHelperFragment.CallPackageMetaData("GET_META_DATA","getString","com.google.android.gms.games.APP_ID") ?? "";
- using (var tasks = new AndroidJavaClass(TasksClassName))
- using (var allTask = tasks.CallStatic("whenAll", signInTasks))
- {
- AndroidTaskUtils.AddOnCompleteListener(
- allTask,
- completeTask =>
- {
- if (completeTask.Call("isSuccessful"))
- {
- using (var resultObject = taskGetPlayer.Call("getResult"))
- {
- mUser = AndroidJavaConverter.ToPlayer(resultObject);
- }
-
- lock (GameServicesLock)
- {
- mSavedGameClient = new AndroidSavedGameClient(this);
- mEventsClient = new AndroidEventsClient();
- }
-
- mAuthState = AuthState.Authenticated;
- InvokeCallbackOnGameThread(callback, SignInStatus.Success);
- OurUtils.Logger.d("Authentication succeeded");
- LoadAchievements(ignore => { });
- }
- else
- {
- if (completeTask.Call("isCanceled"))
- {
- InvokeCallbackOnGameThread(callback, SignInStatus.Canceled);
- return;
- }
-
- using (var exception = completeTask.Call("getException"))
- {
- OurUtils.Logger.e(
- "Authentication failed - " + exception.Call("toString"));
- InvokeCallbackOnGameThread(callback, SignInStatus.InternalError);
- }
- }
- }
- );
- }
- }
+ return appID;
}
- else
+ }
+
+ static string webClientId = null;
+ public static string WebClientId
+ {
+ get
{
- lock (AuthStateLock)
- {
- OurUtils.Logger.e("Returning an error code.");
- InvokeCallbackOnGameThread(callback, SignInStatus.Canceled);
- }
+ if(webClientId == null)
+ webClientId = AndroidHelperFragment.CallPackageMetaData("GET_META_DATA","getString","com.google.android.gms.games.WEB_CLIENT_ID") ?? "";
+
+ return webClientId;
}
}
@@ -183,25 +167,14 @@ public void RequestServerSideAccess(bool forceRefreshToken, Action callb
{
callback = AsOnGameThreadCallback(callback);
- if (!GameInfo.WebClientIdInitialized())
- {
- throw new InvalidOperationException("Requesting server side access requires web " +
- "client id to be configured.");
- }
+ 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,
- authCode => callback(authCode)
- );
-
- AndroidTaskUtils.AddOnFailureListener(task, exception =>
- {
- OurUtils.Logger.e("Requesting server side access task failed - " +
- exception.Call("toString"));
+ task.AddOnSuccessListener(authCode => callback(authCode)).AddOnFailureListener((exception) => {
+ OurUtils.Logger.e("Requesting server side access task failed - " + exception.Call("toString"));
callback(null);
});
}
@@ -261,8 +234,7 @@ private static void InvokeCallbackOnGameThread(Action callback, T data)
}
- private static Action AsOnGameThreadCallback(
- Action toInvokeOnGameThread)
+ private static Action AsOnGameThreadCallback(Action toInvokeOnGameThread)
{
return (result1, result2) =>
{
@@ -298,11 +270,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 +296,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,34 +308,28 @@ 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())
using (var task = isLoadMore
? playersClient.Call("loadMoreFriends", pageSize)
- : playersClient.Call("loadFriends", pageSize,
- forceReload))
+ : playersClient.Call("loadFriends", pageSize, forceReload))
{
- AndroidTaskUtils.AddOnSuccessListener(
- task, annotatedData =>
+ task.AddOnSuccessListener(annotatedData => {
+ using (var playersBuffer = annotatedData.Call("get"))
{
- using (var playersBuffer = annotatedData.Call("get"))
- {
- AndroidJavaObject metadata = playersBuffer.Call("getMetadata");
- var areMoreFriendsToLoad = metadata != null &&
- metadata.Call("getString",
- "next_page_token") != null;
- mFriends = AndroidJavaConverter.playersBufferToArray(playersBuffer);
- mLastLoadFriendsStatus = areMoreFriendsToLoad
- ? LoadFriendsStatus.LoadMore
- : LoadFriendsStatus.Completed;
- InvokeCallbackOnGameThread(callback, mLastLoadFriendsStatus);
- }
- });
- AndroidTaskUtils.AddOnFailureListener(task, exception =>
- {
+ AndroidJavaObject metadata = playersBuffer.Call("getMetadata");
+ var areMoreFriendsToLoad = metadata != null &&
+ metadata.Call("getString",
+ "next_page_token") != null;
+ mFriends = AndroidJavaConverter.playersBufferToArray(playersBuffer);
+ mLastLoadFriendsStatus = areMoreFriendsToLoad
+ ? LoadFriendsStatus.LoadMore
+ : LoadFriendsStatus.Completed;
+ InvokeCallbackOnGameThread(callback, mLastLoadFriendsStatus);
+ }
+ }).AddOnFailureListener(exception => {
AndroidHelperFragment.IsResolutionRequired(exception, resolutionRequired =>
{
if (resolutionRequired)
@@ -393,8 +356,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);
}
});
@@ -404,8 +366,7 @@ private void LoadFriendsPaginated(int pageSize, bool isLoadMore, bool forceReloa
}
private static bool IsApiException(AndroidJavaObject exception) {
- var exceptionClassName = exception.Call("getClass")
- .Call("getName");
+ var exceptionClassName = exception.Call("getClass").Call("getName");
return exceptionClassName == "com.google.android.gms.common.api.ApiException";
}
@@ -422,14 +383,11 @@ 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); });
- AndroidTaskUtils.AddOnFailureListener(task, exception =>
- {
+ task.AddOnSuccessListener(annotatedData => {
+ InvokeCallbackOnGameThread(callback, UIStatus.Valid);
+ }).AddOnFailureListener(exception => {
AndroidHelperFragment.IsResolutionRequired(exception, resolutionRequired =>
{
if (resolutionRequired)
@@ -452,8 +410,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 +418,7 @@ public void AskForLoadFriendsResolution(Action callback)
}
else
{
- AndroidHelperFragment.AskForLoadFriendsResolution(mFriendsResolutionException,
- AsOnGameThreadCallback(callback));
+ AndroidHelperFragment.AskForLoadFriendsResolution(mFriendsResolutionException,AsOnGameThreadCallback(callback));
}
}
@@ -476,15 +432,12 @@ 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 =>
- {
+ task.AddOnSuccessListener(annotatedData => {
AndroidJavaObject currentPlayerInfo =
annotatedData.Call("get").Call(
"getCurrentPlayerInfo");
@@ -492,11 +445,8 @@ public void GetFriendsListVisibility(bool forceReload,
currentPlayerInfo.Call("getFriendsListVisibilityStatus");
InvokeCallbackOnGameThread(callback,
AndroidJavaConverter.ToFriendsListVisibilityStatus(playerListVisibility));
- });
- AndroidTaskUtils.AddOnFailureListener(task, exception =>
- {
+ }).AddOnFailureListener(exception => {
InvokeCallbackOnGameThread(callback, FriendsListVisibilityStatus.NetworkError);
- return;
});
}
}
@@ -541,41 +491,35 @@ public void GetPlayerStats(Action callback)
using (var playerStatsClient = getPlayerStatsClient())
using (var task = playerStatsClient.Call("loadPlayerStats", /* forceReload= */ false))
{
- AndroidTaskUtils.AddOnSuccessListener(
- task,
- annotatedData =>
+ task.AddOnSuccessListener(annotatedData => {
+ using (var playerStatsJava = annotatedData.Call("get"))
{
- using (var playerStatsJava = annotatedData.Call("get"))
- {
- int numberOfPurchases = playerStatsJava.Call("getNumberOfPurchases");
- float avgSessionLength = playerStatsJava.Call("getAverageSessionLength");
- int daysSinceLastPlayed = playerStatsJava.Call("getDaysSinceLastPlayed");
- int numberOfSessions = playerStatsJava.Call("getNumberOfSessions");
- float sessionPercentile = playerStatsJava.Call("getSessionPercentile");
- float spendPercentile = playerStatsJava.Call("getSpendPercentile");
- float spendProbability = playerStatsJava.Call("getSpendProbability");
- float churnProbability = playerStatsJava.Call("getChurnProbability");
- float highSpenderProbability = playerStatsJava.Call("getHighSpenderProbability");
- float totalSpendNext28Days = playerStatsJava.Call("getTotalSpendNext28Days");
-
- PlayerStats result = new PlayerStats(
- numberOfPurchases,
- avgSessionLength,
- daysSinceLastPlayed,
- numberOfSessions,
- sessionPercentile,
- spendPercentile,
- spendProbability,
- churnProbability,
- highSpenderProbability,
- totalSpendNext28Days);
-
- InvokeCallbackOnGameThread(callback, CommonStatusCodes.Success, result);
- }
- });
-
- AndroidTaskUtils.AddOnFailureListener(task, exception =>
- {
+ int numberOfPurchases = playerStatsJava.Call("getNumberOfPurchases");
+ float avgSessionLength = playerStatsJava.Call("getAverageSessionLength");
+ int daysSinceLastPlayed = playerStatsJava.Call("getDaysSinceLastPlayed");
+ int numberOfSessions = playerStatsJava.Call("getNumberOfSessions");
+ float sessionPercentile = playerStatsJava.Call("getSessionPercentile");
+ float spendPercentile = playerStatsJava.Call("getSpendPercentile");
+ float spendProbability = playerStatsJava.Call("getSpendProbability");
+ float churnProbability = playerStatsJava.Call("getChurnProbability");
+ float highSpenderProbability = playerStatsJava.Call("getHighSpenderProbability");
+ float totalSpendNext28Days = playerStatsJava.Call("getTotalSpendNext28Days");
+
+ PlayerStats result = new PlayerStats(
+ numberOfPurchases,
+ avgSessionLength,
+ daysSinceLastPlayed,
+ numberOfSessions,
+ sessionPercentile,
+ spendPercentile,
+ spendProbability,
+ churnProbability,
+ highSpenderProbability,
+ totalSpendNext28Days);
+
+ InvokeCallbackOnGameThread(callback, CommonStatusCodes.Success, result);
+ }
+ }).AddOnFailureListener(exception => {
OurUtils.Logger.e("GetPlayerStats failed: " + exception.Call("toString"));
var statusCode = IsAuthenticated()
? CommonStatusCodes.InternalError
@@ -603,35 +547,29 @@ public void LoadUsers(string[] userIds, Action callback)
{
using (var task = playersClient.Call("loadPlayer", userIds[i]))
{
- AndroidTaskUtils.AddOnSuccessListener(
- task,
- annotatedData =>
+ task.AddOnSuccessListener(annotatedData => {
+ using (var player = annotatedData.Call("get"))
{
- using (var player = annotatedData.Call("get"))
+ string playerId = player.Call("getPlayerId");
+ for (int j = 0; j < count; ++j)
{
- string playerId = player.Call("getPlayerId");
- for (int j = 0; j < count; ++j)
+ if (playerId == userIds[j])
{
- if (playerId == userIds[j])
- {
- users[j] = AndroidJavaConverter.ToPlayer(player);
- break;
- }
+ users[j] = AndroidJavaConverter.ToPlayer(player);
+ break;
}
+ }
- lock (countLock)
+ lock (countLock)
+ {
+ ++resultCount;
+ if (resultCount == count)
{
- ++resultCount;
- if (resultCount == count)
- {
- InvokeCallbackOnGameThread(callback, users);
- }
+ InvokeCallbackOnGameThread(callback, users);
}
}
- });
-
- AndroidTaskUtils.AddOnFailureListener(task, exception =>
- {
+ }
+ }).AddOnFailureListener(exception => {
OurUtils.Logger.e("LoadUsers failed for index " + i +
" with: " + exception.Call("toString"));
lock (countLock)
@@ -653,52 +591,46 @@ public void LoadAchievements(Action callback)
using (var achievementsClient = getAchievementsClient())
using (var task = achievementsClient.Call("load", /* forceReload= */ false))
{
- AndroidTaskUtils.AddOnSuccessListener(
- task,
- annotatedData =>
+ task.AddOnSuccessListener(annotatedData => {
+ using (var achievementBuffer = annotatedData.Call("get"))
{
- using (var achievementBuffer = annotatedData.Call("get"))
+ int count = achievementBuffer.Call("getCount");
+ Achievement[] result = new Achievement[count];
+ for (int i = 0; i < count; ++i)
{
- int count = achievementBuffer.Call("getCount");
- Achievement[] result = new Achievement[count];
- for (int i = 0; i < count; ++i)
+ Achievement achievement = new Achievement();
+ using (var javaAchievement = achievementBuffer.Call("get", i))
{
- Achievement achievement = new Achievement();
- using (var javaAchievement = achievementBuffer.Call("get", i))
+ achievement.Id = javaAchievement.Call("getAchievementId");
+ achievement.Description = javaAchievement.Call("getDescription");
+ achievement.Name = javaAchievement.Call("getName");
+ achievement.Points = javaAchievement.Call("getXpValue");
+
+ long timestamp = javaAchievement.Call("getLastUpdatedTimestamp");
+ achievement.LastModifiedTime = AndroidJavaConverter.ToDateTime(timestamp);
+
+ achievement.RevealedImageUrl = javaAchievement.Call("getRevealedImageUrl");
+ achievement.UnlockedImageUrl = javaAchievement.Call("getUnlockedImageUrl");
+ achievement.IsIncremental =
+ javaAchievement.Call("getType") == 1 /* TYPE_INCREMENTAL */;
+ if (achievement.IsIncremental)
{
- achievement.Id = javaAchievement.Call("getAchievementId");
- achievement.Description = javaAchievement.Call("getDescription");
- achievement.Name = javaAchievement.Call("getName");
- achievement.Points = javaAchievement.Call("getXpValue");
-
- long timestamp = javaAchievement.Call("getLastUpdatedTimestamp");
- achievement.LastModifiedTime = AndroidJavaConverter.ToDateTime(timestamp);
-
- achievement.RevealedImageUrl = javaAchievement.Call("getRevealedImageUrl");
- achievement.UnlockedImageUrl = javaAchievement.Call("getUnlockedImageUrl");
- achievement.IsIncremental =
- javaAchievement.Call("getType") == 1 /* TYPE_INCREMENTAL */;
- if (achievement.IsIncremental)
- {
- achievement.CurrentSteps = javaAchievement.Call("getCurrentSteps");
- achievement.TotalSteps = javaAchievement.Call("getTotalSteps");
- }
-
- int state = javaAchievement.Call("getState");
- achievement.IsUnlocked = state == 0 /* STATE_UNLOCKED */;
- achievement.IsRevealed = state == 1 /* STATE_REVEALED */;
+ achievement.CurrentSteps = javaAchievement.Call("getCurrentSteps");
+ achievement.TotalSteps = javaAchievement.Call("getTotalSteps");
}
- result[i] = achievement;
+ int state = javaAchievement.Call("getState");
+ achievement.IsUnlocked = state == 0 /* STATE_UNLOCKED */;
+ achievement.IsRevealed = state == 1 /* STATE_REVEALED */;
}
- achievementBuffer.Call("release");
- InvokeCallbackOnGameThread(callback, result);
+ result[i] = achievement;
}
- });
- AndroidTaskUtils.AddOnFailureListener(task, exception =>
- {
+ achievementBuffer.Call("release");
+ InvokeCallbackOnGameThread(callback, result);
+ }
+ }).AddOnFailureListener(exception => {
OurUtils.Logger.e("LoadAchievements failed: " + exception.Call("toString"));
InvokeCallbackOnGameThread(callback, new Achievement[0]);
});
@@ -806,90 +738,67 @@ public void LoadScores(string leaderboardId, LeaderboardStart start,
Action callback)
{
using (var client = getLeaderboardsClient())
- {
- string loadScoresMethod =
- start == LeaderboardStart.TopScores ? "loadTopScores" : "loadPlayerCenteredScores";
- using (var task = client.Call(
- loadScoresMethod,
- leaderboardId,
- AndroidJavaConverter.ToLeaderboardVariantTimeSpan(timeSpan),
- AndroidJavaConverter.ToLeaderboardVariantCollection(collection),
- rowCount))
- {
- AndroidTaskUtils.AddOnSuccessListener(
- task,
- annotatedData =>
- {
- using (var leaderboardScores = annotatedData.Call("get"))
- {
- InvokeCallbackOnGameThread(callback, CreateLeaderboardScoreData(
- leaderboardId,
- collection,
- timeSpan,
- annotatedData.Call("isStale")
- ? ResponseStatus.SuccessWithStale
- : ResponseStatus.Success,
- leaderboardScores));
- leaderboardScores.Call("release");
- }
- });
-
- AndroidTaskUtils.AddOnFailureListener(task, exception =>
+ using (var task = client.Call(
+ start == LeaderboardStart.TopScores ? "loadTopScores" : "loadPlayerCenteredScores",
+ leaderboardId,
+ AndroidJavaConverter.ToLeaderboardVariantTimeSpan(timeSpan),
+ AndroidJavaConverter.ToLeaderboardVariantCollection(collection),
+ rowCount))
+ {
+ task.AddOnSuccessListener(annotatedData => {
+ using (var leaderboardScores = annotatedData.Call("get"))
{
- AndroidHelperFragment.IsResolutionRequired(
- exception, resolutionRequired =>
- {
- if (resolutionRequired)
- {
- mFriendsResolutionException = exception.Call(
- "getResolution");
- InvokeCallbackOnGameThread(
- callback, new LeaderboardScoreData(leaderboardId,
- ResponseStatus.ResolutionRequired));
- }
- else
- {
- mFriendsResolutionException = null;
- }
- });
- OurUtils.Logger.e("LoadScores failed: " + exception.Call("toString"));
- InvokeCallbackOnGameThread(
- callback, new LeaderboardScoreData(leaderboardId,
- ResponseStatus.InternalError));
+ InvokeCallbackOnGameThread(callback, CreateLeaderboardScoreData(
+ leaderboardId,
+ collection,
+ timeSpan,
+ annotatedData.Call("isStale")
+ ? ResponseStatus.SuccessWithStale
+ : ResponseStatus.Success,
+ leaderboardScores));
+ leaderboardScores.Call("release");
+ }
+ }).AddOnFailureListener(exception => {
+ AndroidHelperFragment.IsResolutionRequired(exception, resolutionRequired => {
+ if (resolutionRequired)
+ {
+ mFriendsResolutionException = exception.Call("getResolution");
+ InvokeCallbackOnGameThread(
+ callback, new LeaderboardScoreData(leaderboardId,ResponseStatus.ResolutionRequired));
+ }
+ else
+ {
+ mFriendsResolutionException = null;
+ }
});
- }
+
+ OurUtils.Logger.e("LoadScores failed: " + exception.Call("toString"));
+ InvokeCallbackOnGameThread(callback, new LeaderboardScoreData(leaderboardId,ResponseStatus.InternalError));
+ });
}
}
- 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",
token.InternalObject, rowCount, AndroidJavaConverter.ToPageDirection(token.Direction)))
{
- AndroidTaskUtils.AddOnSuccessListener(
- task,
- annotatedData =>
- {
- using (var leaderboardScores = annotatedData.Call("get"))
- {
- InvokeCallbackOnGameThread(callback, CreateLeaderboardScoreData(
- token.LeaderboardId,
- token.Collection,
- token.TimeSpan,
- annotatedData.Call("isStale")
- ? ResponseStatus.SuccessWithStale
- : ResponseStatus.Success,
- leaderboardScores));
- leaderboardScores.Call("release");
- }
- });
-
- AndroidTaskUtils.AddOnFailureListener(task, exception =>
- {
- AndroidHelperFragment.IsResolutionRequired(exception, resolutionRequired =>
+ task.AddOnSuccessListener(annotatedData => {
+ using (var leaderboardScores = annotatedData.Call("get"))
{
+ InvokeCallbackOnGameThread(callback, CreateLeaderboardScoreData(
+ token.LeaderboardId,
+ token.Collection,
+ token.TimeSpan,
+ annotatedData.Call("isStale")
+ ? ResponseStatus.SuccessWithStale
+ : ResponseStatus.Success,
+ leaderboardScores));
+ leaderboardScores.Call("release");
+ }
+ }).AddOnFailureListener(exception => {
+ AndroidHelperFragment.IsResolutionRequired(exception, resolutionRequired => {
if (resolutionRequired)
{
mFriendsResolutionException =
@@ -983,8 +892,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/Runtime/Scripts/Platforms/Android/AndroidTaskUtils.cs b/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/Platforms/Android/AndroidTaskUtils.cs
index 4740cae82..8313442fd 100644
--- a/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/Platforms/Android/AndroidTaskUtils.cs
+++ b/Assets/Public/GooglePlayGames/com.google.play.games/Runtime/Scripts/Platforms/Android/AndroidTaskUtils.cs
@@ -6,32 +6,37 @@ namespace GooglePlayGames.Android
using UnityEngine;
using System;
- class AndroidTaskUtils
+ static class AndroidTaskUtils
{
- private AndroidTaskUtils()
+ /** self */
+ public static AndroidJavaObject AddOnCanceledListener(this AndroidJavaObject task, Action callback)
{
+ using (task.Call("addOnCanceledListener",new TaskOnCanceledProxy(callback))) ;
+ return task;
}
- public static void AddOnSuccessListener(AndroidJavaObject task, Action callback)
- {
- using (task.Call("addOnSuccessListener",
- new TaskOnSuccessProxy(callback, /* disposeResult= */ true))) ;
- }
+ /** self */
+ public static AndroidJavaObject AddOnSuccessListener(this AndroidJavaObject task, Action callback) => task.AddOnSuccessListener(true,callback);
- public static void AddOnSuccessListener(AndroidJavaObject task, bool disposeResult, Action callback)
+ /** self */
+ public static AndroidJavaObject AddOnSuccessListener(this AndroidJavaObject task, bool disposeResult, Action callback)
{
- using (task.Call("addOnSuccessListener",
- new TaskOnSuccessProxy(callback, disposeResult))) ;
+ using (task.Call("addOnSuccessListener",new TaskOnSuccessProxy(callback, disposeResult))) ;
+ return task;
}
- public static void AddOnFailureListener(AndroidJavaObject task, Action callback)
+ /** self */
+ public static AndroidJavaObject AddOnFailureListener(this AndroidJavaObject task, Action callback)
{
using (task.Call("addOnFailureListener", new TaskOnFailedProxy(callback))) ;
+ return task;
}
- public static void AddOnCompleteListener(AndroidJavaObject task, Action