AnimatorWindowProxy.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using UnityEngine;
  2. using UnityEditor;
  3. using UnityEditor.Graphs;
  4. using UnityEditor.Animations;
  5. using System;
  6. using System.Reflection;
  7. namespace FluxEditor
  8. {
  9. public static class AnimatorWindowProxy
  10. {
  11. public static Type ANIMATOR_WINDOW_TYPE = typeof(Graph).Assembly.GetType("UnityEditor.Graphs.AnimatorControllerTool");
  12. private static PropertyInfo _animatorController = null;
  13. public static PropertyInfo AnimatorController {
  14. get {
  15. if( _animatorController == null )
  16. _animatorController = ANIMATOR_WINDOW_TYPE.GetProperty( "animatorController", BindingFlags.Public | BindingFlags.Instance );
  17. return _animatorController;
  18. }
  19. }
  20. public static EditorWindow OpenAnimatorWindow()
  21. {
  22. return EditorWindow.GetWindow( ANIMATOR_WINDOW_TYPE );
  23. }
  24. public static void OpenAnimatorWindowWithAnimatorController( AnimatorController controller )
  25. {
  26. EditorWindow animatorWindow = OpenAnimatorWindow();
  27. AnimatorController animatorControllerValue = AnimatorController.GetValue( animatorWindow, null ) as AnimatorController;
  28. if( animatorControllerValue != controller )
  29. AnimatorController.SetValue( animatorWindow, controller, null );
  30. }
  31. }
  32. }