-
Notifications
You must be signed in to change notification settings - Fork 341
Expand file tree
/
Copy pathDrawArrowWindow.cs
More file actions
46 lines (41 loc) · 1.56 KB
/
DrawArrowWindow.cs
File metadata and controls
46 lines (41 loc) · 1.56 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
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace ToolKits
{
public class DrawArrowWindow : EditorWindow
{
private static DrawArrowWindow _window;
private static readonly Vector2 MIN_SIZE = new Vector2(300, 200);
private const int LABEL_SIZE = 25;
[MenuItem("Tools/在窗口上绘制一条带有箭头的线", priority = 6)]
public static void PopUp()
{
_window = GetWindow<DrawArrowWindow>("箭头线窗口");
_window.minSize = _window.maxSize = MIN_SIZE;
_window.Show();
}
private void OnGUI()
{
DrawArrow(new Vector2(10, 10), new Vector2(150, 10), Color.white);
DrawArrow(new Vector2(10, 10), new Vector2(10, 150), Color.white);
GUI.Label(new Rect(160, 10, LABEL_SIZE, LABEL_SIZE), "X轴");
GUI.Label(new Rect(10, 160, LABEL_SIZE, LABEL_SIZE), "Y轴");
}
private void DrawArrow(Vector2 from, Vector2 to, Color color)
{
Handles.BeginGUI();
Handles.color = color;
Handles.DrawAAPolyLine(3, from, to);
Vector2 v0 = from - to;
v0 *= 10 / v0.magnitude;
Vector2 v1 = new Vector2(v0.x * 0.866f - v0.y * 0.5f, v0.x * 0.5f + v0.y * 0.866f);
Vector2 v2 = new Vector2(v0.x * 0.866f + v0.y * 0.5f, v0.x * -0.5f + v0.y * 0.866f);
;
Handles.DrawAAPolyLine(3, to + v1, to, to + v2);
Handles.EndGUI();
}
}
}