A game about forced loneliness, made by TACStudios
at master 1.8 kB view raw
1using UnityEditor.EditorTools; 2using UnityEngine; 3 4namespace UnityEditor.Tilemaps 5{ 6 /// <summary> 7 /// An `EditorTool` for handling Transform for a `GridSelection`. 8 /// </summary> 9 public class GridSelectionTransformTool : GridSelectionTool 10 { 11 private static class Styles 12 { 13 public static readonly GUIContent toolbarIcon = EditorGUIUtility.TrTextContentWithIcon("Transform", "Shows a Gizmo in the Scene view for changing the transform for the Grid Selection", "TransformTool"); 14 } 15 16 /// <summary> 17 /// Toolbar icon for the `GridSelectionTransformTool`. 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 Transforms for the `GridSelectionTransformTool`. 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 = before; 41 Handles.TransformHandle(ref position, ref after, ref scale); 42 if (EditorGUI.EndChangeCheck()) 43 { 44 rotation *= Quaternion.Inverse(before) * after; 45 } 46 before = after; 47 } 48 } 49}