説明なし
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

GameMenuHandler.cs 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using AppleAuth.Enums;
  2. using AppleAuth.Extensions;
  3. using AppleAuth.Interfaces;
  4. using System;
  5. using System.Text;
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8. [Serializable]
  9. public class GameMenuHandler
  10. {
  11. public GameObject Parent;
  12. public Text AppleUserIdLabel;
  13. public Text AppleUserCredentialLabel;
  14. public void SetVisible(bool visible)
  15. {
  16. this.Parent.SetActive(visible);
  17. }
  18. public void SetupAppleData(string appleUserId, ICredential receivedCredential)
  19. {
  20. this.AppleUserIdLabel.text = "Apple User ID: " + appleUserId;
  21. if (receivedCredential == null)
  22. {
  23. this.AppleUserCredentialLabel.text = "NO CREDENTIALS RECEIVED\nProbably credential status for " + appleUserId + "was Authorized";
  24. return;
  25. }
  26. var appleIdCredential = receivedCredential as IAppleIDCredential;
  27. var passwordCredential = receivedCredential as IPasswordCredential;
  28. if (appleIdCredential != null)
  29. {
  30. var stringBuilder = new StringBuilder();
  31. stringBuilder.AppendLine("RECEIVED APPLE ID CREDENTIAL.\nYOU CAN LOGIN/CREATE A USER WITH THIS");
  32. stringBuilder.AppendLine("<b>Username:</b> " + appleIdCredential.User);
  33. stringBuilder.AppendLine("<b>Real user status:</b> " + appleIdCredential.RealUserStatus.ToString());
  34. if (appleIdCredential.State != null)
  35. stringBuilder.AppendLine("<b>State:</b> " + appleIdCredential.State);
  36. if (appleIdCredential.IdentityToken != null)
  37. {
  38. var identityToken = Encoding.UTF8.GetString(appleIdCredential.IdentityToken, 0, appleIdCredential.IdentityToken.Length);
  39. stringBuilder.AppendLine("<b>Identity token (" + appleIdCredential.IdentityToken.Length + " bytes)</b>");
  40. stringBuilder.AppendLine(identityToken.Substring(0, 45) + "...");
  41. }
  42. if (appleIdCredential.AuthorizationCode != null)
  43. {
  44. var authorizationCode = Encoding.UTF8.GetString(appleIdCredential.AuthorizationCode, 0, appleIdCredential.AuthorizationCode.Length);
  45. stringBuilder.AppendLine("<b>Authorization Code (" + appleIdCredential.AuthorizationCode.Length + " bytes)</b>");
  46. stringBuilder.AppendLine(authorizationCode.Substring(0, 45) + "...");
  47. }
  48. if (appleIdCredential.AuthorizedScopes != null)
  49. stringBuilder.AppendLine("<b>Authorized Scopes:</b> " + string.Join(", ", appleIdCredential.AuthorizedScopes));
  50. if (appleIdCredential.Email != null)
  51. {
  52. stringBuilder.AppendLine();
  53. stringBuilder.AppendLine("<b>EMAIL RECEIVED: YOU WILL ONLY SEE THIS ONCE PER SIGN UP. SEND THIS INFORMATION TO YOUR BACKEND!</b>");
  54. stringBuilder.AppendLine("<b>You can test this again by revoking credentials in Settings</b>");
  55. stringBuilder.AppendLine("<b>Email:</b> " + appleIdCredential.Email);
  56. }
  57. if (appleIdCredential.FullName != null)
  58. {
  59. var fullName = appleIdCredential.FullName;
  60. stringBuilder.AppendLine();
  61. stringBuilder.AppendLine("<b>NAME RECEIVED: YOU WILL ONLY SEE THIS ONCE PER SIGN UP. SEND THIS INFORMATION TO YOUR BACKEND!</b>");
  62. stringBuilder.AppendLine("<b>You can test this again by revoking credentials in Settings</b>");
  63. stringBuilder.AppendLine("<b>Name:</b> " + fullName.ToLocalizedString());
  64. stringBuilder.AppendLine("<b>Name (Short):</b> " + fullName.ToLocalizedString(PersonNameFormatterStyle.Short));
  65. stringBuilder.AppendLine("<b>Name (Medium):</b> " + fullName.ToLocalizedString(PersonNameFormatterStyle.Medium));
  66. stringBuilder.AppendLine("<b>Name (Long):</b> " + fullName.ToLocalizedString(PersonNameFormatterStyle.Long));
  67. stringBuilder.AppendLine("<b>Name (Abbreviated):</b> " + fullName.ToLocalizedString(PersonNameFormatterStyle.Abbreviated));
  68. if (appleIdCredential.FullName.PhoneticRepresentation != null)
  69. {
  70. var phoneticName = appleIdCredential.FullName.PhoneticRepresentation;
  71. stringBuilder.AppendLine("<b>Phonetic name:</b> " + phoneticName.ToLocalizedString());
  72. stringBuilder.AppendLine("<b>Phonetic name (Short):</b> " + phoneticName.ToLocalizedString(PersonNameFormatterStyle.Short));
  73. stringBuilder.AppendLine("<b>Phonetic name (Medium):</b> " + phoneticName.ToLocalizedString(PersonNameFormatterStyle.Medium));
  74. stringBuilder.AppendLine("<b>Phonetic name (Long):</b> " + phoneticName.ToLocalizedString(PersonNameFormatterStyle.Long));
  75. stringBuilder.AppendLine("<b>Phonetic name (Abbreviated):</b> " + phoneticName.ToLocalizedString(PersonNameFormatterStyle.Abbreviated));
  76. }
  77. }
  78. this.AppleUserCredentialLabel.text = stringBuilder.ToString();
  79. }
  80. else if (passwordCredential != null)
  81. {
  82. var stringBuilder = new StringBuilder();
  83. stringBuilder.AppendLine("USERNAME/PASSWORD RECEIVED (iCloud?)");
  84. stringBuilder.AppendLine("<b>Username:</b> " + passwordCredential.User);
  85. stringBuilder.AppendLine("<b>Password:</b> " + passwordCredential.Password);
  86. this.AppleUserCredentialLabel.text = stringBuilder.ToString();
  87. }
  88. else
  89. {
  90. this.AppleUserCredentialLabel.text = "Unknown credentials for user " + receivedCredential.User;
  91. }
  92. }
  93. }