|
image.png
其实就是获取当前鼠标点击对象的mesh属性,并用GUI显示出来
using System.Collections;using System.Collections.Generic;using UnityEditor;using UnityEngine; [RequireComponent(typeof(MeshFilter))] public class TestMeshViewer : MonoBehaviour { private MeshFilter _meshFilter; private Mesh _mesh; public List<Vector3> verticesList = new List<Vector3>(); public List<Vector2> uvList = new List<Vector2>(); public List<int> triList = new List<int>(); private void Start() { _meshFilter = this.GetComponent<MeshFilter>(); _mesh = _meshFilter.mesh; ReadMeshInfo(); } private void ReadMeshInfo() { for (int i = 0, imax = _mesh.vertexCount; i < imax; ++i) { verticesList.Add(_mesh.vertices); uvList.Add(_mesh.uv); } for (int i = 0, imax = _mesh.triangles.Length; i < imax; ++i) { triList.Add(_mesh.triangles); } } }using UnityEditor;using UnityEngine;using System.Collections.Generic;using System.Text;namespace YanCheZuo{ [CustomEditor(typeof(TestMeshViewer))] public class MeshViewerEditor : Editor { private bool showInfo = true; private bool showUV = true; private bool showVertice = true; public override void OnInspectorGUI() { base.OnInspectorGUI(); showInfo = GUILayout.Toggle(showInfo, "Show Info"); showVertice = GUILayout.Toggle(showVertice, "Show Vertice"); showUV = GUILayout.Toggle(showUV, "Show UV"); } private void OnSceneGUI() { if (!showInfo) { return; } GUIStyle style = new GUIStyle(); style.normal.textColor = Color.red; TestMeshViewer viewer = target as TestMeshViewer; Dictionary<Vector3, StringBuilder> posList = new Dictionary<Vector3, StringBuilder>(); for (int i = 0, imax = viewer.verticesList.Count; i < imax; ++i) { Vector3 vPos = viewer.transform.TransformPoint(viewer.verticesList); StringBuilder sb; if (posList.TryGetValue(vPos, out sb)) { StringBuilder str = new StringBuilder("index:" + i); AddVerticeStr(ref str, vPos); AddUVStr(ref str, ref viewer.uvList, i); sb.AppendLine(str.ToString()); } else { sb = new StringBuilder(); StringBuilder str = new StringBuilder("index:" + i); AddVerticeStr(ref str, vPos); AddUVStr(ref str, ref viewer.uvList, i); sb.AppendLine(str.ToString()); posList.Add(vPos, sb); } Handles.Label(vPos, sb.ToString(), style); } } private void AddVerticeStr(ref StringBuilder sb, Vector3 vert) { if (!showVertice) { return; } sb.Append(",vertice:" + vert); } private void AddUVStr(ref StringBuilder sb, ref List<Vector2> uvList, int index) { if (!showUV) { return; } if (uvList.Count > index) { sb.Append(",uv:" + uvList[index]); } } }} |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
×
|