NxrSDKVerifyEditor.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Text.RegularExpressions;
  4. namespace Nxr.Internal
  5. {
  6. public class NxrSDKVerifyEditor : EditorWindow
  7. {
  8. string sdkurl = " https://dev.inibiru.com/#/download/pro";
  9. string GetSDKKey()
  10. {
  11. string data = NxrPluginEditor.Read("AndroidManifest.xml");
  12. string[] lines = data.Split('\n');
  13. for (int i = 0, l = lines.Length; i < l; i++)
  14. {
  15. string lineContent = lines[i];
  16. if (lineContent.Contains("NIBIRU_SDK_KEY"))
  17. {
  18. MatchCollection mc = Regex.Matches(lineContent, "(?<=\").*?(?=\")");
  19. return mc[0].Value;
  20. }
  21. }
  22. return null;
  23. }
  24. //输入文字的内容
  25. private string inputText = null;
  26. bool IsFirstTrigger = false;
  27. private void OnGUI()
  28. {
  29. if (!IsFirstTrigger)
  30. {
  31. IsFirstTrigger = true;
  32. inputText = GetSDKKey();
  33. }
  34. GUILayout.Space(20);
  35. GUIStyle labelStyle = new GUIStyle();
  36. labelStyle.normal.textColor = new Color(220 / 255.0f, 20 / 255.0f, 60 / 255.0f, 1.0f);
  37. labelStyle.fontSize = 13;
  38. GUILayout.Label(" SDK Verify: \n\n Step1: Use Nibiru Signature Tool generate NibiruSDKKey.bin.\n" +
  39. " Step2: Put NibiruSDKKey.bin to Assets\\Plugins\\Android\\assets.\n" +
  40. " Step3: Put Encryption Key String to Input Box.",
  41. labelStyle);
  42. GUILayout.Space(20);
  43. EditorGUILayout.Space();
  44. EditorGUILayout.LabelField("Get the lastest version of Tool:");
  45. GUIStyle style = new GUIStyle();
  46. style.normal.textColor = new Color(0, 122f / 255f, 204f / 255f);
  47. if (GUILayout.Button(sdkurl, style, GUILayout.Width(200)))
  48. {
  49. Application.OpenURL(sdkurl);
  50. }
  51. GUILayout.Space(20);
  52. // inputText = TextField(inputText, null);// GUILayout.TextField(inputText);
  53. inputText = EditorGUILayout.TextArea(inputText);
  54. GUILayout.Space(20);
  55. bool SDKKeyExist = NxrPluginEditor.IsFileExists("assets/NibiruSDKKey.bin");
  56. if (!SDKKeyExist)
  57. {
  58. GUILayout.Label(" [Warning] NibiruSDKKey.bin is not exist. [Warning] ", labelStyle);
  59. GUILayout.Space(20);
  60. }
  61. if (inputText != null && GUILayout.Button("Confirm", GUILayout.Width(100), GUILayout.Height(30)))
  62. {
  63. {
  64. string data = NxrPluginEditor.Read("AndroidManifest.xml");
  65. string[] lines = data.Split('\n');
  66. string newdata = "";
  67. for (int i = 0, l = lines.Length; i < l; i++)
  68. {
  69. string lineContent = lines[i];
  70. if (lineContent.Contains("NIBIRU_SDK_KEY"))
  71. {
  72. lineContent = " <meta-data android:value=\"" + inputText + "\" android:name=\"NIBIRU_SDK_KEY\"/>";
  73. }
  74. newdata = newdata + lineContent + "\n";
  75. }
  76. NxrPluginEditor.Write("AndroidManifest.xml", newdata);
  77. }
  78. Close();
  79. }
  80. if(GUI.changed) Repaint();
  81. }
  82. public static string HandleCopyPaste(int controlID)
  83. {
  84. if (controlID == GUIUtility.keyboardControl)
  85. {
  86. if (Event.current.type == UnityEngine.EventType.KeyUp && (Event.current.modifiers == EventModifiers.Control || Event.current.modifiers == EventModifiers.Command))
  87. {
  88. if (Event.current.keyCode == KeyCode.C)
  89. {
  90. Event.current.Use();
  91. TextEditor editor = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl);
  92. editor.Copy();
  93. }
  94. else if (Event.current.keyCode == KeyCode.V)
  95. {
  96. Event.current.Use();
  97. TextEditor editor = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl);
  98. editor.text = "";
  99. editor.Paste();
  100. #if UNITY_5_3_OR_NEWER || UNITY_5_3
  101. return editor.text; //以及更高的unity版本中editor.content.text已经被废弃,需使用editor.text代替
  102. #else
  103. return editor.content.text;
  104. #endif
  105. }
  106. else if (Event.current.keyCode == KeyCode.A)
  107. {
  108. Event.current.Use();
  109. TextEditor editor = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl);
  110. editor.SelectAll();
  111. }
  112. }
  113. }
  114. return null;
  115. }
  116. /// <summary>
  117. /// TextField复制粘贴的实现
  118. /// </summary>
  119. public static string TextField(string value, params GUILayoutOption[] options)
  120. {
  121. int textFieldID = GUIUtility.GetControlID("TextField".GetHashCode(), FocusType.Keyboard) + 1;
  122. if (textFieldID == 0)
  123. return value;
  124. //处理复制粘贴的操作
  125. value = HandleCopyPaste(textFieldID) ?? value;
  126. return GUILayout.TextField(value, options);
  127. }
  128. }
  129. }