Skip to content

Instantly share code, notes, and snippets.

@Refsa
Created April 23, 2020 16:00
Show Gist options
  • Save Refsa/e4c6c2308f8dc2273b9c67764cc68a44 to your computer and use it in GitHub Desktop.
Save Refsa/e4c6c2308f8dc2273b9c67764cc68a44 to your computer and use it in GitHub Desktop.
Open Unity Preferences window to specific preference provider
// As an example it will look for the name specified in the SettingsProvider
using UnityEditor;
public static class PreferenceProviderExample
{
[SettingsProvider]
public static SettingsProvider CreateSettingsProvider()
{
var provider = new SettingsProvider("YourPreference", SettingsScope.User)
{
}
}
}
// Name of preferences window has changed so the older methods of calling the window doesnt work
// This way is tested in 2020.1.0b5.3485
// It will find any SettingsProvider you have made using the name specified when it was created
using UnityEditor;
using System;
using System.Reflection;
public static class OpenPreferences
{
public static void OpenPreferencesWindow(string preferenceName)
{
var preferencesWindowType = Type.GetType("UnityEditor.PreferenceSettingsWindow,UnityEditor");
var prefWindow = EditorWindow.GetWindow(preferencesWindowType);
var pickPref = preferencesWindowType.GetMethod("SelectProviderByName", BindingFlags.NonPublic | BindingFlags.Instance);
pickPref.Invoke(prefWindow, new object[]{preferenceName});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment