-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSceneCameraRelativeTool.cs
More file actions
68 lines (57 loc) · 2.2 KB
/
SceneCameraRelativeTool.cs
File metadata and controls
68 lines (57 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using UnityEngine;
using UnityEditor;
using UnityEditor.EditorTools;
// 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.
[EditorTool("Scene Camera Relative")]
class SceneCameraRelativeTool : EditorTool
{
// Serialize this value to set a default value in the Inspector.
[SerializeField]
Texture2D m_ToolIcon;
GUIContent m_IconContent;
void OnEnable()
{
m_IconContent = new GUIContent()
{
image = m_ToolIcon,
text = "Scene Camera Relative",
tooltip = "Scene Camera Relative"
};
}
public override GUIContent toolbarIcon
{
get { return m_IconContent; }
}
// This is called for each window that your tool is active in. Put the functionality of your tool here.
public override void OnToolGUI(EditorWindow window)
{
EditorGUI.BeginChangeCheck();
Vector3 position = Tools.handlePosition;
Matrix4x4 cm = SceneView.lastActiveSceneView.camera.cameraToWorldMatrix;
Vector3 up = cm * Vector3.up;
Vector3 right = cm * Vector3.right;
using (new Handles.DrawingScope(Color.red))
{
position = Handles.Slider(position, right);
}
using (new Handles.DrawingScope(Color.green))
{
position = Handles.Slider(position, up);
}
using (new Handles.DrawingScope(new Color(0,0,1,.3f)))
{
float size = HandleUtility.GetHandleSize(position) * .15f;
Vector3 offset = (up * size) + (right * size);
position = Handles.FreeMoveHandle(position + offset, Quaternion.identity, size, Vector3.zero, Handles.DotHandleCap);
position -= offset;
}
if (EditorGUI.EndChangeCheck())
{
Vector3 delta = position - Tools.handlePosition;
Undo.RecordObjects(Selection.transforms, "Move Transform");
foreach (var transform in Selection.transforms)
transform.position += delta;
}
}
}