Created
April 23, 2020 16:00
-
-
Save Refsa/e4c6c2308f8dc2273b9c67764cc68a44 to your computer and use it in GitHub Desktop.
Open Unity Preferences window to specific preference provider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) | |
{ | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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