Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Make package UPM compatible #3282

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.gradle
build
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace GooglePlayGames.Editor
using System.Collections.Generic;
using System.IO;
using System.Xml;
using System.Linq;
using UnityEditor;
using UnityEngine;

Expand Down Expand Up @@ -112,25 +113,66 @@ public static class GPGSUtil

private const string RootFolderName = "com.google.play.games";

static string localResolvedPath = "Packages";

public static void InitResolverPath(Action<bool> onFinished)
{
var listRequest = UnityEditor.PackageManager.Client.List(true,true);

EditorApplication.update += Progress;

void Progress()
{
if(listRequest.Status == UnityEditor.PackageManager.StatusCode.InProgress)
return;

EditorApplication.update -= Progress;

if(listRequest.Status == UnityEditor.PackageManager.StatusCode.Failure)
{
Alert(listRequest.Error.errorCode.ToString(),listRequest.Error.message);
onFinished?.Invoke(false);
return;
}

var packageInfo = listRequest.Result.FirstOrDefault((info) => info.packageId.StartsWith(RootFolderName + "@"));
if(packageInfo == null)
{
Alert(RootFolderName,"Not installed");
onFinished?.Invoke(false);
return;
}

if(packageInfo.source == UnityEditor.PackageManager.PackageSource.Local)
localResolvedPath = Path.GetDirectoryName(packageInfo.resolvedPath);

Debug.Log(localResolvedPath);
onFinished?.Invoke(true);
}
}

/// <summary>
/// The root path of the Google Play Games plugin
/// </summary>
public static string RootPath
{
get
{
if (string.IsNullOrEmpty(mRootPath))
if (string.IsNullOrEmpty(mRootPath) || !Directory.Exists(mRootPath))
{
string[] dirs = new[] {
#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<string>(ref dirs, dirsLength + dir1.Length);
Array.Copy(dir1, 0, dirs, dirsLength, dir1.Length);
#else
string[] dirs = Directory.GetDirectories("Assets", RootFolderName, SearchOption.AllDirectories);
// search for remote UPM installation
Path.Join("Library","PackageCache"),
localResolvedPath,
"Packages",
#endif
"Assets"
}.Distinct().SelectMany((path) => {
return Directory.GetDirectories(path, RootFolderName + "*", SearchOption.AllDirectories);
}).Distinct().ToArray();


switch (dirs.Length)
{
case 0:
Expand All @@ -144,8 +186,7 @@ public static string RootPath
default:
for (int i = 0; i < dirs.Length; i++)
{
if (File.Exists(SlashesToPlatformSeparator(Path.Combine(dirs[i], GameInfoRelativePath)))
)
if (File.Exists(SlashesToPlatformSeparator(Path.Combine(dirs[i], GameInfoRelativePath))))
{
mRootPath = SlashesToPlatformSeparator(dirs[i]);
break;
Expand Down Expand Up @@ -251,8 +292,7 @@ public static string ReadFile(string filePath)
/// <param name="name">Name of the template in the editor directory.</param>
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)));
}

/// <summary>
Expand Down Expand Up @@ -662,9 +702,7 @@ public static void UpdateGameInfo()
/// </summary>
public static void CheckAndFixDependencies()
{
string depPath =
SlashesToPlatformSeparator(Path.Combine(GPGSUtil.RootPath,
"Editor/GooglePlayGamesPluginDependencies.xml"));
string depPath = SlashesToPlatformSeparator(Path.Combine("Assets","Editor","GooglePlayGamesPluginDependencies.xml"));

XmlDocument doc = new XmlDocument();
doc.Load(depPath);
Expand Down Expand Up @@ -694,8 +732,12 @@ public static void CheckAndFixDependencies()
/// </summary>
public static void CheckAndFixVersionedAssestsPaths()
{
string[] foundPaths =
Directory.GetFiles(RootPath, "GooglePlayGamesPlugin_v*.txt", SearchOption.AllDirectories);
string[] rootPaths = new string[] { "Assets",RootPath };
string[] foundPaths = rootPaths.Select((rootPath) => {
return Directory.GetFiles(Path.Combine(rootPath,"Editor"), "GooglePlayGamesPlugin_v*.txt", SearchOption.AllDirectories);
}).FirstOrDefault((txtFiles) => {
return txtFiles.Length > 0 && File.Exists(txtFiles[0]);
});

if (foundPaths.Length == 1)
{
Expand All @@ -710,8 +752,7 @@ public static void CheckAndFixVersionedAssestsPaths()
int pos = assetPath.IndexOf(RootFolderName);
if (pos != -1)
{
assetPath = Path.Combine(RootPath, assetPath.Substring(pos + RootFolderName.Length + 1))
.Replace("\\", "/");
assetPath = Path.Combine(RootPath, assetPath.Substring(pos + RootFolderName.Length + 1)).Replace("\\", "/");
}

writer.WriteLine(assetPath);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>

#if UNITY_ANDROID
namespace GooglePlayGames
{

namespace GooglePlayGames {
///
/// This file is automatically generated DO NOT EDIT!
///
Expand All @@ -30,43 +29,43 @@ namespace GooglePlayGames
/// 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 "__".
/// </summary>
public static class GameInfo
{
public static class GameInfo {

private const string UnescapedApplicationId = "APP_ID";
private const string UnescapedIosClientId = "IOS_CLIENTID";
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 const string IosClientId = "__IOS_CLIENTID__"; // Filled in automatically

public static bool ApplicationIdInitialized() {
return !string.IsNullOrEmpty(ApplicationId) && !ApplicationId.Equals(ToEscapedToken(UnescapedApplicationId));
}

public static bool ApplicationIdInitialized()
{
return !string.IsNullOrEmpty(ApplicationId) &&
!ApplicationId.Equals(ToEscapedToken(UnescapedApplicationId));
public static bool IosClientIdInitialized() {
return !string.IsNullOrEmpty(IosClientId) && !IosClientId.Equals(ToEscapedToken(UnescapedIosClientId));
}

public static bool WebClientIdInitialized()
{
public static bool WebClientIdInitialized() {
return !string.IsNullOrEmpty(WebClientId) && !WebClientId.Equals(ToEscapedToken(UnescapedWebClientId));
}

public static bool NearbyConnectionsInitialized()
{
public static bool NearbyConnectionsInitialized() {
return !string.IsNullOrEmpty(NearbyConnectionServiceId) &&
!NearbyConnectionServiceId.Equals(ToEscapedToken(UnescapedNearbyServiceId));
!NearbyConnectionServiceId.Equals(ToEscapedToken(UnescapedNearbyServiceId));
}

/// <summary>
/// Returns an escaped token (i.e. one flanked with "__") for the passed token
/// </summary>
/// <returns>The escaped token.</returns>
/// <param name="token">The Token</param>
private static string ToEscapedToken(string token)
{
private static string ToEscapedToken(string token) {
return string.Format("__{0}__", token);
}
}
}
#endif //UNITY_ANDROID
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class PluginVersion
{
// Current Version.
public const int VersionInt = 0x01101;
public const string VersionString = "0.11.01";
public const string VersionString = "0.11.1";
public const string VersionKey = "01101" ;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "com.google.play.games",
"displayName": "Google Play Games",
"description": "The Google Play Games plugin for Unity allows you to access the Google Play Games API through Unity's social interface.",
"version": "0.11.01",
"version": "0.11.1",
"unity": "2018.4",
"author": {
"name": "Google LLC"
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ project.ext {
}

// Also update in com.google.play.games/package.json
pluginVersion = "0.11.01"
pluginVersion = "0.11.1"

// String for specifying the build mode.
// If 'eap', will include all files from the 'Protected' folder.
Expand Down