示例
[MenuItem ("Tool/Open Unity Preferences")]
static void OpenUnityPreferences()
{
//GetType("NameSpace.ClassName+嵌套类,程序集")
System.Type T = System.Type.GetType("UnityEditor.PreferencesWindow,UnityEditor");
Debug.Log(T);
if (T == null)
return;
var focusedWindow = EditorWindow.focusedWindow;
//已经打开
if (focusedWindow != null && focusedWindow.GetType() == T)
return;
//GetWindow(Type, true(不可嵌入其他窗口内), 标题)
var window = EditorWindow.GetWindow(T, true, "Unity Preferences");
if (window == null) {
Debug.Log("No Preferences Window Found");
return;
}
var invokerType = window.GetType();
var invokerMethod = invokerType.GetMethod("ReadPreferences",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
if (invokerMethod != null) {
invokerMethod.Invoke(window, null);
} else {
Debug.Log("No Reflection Method Found For Preferences");
}
}