public static HookInterceptorPreferences GetOrCreatePreferences()
        {
            var allAssets = AssetDatabase.FindAssets("t:HookInterceptorPreferences");
            HookInterceptorPreferences settings = null;

            if (allAssets.Length > 0)
            {
                var path = AssetDatabase.GUIDToAssetPath(allAssets[0]);
                settings = AssetDatabase.LoadAssetAtPath <HookInterceptorPreferences>(path);
            }

            if (settings != null)
            {
                return(settings);
            }

            settings = CreateInstance <HookInterceptorPreferences>();

            AssetDatabase.CreateFolder("Assets", "Editor");
            AssetDatabase.CreateFolder("Assets/Editor", "HookInterceptor");
            AssetDatabase.CreateAsset(settings, PreferencesPath);
            AssetDatabase.SaveAssets();

            return(settings);
        }
Example #2
0
        static HookInterceptor()
        {
            _preferences = HookInterceptorPreferences.GetOrCreatePreferences();

            EditorApplication.update += OnUpdate;
            Intercepted += OnIntercept;
            Formatted   += OnFormatted;
        }
        public static SettingsProvider CreateProvider()
        {
            var provider = new SettingsProvider("Preferences/Hook Interceptor", SettingsScope.User)
            {
                label      = "Hook Interceptor",
                guiHandler = (searchContext) => {
                    var settings = HookInterceptorPreferences.GetSerializedPreferences();

                    settings.Update();
                    EditorGUILayout.PropertyField(settings.FindProperty("_allowIntercepting"), new GUIContent("Allow Intercepting \u24D8", "If disabled, url hooks won't be intercepted using the default logic.\n\nOnly manually intercepting and formatting will work. Both InterceptedSecurely() and Formatted() won't be called."));

                    GUI.enabled = settings.FindProperty("_allowIntercepting").boolValue;
                    EditorGUILayout.PropertyField(settings.FindProperty("_allowFormatting"), new GUIContent("Allow Formatting \u24D8", "If disabled, url hooks won't be formatted using the default logic and methods using attributes won't be called.\n\nOnly manually formatting will work, and Formatted() won't be called."));

                    EditorGUILayout.Space();

                    EditorGUILayout.PropertyField(settings.FindProperty("_useSecureHooks"), new GUIContent("Use secure hooks \u24D8", "If enabled only url hooks with a secure key will be allowed and parsed."));

                    GUI.enabled = settings.FindProperty("_useSecureHooks").boolValue&& settings.FindProperty("_allowIntercepting").boolValue;
                    EditorGUILayout.PropertyField(settings.FindProperty("_secureKey"), new GUIContent("Secure key \u24D8", "Key that an allowed url hook must contain.\n\nAny length and characters are allowed, minus / and \\"));

                    GUI.enabled = settings.FindProperty("_allowIntercepting").boolValue&& settings.FindProperty("_allowFormatting").boolValue;
                    EditorGUILayout.PropertyField(settings.FindProperty("_exceptions"), new GUIContent("Parsing exceptions \u24D8", "Each string listed here will not be parsed, which means Formatted() won't be called. You must parse the exceptions manually yourself.\n\nSeparate each exception with a comma."));

                    GUI.enabled = true;

                    EditorGUILayout.Space();

                    EditorGUILayout.PropertyField(settings.FindProperty("_logging"), new GUIContent("Logging level \u24D8", "Logging level. Essential is recommended."));

                    settings.ApplyModifiedProperties();
                },

                keywords = new HashSet <string>(new[] { "HookInterceptor", "Hook", "Hooks", "Interceptor", "URL", "F10" })
            };

            return(provider);
        }