Aucune description
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

UniWebViewEditorSettings.cs 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Collections.Generic;
  4. using System;
  5. using System.IO;
  6. class UniWebViewEditorSettings: ScriptableObject
  7. {
  8. const string assetPath = "Assets/Editor/UniWebView/settings.asset";
  9. [SerializeField]
  10. internal bool usesCleartextTraffic = false;
  11. [SerializeField]
  12. internal bool writeExternalStorage = false;
  13. [SerializeField]
  14. internal bool accessFineLocation = false;
  15. [SerializeField]
  16. internal bool addsKotlin = true;
  17. [SerializeField]
  18. internal string kotlinVersion = null;
  19. [SerializeField]
  20. internal bool addsAndroidBrowser = true;
  21. [SerializeField]
  22. internal string androidBrowserVersion = null;
  23. [SerializeField]
  24. internal bool enableJetifier = true;
  25. [SerializeField]
  26. internal string[] authCallbackUrls = { };
  27. [SerializeField]
  28. internal bool supportLINELogin = false;
  29. internal static string defaultKotlinVersion = "1.6.21";
  30. internal static string defaultAndroidBrowserVersion = "1.2.0";
  31. internal static UniWebViewEditorSettings GetOrCreateSettings() {
  32. var settings = AssetDatabase.LoadAssetAtPath<UniWebViewEditorSettings>(assetPath);
  33. if (settings == null) {
  34. settings = ScriptableObject.CreateInstance<UniWebViewEditorSettings>();
  35. Directory.CreateDirectory("Assets/Editor/UniWebView/");
  36. AssetDatabase.CreateAsset(settings, assetPath);
  37. AssetDatabase.SaveAssets();
  38. }
  39. return settings;
  40. }
  41. internal static SerializedObject GetSerializedSettings() {
  42. return new SerializedObject(GetOrCreateSettings());
  43. }
  44. }
  45. static class UniWebViewSettingsProvider {
  46. static SerializedObject settings;
  47. #if UNITY_2018_3_OR_NEWER
  48. private class Provider : SettingsProvider {
  49. public Provider(string path, SettingsScope scope = SettingsScope.User): base(path, scope) {}
  50. public override void OnGUI(string searchContext) {
  51. DrawPref();
  52. }
  53. }
  54. [SettingsProvider]
  55. static SettingsProvider UniWebViewPref() {
  56. return new Provider("Preferences/UniWebView");
  57. }
  58. #else
  59. [PreferenceItem("UniWebView")]
  60. #endif
  61. static void DrawPref() {
  62. EditorGUIUtility.labelWidth = 320;
  63. EditorGUIUtility.fieldWidth = 20;
  64. if (settings == null) {
  65. settings = UniWebViewEditorSettings.GetSerializedSettings();
  66. }
  67. settings.Update();
  68. EditorGUI.BeginChangeCheck();
  69. // Manifest
  70. EditorGUILayout.Space();
  71. EditorGUILayout.BeginVertical();
  72. EditorGUILayout.LabelField("Android Manifest", EditorStyles.boldLabel);
  73. EditorGUI.indentLevel++;
  74. EditorGUILayout.PropertyField(settings.FindProperty("usesCleartextTraffic"));
  75. DrawDetailLabel("If you need to load plain HTTP content.");
  76. EditorGUILayout.PropertyField(settings.FindProperty("writeExternalStorage"));
  77. DrawDetailLabel("If you need to download an image from web page.");
  78. EditorGUILayout.PropertyField(settings.FindProperty("accessFineLocation"));
  79. DrawDetailLabel("If you need to enable location support in web view.");
  80. EditorGUI.indentLevel--;
  81. EditorGUILayout.EndVertical();
  82. // Gradle
  83. EditorGUILayout.Space();
  84. EditorGUILayout.BeginVertical();
  85. EditorGUILayout.LabelField("Gradle Build", EditorStyles.boldLabel);
  86. EditorGUI.indentLevel++;
  87. EditorGUILayout.PropertyField(settings.FindProperty("addsKotlin"));
  88. DrawDetailLabel("Turn off this if another library is already adding Kotlin runtime.");
  89. var addingKotlin = settings.FindProperty("addsKotlin").boolValue;
  90. if (addingKotlin) {
  91. EditorGUI.indentLevel++;
  92. EditorGUILayout.PropertyField(settings.FindProperty("kotlinVersion"), GUILayout.Width(400));
  93. DrawDetailLabel("If not specified, use the default version: " + UniWebViewEditorSettings.defaultKotlinVersion);
  94. EditorGUI.indentLevel--;
  95. }
  96. EditorGUILayout.PropertyField(settings.FindProperty("addsAndroidBrowser"));
  97. DrawDetailLabel("Turn off this if another library is already adding 'androidx.browser:browser'.");
  98. var addingBrowser = settings.FindProperty("addsAndroidBrowser").boolValue;
  99. if (addingBrowser) {
  100. EditorGUI.indentLevel++;
  101. EditorGUILayout.PropertyField(settings.FindProperty("androidBrowserVersion"), GUILayout.Width(400));
  102. DrawDetailLabel("If not specified, use the default version: " + UniWebViewEditorSettings.defaultAndroidBrowserVersion);
  103. EditorGUI.indentLevel--;
  104. }
  105. EditorGUILayout.PropertyField(settings.FindProperty("enableJetifier"));
  106. DrawDetailLabel("Turn off this if you do not need Jetifier (for converting other legacy support dependencies to Android X).");
  107. EditorGUI.indentLevel--;
  108. EditorGUILayout.EndVertical();
  109. // Auth callbacks
  110. EditorGUILayout.Space();
  111. EditorGUILayout.BeginVertical();
  112. EditorGUILayout.LabelField("Auth Callbacks", EditorStyles.boldLabel);
  113. EditorGUI.indentLevel++;
  114. EditorGUILayout.PropertyField(settings.FindProperty("authCallbackUrls"), true);
  115. DrawDetailLabel("Adds all available auth callback URLs here to use UniWebView's auth support.");
  116. EditorGUILayout.Space();
  117. EditorGUILayout.PropertyField(settings.FindProperty("supportLINELogin"));
  118. DrawDetailLabel("LINE Login is using a custom fixed scheme. If you want to support LINE Login, turn on this.");
  119. EditorGUI.indentLevel--;
  120. EditorGUILayout.EndVertical();
  121. EditorGUILayout.Space();
  122. EditorGUILayout.BeginHorizontal();
  123. EditorGUI.indentLevel++;
  124. EditorGUILayout.HelpBox("Read the help page to know more about all UniWebView preferences detail.", MessageType.Info);
  125. var style = new GUIStyle(GUI.skin.label);
  126. style.normal.textColor = Color.blue;
  127. if (GUILayout.Button("Help Page", style)) {
  128. Application.OpenURL("https://docs.uniwebview.com/guide/installation.html#optional-steps");
  129. }
  130. EditorGUILayout.Space();
  131. EditorGUI.indentLevel--;
  132. EditorGUILayout.EndHorizontal();
  133. if (EditorGUI.EndChangeCheck()) {
  134. settings.ApplyModifiedProperties();
  135. AssetDatabase.SaveAssets();
  136. }
  137. EditorGUIUtility.labelWidth = 0;
  138. }
  139. static void DrawDetailLabel(string text) {
  140. EditorGUI.indentLevel++;
  141. EditorGUILayout.LabelField(text, EditorStyles.miniLabel);
  142. EditorGUI.indentLevel--;
  143. }
  144. }