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

Fix fetch item and build errors for other platform #18

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using UnityEditor;
using UnityEngine;

#if UNITY_EDITOR_OSX
#if UNITY_EDITOR_OSX && (UNITY_IOS || UNITY_TVOS || UNITY_STANDALONE_OSX)
using UnityEditor.iOS.Xcode;
#endif

Expand All @@ -20,7 +20,7 @@ public class AppleAccessibilityBuildStep : AppleBuildStep
{BuildTarget.tvOS, "AppleAccessibility.framework"},
};

#if UNITY_EDITOR_OSX
#if UNITY_EDITOR_OSX && (UNITY_IOS || UNITY_TVOS || UNITY_STANDALONE_OSX)
public override void OnProcessFrameworks(AppleBuildProfile _, BuildTarget buildTarget, string pathToBuiltTarget, PBXProject pbxProject)
{
if (_libraryTable.ContainsKey(buildTarget))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if UNITY_EDITOR_OSX && (UNITY_IOS || UNITY_TVOS || UNITY_STANDALONE_OSX)
using System.IO;
using System.Text.RegularExpressions;
using UnityEditor;
Expand Down Expand Up @@ -422,3 +423,4 @@ public static void ProcessExportPlistOptions(AppleBuildProfile appleBuildProfile

}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using UnityEditor;
using UnityEngine;

#if UNITY_EDITOR_OSX
#if UNITY_EDITOR_OSX && (UNITY_IOS || UNITY_TVOS || UNITY_STANDALONE_OSX)
using UnityEditor.iOS.Xcode;
#endif

Expand All @@ -20,6 +20,7 @@ public class AppleBuildStep : ScriptableObject
/// <summary>
/// Returns an enumerable collection of all objects in the project which derive from AppleBuildStep
/// </summary>

public static IEnumerable<Type> ProjectAppleBuildStepTypes()
{
var appleBuildStepTypes = from assembly in AppDomain.CurrentDomain.GetAssemblies()
Expand All @@ -38,6 +39,8 @@ where typeof(AppleBuildStep).IsAssignableFrom(type) && type != typeof(AppleBuild
/// <param name="pathToBuiltProject"></param>
public virtual void OnBeginPostProcess(AppleBuildProfile appleBuildProfile, BuildTarget buildTarget, string pathToBuiltProject) { }

#if UNITY_EDITOR_OSX && (UNITY_IOS || UNITY_TVOS || UNITY_STANDALONE_OSX)

/// <summary>
/// Called when steps should modify the info plist.
/// </summary>
Expand Down Expand Up @@ -72,7 +75,7 @@ where typeof(AppleBuildStep).IsAssignableFrom(type) && type != typeof(AppleBuild
/// <param name="buildTarget"></param>
/// <param name="exportPlistOptions"></param>
public virtual void OnProcessExportPlistOptions(AppleBuildProfile appleBuildProfile, BuildTarget buildTarget, string pathToBuiltProject, PlistDocument exportPlistOptions) { }

#endif
/// <summary>
/// Called on all steps, in-order, as a final post process command. Any final signatures can be done here (if last step).
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using UnityEngine;
using UnityEditor;

#if UNITY_EDITOR_OSX
#if UNITY_EDITOR_OSX && (UNITY_IOS || UNITY_TVOS || UNITY_STANDALONE_OSX)
using UnityEditor.iOS.Xcode;
#endif

Expand All @@ -20,7 +20,7 @@ public class AppleCoreBuildStep : AppleBuildStep
{BuildTarget.StandaloneOSX, "AppleCoreNativeMac.bundle"}
};

#if UNITY_EDITOR_OSX
#if UNITY_EDITOR_OSX && (UNITY_IOS || UNITY_TVOS || UNITY_STANDALONE_OSX)
public override void OnFinalizePostProcess(AppleBuildProfile appleBuildProfile, BuildTarget buildTarget, string pathToBuiltProject)
{
Debug.Log($"AppleBuild: disabling Bitcode for framework and app targets.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if UNITY_EDITOR_OSX
#if UNITY_EDITOR_OSX && (UNITY_IOS || UNITY_TVOS || UNITY_STANDALONE_OSX)
using System;
using System.IO;
using UnityEditor;
Expand Down Expand Up @@ -43,6 +43,21 @@ public static string GetPluginLibraryPathForBuildTarget(string libraryName, Buil
}
}

if( libraryName.EndsWith(".framework") )
{
string libraryNameWithoutFramework = libraryName.Substring( 0, libraryName.LastIndexOf(".framework") );
results = AssetDatabase.FindAssets(libraryNameWithoutFramework);
foreach (string currGUID in results)
{
string libraryPath = AssetDatabase.GUIDToAssetPath(currGUID);
string[] folders = libraryPath.Split('/');
if (Array.IndexOf(folders, platformString) > -1)
{
return libraryPath;
}
}

}
return string.Empty;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if UNITY_EDITOR_OSX && (UNITY_IOS || UNITY_TVOS || UNITY_STANDALONE_OSX)
using System;
using System.IO;
using System.Collections;
Expand Down Expand Up @@ -174,3 +175,4 @@ static void OnPostprocessAllAssets(string[] assetPaths, string[] _, string[] _1,
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if UNITY_EDITOR_OSX && (UNITY_IOS || UNITY_TVOS || UNITY_STANDALONE_OSX)
using UnityEditor;
using UnityEditor.iOS.Xcode;
using UnityEngine;
Expand Down Expand Up @@ -129,4 +130,5 @@ public override void OnProcessEntitlements(AppleBuildProfile appleBuildProfile,
entitlements.root.SetBoolean("com.apple.security.assets.movies.read-write", true);
}
}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void Reset()
IsEnabled = false;
}

#if UNITY_EDITOR_OSX
#if UNITY_EDITOR_OSX && (UNITY_IOS || UNITY_TVOS || UNITY_STANDALONE_OSX)
public override void OnProcessEntitlements(AppleBuildProfile appleBuildProfile, BuildTarget buildTarget, string pathToBuiltTarget, PlistDocument entitlements)
{
if (buildTarget == BuildTarget.tvOS)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if UNITY_EDITOR_OSX
#if UNITY_EDITOR_OSX && (UNITY_IOS || UNITY_TVOS || UNITY_STANDALONE_OSX)
using System.Collections.Generic;
using System.IO;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if UNITY_EDITOR_OSX
#if UNITY_EDITOR_OSX && (UNITY_IOS || UNITY_TVOS || UNITY_STANDALONE_OSX)

using System.IO;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if UNITY_EDITOR_OSX
#if UNITY_EDITOR_OSX && (UNITY_IOS || UNITY_TVOS || UNITY_STANDALONE_OSX)
using System.Collections.Generic;
using System.IO;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if UNITY_EDITOR_OSX
#if UNITY_EDITOR_OSX && (UNITY_IOS || UNITY_TVOS || UNITY_STANDALONE_OSX)

namespace Apple.Core
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if UNITY_EDITOR_OSX
#if UNITY_EDITOR_OSX && (UNITY_IOS || UNITY_TVOS || UNITY_STANDALONE_OSX)
using System;
using UnityEngine;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if UNITY_EDITOR_OSX
#if UNITY_EDITOR_OSX && (UNITY_IOS || UNITY_TVOS || UNITY_STANDALONE_OSX)
using System.Collections.Generic;
using System.IO;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if UNITY_EDITOR_OSX
#if UNITY_EDITOR_OSX && (UNITY_IOS || UNITY_TVOS || UNITY_STANDALONE_OSX)

using System.Collections.Generic;
using System.IO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using UnityEditor;
using UnityEngine;

#if UNITY_EDITOR_OSX
#if UNITY_EDITOR_OSX && (UNITY_IOS || UNITY_TVOS || UNITY_STANDALONE_OSX)
using UnityEditor.iOS.Xcode;
#endif

Expand All @@ -21,7 +21,7 @@ public class CHBuildStep : AppleBuildStep
{BuildTarget.StandaloneOSX, "CoreHapticsWrapper.bundle"}
};

#if UNITY_EDITOR_OSX
#if UNITY_EDITOR_OSX && (UNITY_IOS || UNITY_TVOS || UNITY_STANDALONE_OSX)
public override void OnProcessFrameworks(AppleBuildProfile _, BuildTarget buildTarget, string pathToBuiltTarget, PBXProject pbxProject)
{
if (_libraryTable.ContainsKey(buildTarget))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using UnityEditor;
using UnityEngine;

#if UNITY_EDITOR_OSX
#if UNITY_EDITOR_OSX && (UNITY_IOS || UNITY_TVOS || UNITY_STANDALONE_OSX)
using UnityEditor.iOS.Xcode;
#endif

Expand All @@ -25,7 +25,7 @@ public class AppleGameControllerBuildStep : AppleBuildStep
public bool SupportsMicroGamePad = true;
public bool SupportsExtendedGamePad = true;

#if UNITY_EDITOR_OSX
#if UNITY_EDITOR_OSX && (UNITY_IOS || UNITY_TVOS || UNITY_STANDALONE_OSX)
public override void OnProcessInfoPlist(AppleBuildProfile _, BuildTarget buildTarget, string pathToBuiltTarget, PlistDocument infoPlist)
{
// Notify that we support controllers...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using UnityEditor;
using UnityEngine;

#if UNITY_EDITOR_OSX
#if UNITY_EDITOR_OSX && (UNITY_IOS || UNITY_TVOS || UNITY_STANDALONE_OSX)
using UnityEditor.iOS.Xcode;
#endif

Expand All @@ -21,7 +21,7 @@ public class AppleGameKitBuildStep : AppleBuildStep
{BuildTarget.StandaloneOSX, "GameKitWrapper.bundle"}
};

#if UNITY_EDITOR_OSX
#if UNITY_EDITOR_OSX && (UNITY_IOS || UNITY_TVOS || UNITY_STANDALONE_OSX)
public override void OnProcessEntitlements(AppleBuildProfile _, BuildTarget buildTarget, string _1, PlistDocument entitlements)
{
if(buildTarget == BuildTarget.StandaloneOSX)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,42 @@ public struct GKIdentityVerificationResponse
/// <summary>
/// The URL for the public encryption key.
/// </summary>
//public string PublicKeyUrl;
public string PublicKeyUrl;
internal IntPtr Signature;
internal int SignatureLength;
internal IntPtr Salt;
internal int SaltLength;
/// <summary>
/// The signature’s creation date and time.
/// </summary>
public ulong Timestamp;

/// <summary>
/// The verification signature data that GameKit generates.
/// </summary>
/// <returns></returns>
public byte[] GetSignature()
{
var signature = new byte[SignatureLength];
Marshal.Copy(Signature, signature, 0, SignatureLength);

return signature;
}

public byte[] Signature;

/// <summary>
/// A random NSString that GameKit uses to compute the hash and randomize it.
/// </summary>
/// <returns></returns>
public byte[] GetSalt()
public byte[] Salt;

/// <summary>
/// The signature’s creation date and time.
/// </summary>
public ulong Timestamp;

internal GKIdentityVerificationResponse(ulong timestamp,
IntPtr publicKeyUrl, int publicKeyUrlLength,
IntPtr signature, int signatureLength,
IntPtr salt, int saltLength)
{
var salt = new byte[SaltLength];
Marshal.Copy(Salt, salt, 0, SaltLength);
Timestamp = timestamp;

var publicKeyUrlBytes = new byte[publicKeyUrlLength];
Marshal.Copy(publicKeyUrl, publicKeyUrlBytes, 0, publicKeyUrlLength);
PublicKeyUrl = System.Text.Encoding.UTF8.GetString(publicKeyUrlBytes);

Signature = new byte[signatureLength];
Marshal.Copy(signature, Signature, 0, signatureLength);

Salt = new byte[saltLength];
Marshal.Copy(salt, Salt, 0, saltLength);

return salt;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,13 @@ public static GKLocalPlayer Local
#endregion

#region FetchItems
private delegate void SuccessTaskFetchItemsCallback(long taskId, ulong timestamp,
IntPtr publicKeyUrl, int publicKeyUrlLength,
IntPtr signature, int signatureLength,
IntPtr salt, int saltLength);

[DllImport(InteropUtility.DLLName)]
private static extern void GKLocalPlayer_FetchItems(IntPtr pointer, long taskId, SuccessTaskCallback<GKIdentityVerificationResponse> onSuccess, NSErrorTaskCallback onError);
private static extern void GKLocalPlayer_FetchItems(IntPtr pointer, long taskId, SuccessTaskFetchItemsCallback onSuccess, NSErrorTaskCallback onError);

/// <summary>
/// Generates a signature so that a third-party server can authenticate the local player.
Expand All @@ -104,9 +109,17 @@ public Task<GKIdentityVerificationResponse> FetchItems()
return tcs.Task;
}

[MonoPInvokeCallback(typeof(SuccessTaskCallback<GKIdentityVerificationResponse>))]
private static void OnFetchItems(long taskId, GKIdentityVerificationResponse response)
[MonoPInvokeCallback(typeof(SuccessTaskFetchItemsCallback))]
private static void OnFetchItems(long taskId, ulong timestamp,
IntPtr publicKeyUrl, int publicKeyUrlLength,
IntPtr signature, int signatureLength,
IntPtr salt, int saltLength)
{
var response = new GKIdentityVerificationResponse(timestamp,
publicKeyUrl, publicKeyUrlLength,
signature, signatureLength,
salt, saltLength);

InteropTasks.TrySetResultAndRemove(taskId, response);
}

Expand All @@ -116,7 +129,7 @@ private static void OnFetchItemsError(long taskId, IntPtr errorPointer)
InteropTasks.TrySetExceptionAndRemove<GKIdentityVerificationResponse>(taskId, new GameKitException(errorPointer));
}
#endregion

#region Authenticate
[DllImport(InteropUtility.DLLName)]
private static extern void GKLocalPlayer_Authenticate(long taskId, SuccessTaskCallback<IntPtr> onSuccess, NSErrorTaskCallback onError);
Expand Down Expand Up @@ -240,4 +253,4 @@ private static void OnLoadRecentPlayersError(long taskId, IntPtr errorPointer)
}
#endregion
}
}
}