利用反射打开PreferencesWindow

作者:追风剑情 发布于:2018-4-11 15:02 分类:Unity3d

示例


  1. [MenuItem ("Tool/Open Unity Preferences")]
  2. static void OpenUnityPreferences()
  3. {
  4. //GetType("NameSpace.ClassName+嵌套类,程序集")
  5. System.Type T = System.Type.GetType("UnityEditor.PreferencesWindow,UnityEditor");
  6. Debug.Log(T);
  7. if (T == null)
  8. return;
  9. var focusedWindow = EditorWindow.focusedWindow;
  10. //已经打开
  11. if (focusedWindow != null && focusedWindow.GetType() == T)
  12. return;
  13.  
  14. //GetWindow(Type, true(不可嵌入其他窗口内), 标题)
  15. var window = EditorWindow.GetWindow(T, true, "Unity Preferences");
  16. if (window == null) {
  17. Debug.Log("No Preferences Window Found");
  18. return;
  19. }
  20.  
  21. var invokerType = window.GetType();
  22. var invokerMethod = invokerType.GetMethod("ReadPreferences",
  23. System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
  24.  
  25. if (invokerMethod != null) {
  26. invokerMethod.Invoke(window, null);
  27. } else {
  28. Debug.Log("No Reflection Method Found For Preferences");
  29. }
  30. }


111111.jpg

标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号