123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- using UnityEngine;
- using UnityEditor;
- using System.Collections.Generic;
- using System;
- using System.IO;
-
- class UniWebViewEditorSettings: ScriptableObject
- {
- const string assetPath = "Assets/Editor/UniWebView/settings.asset";
-
- [SerializeField]
- internal bool usesCleartextTraffic = false;
-
- [SerializeField]
- internal bool writeExternalStorage = false;
-
- [SerializeField]
- internal bool accessFineLocation = false;
-
- [SerializeField]
- internal bool addsKotlin = true;
-
- [SerializeField]
- internal string kotlinVersion = null;
-
- [SerializeField]
- internal bool addsAndroidBrowser = true;
-
- [SerializeField]
- internal string androidBrowserVersion = null;
-
- [SerializeField]
- internal bool enableJetifier = true;
-
- [SerializeField]
- internal string[] authCallbackUrls = { };
-
- [SerializeField]
- internal bool supportLINELogin = false;
-
- internal static string defaultKotlinVersion = "1.6.21";
- internal static string defaultAndroidBrowserVersion = "1.2.0";
-
- internal static UniWebViewEditorSettings GetOrCreateSettings() {
- var settings = AssetDatabase.LoadAssetAtPath<UniWebViewEditorSettings>(assetPath);
-
- if (settings == null) {
- settings = ScriptableObject.CreateInstance<UniWebViewEditorSettings>();
-
- Directory.CreateDirectory("Assets/Editor/UniWebView/");
- AssetDatabase.CreateAsset(settings, assetPath);
- AssetDatabase.SaveAssets();
- }
-
- return settings;
- }
-
- internal static SerializedObject GetSerializedSettings() {
- return new SerializedObject(GetOrCreateSettings());
- }
- }
-
- static class UniWebViewSettingsProvider {
- static SerializedObject settings;
-
- #if UNITY_2018_3_OR_NEWER
- private class Provider : SettingsProvider {
- public Provider(string path, SettingsScope scope = SettingsScope.User): base(path, scope) {}
- public override void OnGUI(string searchContext) {
- DrawPref();
- }
- }
- [SettingsProvider]
- static SettingsProvider UniWebViewPref() {
- return new Provider("Preferences/UniWebView");
- }
- #else
- [PreferenceItem("UniWebView")]
- #endif
- static void DrawPref() {
- EditorGUIUtility.labelWidth = 320;
- EditorGUIUtility.fieldWidth = 20;
- if (settings == null) {
- settings = UniWebViewEditorSettings.GetSerializedSettings();
- }
- settings.Update();
- EditorGUI.BeginChangeCheck();
-
- // Manifest
- EditorGUILayout.Space();
- EditorGUILayout.BeginVertical();
- EditorGUILayout.LabelField("Android Manifest", EditorStyles.boldLabel);
-
- EditorGUI.indentLevel++;
- EditorGUILayout.PropertyField(settings.FindProperty("usesCleartextTraffic"));
- DrawDetailLabel("If you need to load plain HTTP content.");
-
- EditorGUILayout.PropertyField(settings.FindProperty("writeExternalStorage"));
- DrawDetailLabel("If you need to download an image from web page.");
-
- EditorGUILayout.PropertyField(settings.FindProperty("accessFineLocation"));
- DrawDetailLabel("If you need to enable location support in web view.");
- EditorGUI.indentLevel--;
- EditorGUILayout.EndVertical();
-
- // Gradle
- EditorGUILayout.Space();
- EditorGUILayout.BeginVertical();
- EditorGUILayout.LabelField("Gradle Build", EditorStyles.boldLabel);
- EditorGUI.indentLevel++;
- EditorGUILayout.PropertyField(settings.FindProperty("addsKotlin"));
- DrawDetailLabel("Turn off this if another library is already adding Kotlin runtime.");
- var addingKotlin = settings.FindProperty("addsKotlin").boolValue;
- if (addingKotlin) {
- EditorGUI.indentLevel++;
- EditorGUILayout.PropertyField(settings.FindProperty("kotlinVersion"), GUILayout.Width(400));
- DrawDetailLabel("If not specified, use the default version: " + UniWebViewEditorSettings.defaultKotlinVersion);
- EditorGUI.indentLevel--;
- }
-
- EditorGUILayout.PropertyField(settings.FindProperty("addsAndroidBrowser"));
- DrawDetailLabel("Turn off this if another library is already adding 'androidx.browser:browser'.");
- var addingBrowser = settings.FindProperty("addsAndroidBrowser").boolValue;
- if (addingBrowser) {
- EditorGUI.indentLevel++;
- EditorGUILayout.PropertyField(settings.FindProperty("androidBrowserVersion"), GUILayout.Width(400));
- DrawDetailLabel("If not specified, use the default version: " + UniWebViewEditorSettings.defaultAndroidBrowserVersion);
- EditorGUI.indentLevel--;
- }
-
-
- EditorGUILayout.PropertyField(settings.FindProperty("enableJetifier"));
- DrawDetailLabel("Turn off this if you do not need Jetifier (for converting other legacy support dependencies to Android X).");
- EditorGUI.indentLevel--;
- EditorGUILayout.EndVertical();
-
- // Auth callbacks
- EditorGUILayout.Space();
- EditorGUILayout.BeginVertical();
- EditorGUILayout.LabelField("Auth Callbacks", EditorStyles.boldLabel);
- EditorGUI.indentLevel++;
- EditorGUILayout.PropertyField(settings.FindProperty("authCallbackUrls"), true);
- DrawDetailLabel("Adds all available auth callback URLs here to use UniWebView's auth support.");
-
- EditorGUILayout.Space();
- EditorGUILayout.PropertyField(settings.FindProperty("supportLINELogin"));
- DrawDetailLabel("LINE Login is using a custom fixed scheme. If you want to support LINE Login, turn on this.");
-
- EditorGUI.indentLevel--;
- EditorGUILayout.EndVertical();
-
- EditorGUILayout.Space();
- EditorGUILayout.BeginHorizontal();
- EditorGUI.indentLevel++;
- EditorGUILayout.HelpBox("Read the help page to know more about all UniWebView preferences detail.", MessageType.Info);
-
- var style = new GUIStyle(GUI.skin.label);
- style.normal.textColor = Color.blue;
- if (GUILayout.Button("Help Page", style)) {
- Application.OpenURL("https://docs.uniwebview.com/guide/installation.html#optional-steps");
- }
-
- EditorGUILayout.Space();
- EditorGUI.indentLevel--;
- EditorGUILayout.EndHorizontal();
-
- if (EditorGUI.EndChangeCheck()) {
- settings.ApplyModifiedProperties();
- AssetDatabase.SaveAssets();
- }
- EditorGUIUtility.labelWidth = 0;
- }
-
- static void DrawDetailLabel(string text) {
- EditorGUI.indentLevel++;
- EditorGUILayout.LabelField(text, EditorStyles.miniLabel);
- EditorGUI.indentLevel--;
- }
- }
|