Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Assets/Examples/Scripts/NavMeshSourceTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,24 @@ public class NavMeshSourceTag : MonoBehaviour
// Global containers for all active mesh/terrain tags
public static List<MeshFilter> m_Meshes = new List<MeshFilter>();
public static List<Terrain> m_Terrains = new List<Terrain>();
public static List<int> m_Areas = new List<int>();

[SerializeField] private string areaName = "Walkable";

void OnEnable()
{
var m = GetComponent<MeshFilter>();
if (m != null)
{
m_Meshes.Add(m);
m_Areas.Add(NavMesh.GetAreaFromName(areaName));
}

var t = GetComponent<Terrain>();
if (t != null)
{
m_Terrains.Add(t);
m_Areas.Add(NavMesh.GetAreaFromName(areaName));
}
}

Expand Down Expand Up @@ -58,7 +63,7 @@ public static void Collect(ref List<NavMeshBuildSource> sources)
s.shape = NavMeshBuildSourceShape.Mesh;
s.sourceObject = m;
s.transform = mf.transform.localToWorldMatrix;
s.area = 0;
s.area = m_Areas[i];
sources.Add(s);
}

Expand All @@ -72,7 +77,7 @@ public static void Collect(ref List<NavMeshBuildSource> sources)
s.sourceObject = t.terrainData;
// Terrain system only supports translation - so we pass translation only to back-end
s.transform = Matrix4x4.TRS(t.transform.position, Quaternion.identity, Vector3.one);
s.area = 0;
s.area = m_Areas[i];
sources.Add(s);
}
}
Expand Down