main mesh contains all triangles of this mesh and also all that can be accessed via submeshes.
submeshes contains tris that can be accessed also via main mesh
submeshes are always exists in any mesh, at least one
sum of all submeshes tris is equal to main mesh tris
submeshes are used to apply different materials to tris
so finally, when you got from raycast hit to triangle index 50, you should search it in main mesh (it contains all tris including triangle 50), then get vertices for this triangle, and find triangle with those vertices in submeshes
bonus: MeshAnaliser.cs
using UnityEngine;
using System.Collections;
public class MeshAnaliser : MonoBehaviour
{
void Update()
{
if (Input.GetMouseButtonDown(0))
{
RaycastHit hit;
if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit))
{
Mesh m = GetMesh(gameObject);
if (m)
{
int[] hittedTriangle = new int[]
{
m.triangles[hit.triangleIndex * 3],
m.triangles[hit.triangleIndex * 3 + 1],
m.triangles[hit.triangleIndex * 3 + 2]
};
for (int i = 0; i < m.subMeshCount; i++)
{
int[] subMeshTris = m.GetTriangles(i);
for (int j = 0; j < subMeshTris.Length; j += 3)
{
if (subMeshTris[j] == hittedTriangle[0] &&
subMeshTris[j + 1] == hittedTriangle[1] &&
subMeshTris[j + 2] == hittedTriangle[2])
{
Debug.Log(string.Format("triangle index:{0} submesh index:{1} submesh triangle index:{2}", hit.triangleIndex, i, j / 3));
}
}
}
}
}
}
}
static Mesh GetMesh(GameObject go)
{
if (go)
{
MeshFilter mf = go.GetComponent();
if (mf)
{
Mesh m = mf.sharedMesh;
if (!m) { m = mf.mesh; }
if (m)
{
return m;
}
}
}
return (Mesh)null;
}
}
I ran some tests using a procedurally-generated mesh. As artie suspected in his original post, the triangle lists for the submeshes seem to be stored in order in the global triangle list. The ordering is determined by the submesh index, not the order of creation of the submeshes.
The full triangle list will consist of all the vertex indices for submesh0, followed by all the vertex indices for submesh1, followed by all the vertex indices for submesh2.