Rotate3DManipulator.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #if false
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using UnityEngine;
  7. using UnityEngine.UIElements;
  8. using UnityEditor;
  9. namespace UnityEditor.VFX.UI
  10. {
  11. class Rotate3DManipulator : Manipulator
  12. {
  13. public Rotate3DManipulator(Element3D element3D)
  14. {
  15. m_Element3D = element3D;
  16. }
  17. Element3D m_Element3D;
  18. protected override void RegisterCallbacksOnTarget()
  19. {
  20. target.RegisterCallback<MouseUpEvent>(OnMouseUp, Capture.Capture);
  21. target.RegisterCallback<MouseDownEvent>(OnMouseDown, Capture.Capture);
  22. //target.RegisterCallback<KeyDownEvent>(OnKeyDown);
  23. }
  24. protected override void UnregisterCallbacksFromTarget()
  25. {
  26. target.UnregisterCallback<MouseUpEvent>(OnMouseUp);
  27. target.UnregisterCallback<MouseDownEvent>(OnMouseDown);
  28. //target.UnregisterCallback<KeyDownEvent>(OnKeyDown);
  29. }
  30. void Release()
  31. {
  32. if (m_Dragging)
  33. {
  34. m_Dragging = false;
  35. if (target.HasMouseCapture())
  36. target.ReleaseMouseCapture();
  37. EditorGUIUtility.SetWantsMouseJumping(0);
  38. target.UnregisterCallback<MouseMoveEvent>(OnMouseMove);
  39. }
  40. }
  41. bool m_Dragging;
  42. void OnMouseDown(MouseDownEvent e)
  43. {
  44. m_Dragging = true;
  45. EditorGUIUtility.SetWantsMouseJumping(1);
  46. target.TakeMouseCapture();
  47. target.RegisterCallback<MouseMoveEvent>(OnMouseMove, Capture.Capture);
  48. m_Dragging = true;
  49. e.StopPropagation();
  50. }
  51. void OnMouseUp(MouseUpEvent e)
  52. {
  53. Release();
  54. e.StopPropagation();
  55. }
  56. void OnMouseMove(MouseMoveEvent e)
  57. {
  58. if (m_Dragging)
  59. {
  60. if (!target.HasMouseCapture())
  61. {
  62. Release();
  63. return;
  64. }
  65. Quaternion rotation = m_Element3D.rotation;
  66. rotation = Quaternion.AngleAxis(e.mouseDelta.y * .003f * Mathf.Rad2Deg, rotation * Vector3.right) * rotation;
  67. rotation = Quaternion.AngleAxis(e.mouseDelta.x * .003f * Mathf.Rad2Deg, Vector3.up) * rotation;
  68. m_Element3D.rotation = rotation;
  69. e.StopPropagation();
  70. }
  71. }
  72. }
  73. }
  74. #endif