[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void IdentityVerificationSignatureCallback(
string publicKeyUrl,
IntPtr signaturePointer, int signatureLength,
IntPtr saltPointer, int saltLength,
ulong timestamp,
string error);
[DllImport("__Internal")]
public static extern void generateIdentityVerificationSignature(
[MarshalAs(UnmanagedType.FunctionPtr)]IdentityVerificationSignatureCallback callback);
// Note: This callback has to be static because Unity's il2Cpp doesn't support marshalling instance methods.
[MonoPInvokeCallback(typeof(IdentityVerificationSignatureCallback))]
public static void OnIdentityVerificationSignatureGenerated(
string publicKeyUrl,
IntPtr signaturePointer, int signatureLength,
IntPtr saltPointer, int saltLength,
ulong timestamp,
string error)
{
// Create a managed array for the signature
var signature = new byte[signatureLength];
Marshal.Copy(signaturePointer, signature, 0, signatureLength);
// Create a managed array for the salt
var salt = new byte[saltLength];
Marshal.Copy(saltPointer, salt, 0, saltLength);
UnityEngine.Debug.Log($"publicKeyUrl: {publicKeyUrl}");
UnityEngine.Debug.Log($"signature: {signature.Length}");
UnityEngine.Debug.Log($"salt: {salt.Length}");
UnityEngine.Debug.Log($"timestamp: {timestamp}");
UnityEngine.Debug.Log($"error: {error}");
}
3. 해당 코드를 호출 및 사용 하도록 코드 구성
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void IdentityVerificationSignatureCallback(
string publicKeyUrl,
IntPtr signaturePointer, int signatureLength,
IntPtr saltPointer, int saltLength,
ulong timestamp,
string error);
[DllImport("__Internal")]
public static extern void generateIdentityVerificationSignature(
[MarshalAs(UnmanagedType.FunctionPtr)] IdentityVerificationSignatureCallback callback);
// Note: This callback has to be static because Unity's il2Cpp doesn't support marshalling instance methods.
[MonoPInvokeCallback(typeof(IdentityVerificationSignatureCallback))]
public static void OnIdentityVerificationSignatureGenerated(
string publicKeyUrl,
IntPtr signaturePointer, int signatureLength,
IntPtr saltPointer, int saltLength,
ulong timestamp,
string error)
{
// Create a managed array for the signature
var signature = new byte[signatureLength];
Marshal.Copy(signaturePointer, signature, 0, signatureLength);
// Create a managed array for the salt
var salt = new byte[saltLength];
Marshal.Copy(saltPointer, salt, 0, saltLength);
string time = timestamp.ToString();
UnityEngine.Debug.Log($"horae:: publicKeyUrl: {publicKeyUrl}");
UnityEngine.Debug.Log($"horae:: signature.length: {signature.Length}");
UnityEngine.Debug.Log($"horae:: salt.length: {salt.Length}");
UnityEngine.Debug.Log($"horae:: string timestamp: {time}");
UnityEngine.Debug.Log($"horae:: ulong timestamp: {timestamp}");
UnityEngine.Debug.Log($"horae:: error: {error}");
UnityEngine.Debug.Log($"horae:: signature: {BitConverter.ToString(signature).Replace("-", "")}");
UnityEngine.Debug.Log($"horae:: salt: {BitConverter.ToString(salt).Replace("-", "")}");
UnityEngine.Debug.Log($"horae:: signature base64: {Convert.ToBase64String(signature)}");
UnityEngine.Debug.Log($"horae:: salt base64: {Convert.ToBase64String(salt)}");
Task task = SignInWithAppleGameCenterAsync(Convert.ToBase64String(signature), Social.localUser.id, publicKeyUrl, Convert.ToBase64String(salt), timestamp);
}
public void StartIdentityVerification()
{
// 네이티브 코드에게 인증 서명을 생성하도록 요청합니다.
generateIdentityVerificationSignature(OnIdentityVerificationSignatureGenerated);
}
public static async Task SignInWithAppleGameCenterAsync(string signature, string teamPlayerId, string publicKeyURL, string salt, ulong timestamp)
{
Debug.Log("horae:: SignInWithAppleGameCenterAsync");
Debug.Log("horae:: SignInWithAppleGameCenterAsync signature: " + signature);
Debug.Log("horae:: SignInWithAppleGameCenterAsync teamPlayerId: " + teamPlayerId);
Debug.Log("horae:: SignInWithAppleGameCenterAsync publicKeyURL: " + publicKeyURL);
Debug.Log("horae:: SignInWithAppleGameCenterAsync salt: " + salt);
Debug.Log("horae:: SignInWithAppleGameCenterAsync timestamp: " + timestamp);
try
{
Debug.Log("horae:: try await SignInWithAppleGameCenterAsync");
await AuthenticationService.Instance.SignInWithAppleGameCenterAsync(signature, teamPlayerId, publicKeyURL, salt, timestamp);
UnityEngine.Debug.Log("horae:: SignIn is successful.");
}
catch (AuthenticationException ex)
{
// Compare error code to AuthenticationErrorCodes
// Notify the player with the proper error message
Debug.Log("horae:: AuthenticationException");
Debug.LogException(ex);
}
catch (RequestFailedException ex)
{
// Compare error code to CommonErrorCodes
// Notify the player with the proper error message
Debug.Log("horae:: RequestFailedException");
Debug.LogException(ex);
}
}
4. 이제 StartIdentityVerification() 함수를 호출해주면 Gamecenter 로 로그인한 유저를