-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathShowHoveredInfo.cs
More file actions
71 lines (62 loc) · 1.94 KB
/
Copy pathShowHoveredInfo.cs
File metadata and controls
71 lines (62 loc) · 1.94 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
69
70
71
using System.Linq;
namespace UnityEngine.ProBuilder.Debug
{
/// <summary>Internal class.</summary>
[RequireComponent(typeof(Collider))]
public class ShowHoveredInfo : MonoBehaviour
{
Mesh m_Mesh;
static Material m_Material;
bool m_IsHovering;
#if UNITY_EDITOR
[RuntimeInitializeOnLoadMethod]
static void ResetStaticsOnLoad()
{
m_Material = null;
}
#endif
void Start()
{
if (m_Material == null)
m_Material = new Material(Shader.Find("Unlit/Color"));
Mesh original = GetComponent<MeshFilter>().sharedMesh;
m_Mesh = new Mesh();
m_Mesh.vertices = original.vertices;
int[] tris = original.triangles;
int[] lines = new int[tris.Length * 2];
int index = 0;
for (int i = 0; i < tris.Length; i += 3)
{
lines[index++] = tris[i];
lines[index++] = tris[i + 1];
lines[index++] = tris[i + 1];
lines[index++] = tris[i + 2];
lines[index++] = tris[i + 2];
lines[index++] = tris[i];
}
m_Mesh.SetIndices(lines, MeshTopology.Lines, 0, false);
}
void OnMouseEnter()
{
m_IsHovering = true;
}
void OnMouseExit()
{
m_IsHovering = false;
}
void OnGUI()
{
if (!m_IsHovering)
return;
GUI.Label(
new Rect(Input.mousePosition.x, Screen.height - Input.mousePosition.y, 600f, 900f),
gameObject.name + "\n" + string.Join("\n",
GetComponents<Component>().Select(x => x.GetType().ToString()).ToArray()));
}
void OnRenderObject()
{
m_Material.SetPass(0);
Graphics.DrawMeshNow(m_Mesh, transform.localToWorldMatrix, 0);
}
}
}