├── README.md └── SceneCameraRelativeTool.cs /README.md: -------------------------------------------------------------------------------- 1 | # UnitySceneRelativeTransformTool 2 | A custom editor tool for unity that allows you to move transforms relative to the scene camera 3 | 4 | License: creative commons cc0 5 | 6 | here's a video of it in action: 7 | https://www.dropbox.com/s/0jvh9rav1fzyoow/2qPTjmtDaE.mp4?dl=0 8 | -------------------------------------------------------------------------------- /SceneCameraRelativeTool.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | using UnityEditor; 4 | using UnityEditor.EditorTools; 5 | 6 | // Tagging a class with the EditorTool attribute and no target type registers a global tool. Global tools are valid for any selection, and are accessible through the top left toolbar in the editor. 7 | [EditorTool("Scene Camera Relative")] 8 | class SceneCameraRelativeTool : EditorTool 9 | { 10 | // Serialize this value to set a default value in the Inspector. 11 | [SerializeField] 12 | Texture2D m_ToolIcon; 13 | 14 | GUIContent m_IconContent; 15 | 16 | void OnEnable() 17 | { 18 | m_IconContent = new GUIContent() 19 | { 20 | image = m_ToolIcon, 21 | text = "Scene Camera Relative", 22 | tooltip = "Scene Camera Relative" 23 | }; 24 | } 25 | 26 | public override GUIContent toolbarIcon 27 | { 28 | get { return m_IconContent; } 29 | } 30 | 31 | // This is called for each window that your tool is active in. Put the functionality of your tool here. 32 | public override void OnToolGUI(EditorWindow window) 33 | { 34 | EditorGUI.BeginChangeCheck(); 35 | 36 | Vector3 position = Tools.handlePosition; 37 | 38 | Matrix4x4 cm = SceneView.lastActiveSceneView.camera.cameraToWorldMatrix; 39 | Vector3 up = cm * Vector3.up; 40 | Vector3 right = cm * Vector3.right; 41 | 42 | using (new Handles.DrawingScope(Color.red)) 43 | { 44 | position = Handles.Slider(position, right); 45 | } 46 | using (new Handles.DrawingScope(Color.green)) 47 | { 48 | position = Handles.Slider(position, up); 49 | } 50 | using (new Handles.DrawingScope(new Color(0,0,1,.3f))) 51 | { 52 | float size = HandleUtility.GetHandleSize(position) * .15f; 53 | Vector3 offset = (up * size) + (right * size); 54 | position = Handles.FreeMoveHandle(position + offset, Quaternion.identity, size, Vector3.zero, Handles.DotHandleCap); 55 | position -= offset; 56 | } 57 | 58 | if (EditorGUI.EndChangeCheck()) 59 | { 60 | Vector3 delta = position - Tools.handlePosition; 61 | 62 | Undo.RecordObjects(Selection.transforms, "Move Transform"); 63 | 64 | foreach (var transform in Selection.transforms) 65 | transform.position += delta; 66 | } 67 | } 68 | } --------------------------------------------------------------------------------