Ingen beskrivning
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GridSelectionRotationTool.cs 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using UnityEditor.EditorTools;
  2. using UnityEngine;
  3. namespace UnityEditor.Tilemaps
  4. {
  5. /// <summary>
  6. /// An `EditorTool` for handling Rotation for a `GridSelection`.
  7. /// </summary>
  8. public class GridSelectionRotateTool : GridSelectionTool
  9. {
  10. private static class Styles
  11. {
  12. public static readonly GUIContent toolbarIcon = EditorGUIUtility.TrTextContentWithIcon("Rotate", "Shows a Gizmo in the Scene view for changing the rotation for the Grid Selection", "RotateTool");
  13. }
  14. /// <summary>
  15. /// Toolbar icon for the `GridSelectionRotateTool`.
  16. /// </summary>
  17. public override GUIContent toolbarIcon => Styles.toolbarIcon;
  18. private Quaternion before = Quaternion.identity;
  19. private void Reset()
  20. {
  21. before = Quaternion.identity;
  22. }
  23. /// <summary>
  24. /// Handles the gizmo for managing Rotation for the `GridSelectionRotateTool`.
  25. /// </summary>
  26. /// <param name="position">Position of the `GridSelection` gizmo.</param>
  27. /// <param name="rotation">Rotation of the `GridSelection` gizmo.</param>
  28. /// <param name="scale">Scale of the `GridSelection` gizmo.</param>
  29. public override void HandleTool(ref Vector3 position, ref Quaternion rotation, ref Vector3 scale)
  30. {
  31. if (Event.current.GetTypeForControl(GUIUtility.hotControl) == EventType.MouseUp)
  32. Reset();
  33. EditorGUI.BeginChangeCheck();
  34. var after = Handles.RotationHandle(before, position);
  35. if (EditorGUI.EndChangeCheck())
  36. {
  37. rotation *= Quaternion.Inverse(before) * after;
  38. }
  39. before = after;
  40. }
  41. }
  42. }