Skip to content

Commit

Permalink
Move google menu + Fix play image loader
Browse files Browse the repository at this point in the history
  • Loading branch information
Thaina committed Jun 6, 2024
1 parent 6a93801 commit f283bd5
Show file tree
Hide file tree
Showing 17 changed files with 312 additions and 304 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ namespace GooglePlayGames.Editor
using UnityEditor;
using UnityEngine;

#if UNITY_2021_2_OR_NEWER
using UnityEditor.Build;
#endif

/// <summary>
/// Google Play Game Services Setup dialog for Android.
/// </summary>
Expand Down Expand Up @@ -57,15 +61,14 @@ public class GPGSAndroidSetupUI : EditorWindow
/// <summary>
/// Menus the item for GPGS android setup.
/// </summary>
[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<GPGSAndroidSetupUI>(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
Expand Down Expand Up @@ -196,7 +199,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();
Expand Down Expand Up @@ -298,9 +301,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);
}
}

Expand Down Expand Up @@ -355,48 +357,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!!");
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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<XmlNode>().Where((node,n) => i != n))
node.ParentNode.RemoveChild(node);

return nodes[i] as XmlElement;
}
else
{
var element = xmlDoc.DocumentElement;
var stack = new Stack<string>();
while(path.LastIndexOf('/') is int i && i > 0)
{
stack.Push(path.Substring(i + 1));
path = path.Remove(i);
element = xmlDoc.SelectNodes(path,nsmgr)?.OfType<XmlElement>().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
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Expand Down
Loading

0 comments on commit f283bd5

Please sign in to comment.