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