I’m trying to create an editor script which lets me see the index of the vertices (of the gameObject’s mesh) to which the script is attached to. Here’s what I have so far.
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(ModifyMesh))]
public class ModifyMeshEditor : Editor {
GameObject theGO;
MeshFilter mf;
Mesh mesh;
Vector3[] verts;
void OnSceneGUI () {
if (!Application.isPlaying) {
theGO = Selection.activeGameObject;
if (theGO != null) {
mf = theGO.GetComponent<MeshFilter> ();
mesh = mf.sharedMesh;
verts = mesh.vertices;
}
Handles.color = Color.grey;
for (int p = 0; p < verts.Length; p++) {
Handles.Label (verts [p], p.ToString ());
}
}
}
}
And the other class is this:
using UnityEngine;
[ExecuteInEditMode]
public class ModifyMesh : MonoBehaviour {
GameObject g;
}
This works fine. There are however three problems: (could be more)
-
When I move the gameobject in the scene view, the labels do not move along with it.
-
A separate series of the same labels appears on an entirely different place in the same scene.
-
There are multiple labels in the same position.
If you can shed some light on this topic and explain what is happening here and how to solve it, I’d be a happy man once again.
Thanks!