-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditorTool.cs
More file actions
38 lines (33 loc) · 981 Bytes
/
EditorTool.cs
File metadata and controls
38 lines (33 loc) · 981 Bytes
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
using UnityEditor;
using UnityEngine;
public class EditorTool : EditorWindow
{
[MenuItem("Tools/Editor Tool")]
public static void ShowWindow()
{
GetWindow<EditorTool>("Editor Tool");
}
private void OnEnable()
{
SceneView.duringSceneGui += OnScene;
}
private void OnDisable()
{
SceneView.duringSceneGui -= OnScene;
}
private void OnScene(SceneView scene)
{
Vector2 mousePos = Event.current.mousePosition;
// Adjust for correct resolution and orientation
float ppp = EditorGUIUtility.pixelsPerPoint;
mousePos.y = scene.camera.pixelHeight - mousePos.y * ppp;
mousePos.x *= ppp;
Ray ray = scene.camera.ScreenPointToRay(mousePos);
RaycastHit hit;
Physics.Raycast(ray, out hit);
if (Event.current.type == EventType.MouseDown && Event.current.button == 0) // LeftMouseDown
{
Debug.Log(hit.point);
}
}
}