Без опису
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

ObfuscatorWindow.cs 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using Unity.Services.Core.Editor.OrganizationHandler;
  2. using UnityEngine;
  3. using static UnityEditor.Purchasing.UnityPurchasingEditor;
  4. namespace UnityEditor.Purchasing
  5. {
  6. /// <summary>
  7. /// Unity IAP Client-Side Receipt Validation obfuscation window.
  8. /// </summary>
  9. /// <remarks>
  10. /// Collects certificate details for supported stores.
  11. /// Generates .cs file in Assets/, used by Unity IAP Receipt Validation.
  12. /// </remarks>
  13. internal class ObfuscatorWindow : RichEditorWindow
  14. {
  15. // Localize me
  16. private const string kLabelTitle = "Receipt Validation Obfuscator";
  17. private const string kLabelGenerateGoogle = "Obfuscate Google Play License Key";
  18. private const string kLabelGoogleKey = "Google Play Public License Key";
  19. private const string kPublicKeyPlaceholder = "--Paste Public Key Here--";
  20. private const string kLabelGoogleInstructions =
  21. "Follow these four steps to set up receipt validation for Google Play.";
  22. private const string kLabelGooglePlayDeveloperConsoleInstructions =
  23. "1. Get your license key from the Google Play Developer Console:";
  24. private const string kLabelGooglePlayDeveloperConsoleLink = "\tOpen Google Play Developer Console";
  25. private const string kGooglePlayDevConsoleURL = "https://play.google.com/apps/publish/";
  26. private const string kLabelGooglePlayDeveloperConsoleSteps =
  27. "\ta. Select your app from the list\n" +
  28. "\tb. Go to \"Monetization setup\" under \"Monetize\"\n" +
  29. "\tc. Copy the key from the \"Licensing\" section";
  30. private const string kLabelGooglePasteKeyInstructions = "2. Paste the key here:";
  31. private const string kObfuscateKeyInstructions =
  32. "3. Obfuscate the key. (Creates Tangle classes in your project.)";
  33. private const string kDashboardInstructions =
  34. "4. To ensure correct revenue data, enter your key in the Analytics dashboard.";
  35. private const string kLabelDashboardLink = "\tOpen Analytics Dashboard";
  36. private GUIStyle m_ErrorStyle;
  37. private string m_GoogleError;
  38. private string m_AppleError;
  39. /// <summary>
  40. /// The current Google Play Public Key, in string
  41. /// </summary>
  42. string m_GooglePlayPublicKey = kPublicKeyPlaceholder;
  43. #if !ENABLE_EDITOR_GAME_SERVICES
  44. [MenuItem(IapMenuConsts.MenuItemRoot + "/Receipt Validation Obfuscator...", false, 200)]
  45. static void Init()
  46. {
  47. // Get existing open window or if none, make a new one:
  48. var window = (ObfuscatorWindow)GetWindow(typeof(ObfuscatorWindow));
  49. window.titleContent.text = kLabelTitle;
  50. window.minSize = new Vector2(340, 180);
  51. window.Show();
  52. GenericEditorMenuItemClickEventSenderHelpers.SendIapMenuOpenObfuscatorEvent();
  53. GameServicesEventSenderHelpers.SendTopMenuReceiptValidationObfuscatorEvent();
  54. }
  55. #endif
  56. private ObfuscatorWindow()
  57. {
  58. }
  59. void OnGUI()
  60. {
  61. if (m_ErrorStyle == null)
  62. {
  63. m_ErrorStyle = new GUIStyle();
  64. m_ErrorStyle.normal.textColor = Color.red;
  65. }
  66. // Apple error message, if any
  67. if (!string.IsNullOrEmpty(m_AppleError))
  68. {
  69. GUILayout.Label(m_AppleError, m_ErrorStyle);
  70. }
  71. // Google Play
  72. GUILayout.Label(kLabelGoogleKey, EditorStyles.boldLabel);
  73. GUILayout.Label(kLabelGoogleInstructions);
  74. GUILayout.Space(5);
  75. GUILayout.Label(kLabelGooglePlayDeveloperConsoleInstructions);
  76. GUILink(kLabelGooglePlayDeveloperConsoleLink, kGooglePlayDevConsoleURL);
  77. GUILayout.Label(kLabelGooglePlayDeveloperConsoleSteps);
  78. GUILayout.Label(kLabelGooglePasteKeyInstructions);
  79. m_GooglePlayPublicKey = EditorGUILayout.TextArea(
  80. m_GooglePlayPublicKey,
  81. GUILayout.MinHeight(20),
  82. GUILayout.MaxHeight(50));
  83. GUILayout.Label(kObfuscateKeyInstructions);
  84. if (!string.IsNullOrEmpty(m_GoogleError))
  85. {
  86. GUILayout.Label(m_GoogleError, m_ErrorStyle);
  87. }
  88. if (GUILayout.Button(kLabelGenerateGoogle))
  89. {
  90. ObfuscateSecrets(includeGoogle: true);
  91. }
  92. GUILayout.Label(kDashboardInstructions);
  93. GUILink(kLabelDashboardLink, GetFormattedDashboardUrl());
  94. }
  95. static string GetFormattedDashboardUrl()
  96. {
  97. return $"https://dashboard.unity3d.com/organizations/{OrganizationProvider.Organization.Key}/projects/{CloudProjectSettings.projectId}/analytics/v2/dashboards/revenue";
  98. }
  99. void ObfuscateSecrets(bool includeGoogle)
  100. {
  101. ObfuscationGenerator.ObfuscateSecrets(includeGoogle: includeGoogle,
  102. appleError: ref m_AppleError, googleError: ref m_GoogleError,
  103. googlePlayPublicKey: m_GooglePlayPublicKey);
  104. }
  105. }
  106. }