public static void UpdateNavMesh(NavMeshRenderer mesh, SerializedObject serializedObject, ArcTeleportData teleportSettings) { UnityEngine.AI.NavMeshTriangulation tri = UnityEngine.AI.NavMesh.CalculateTriangulation(); int vert_size, tri_size; CullNavmeshTriangulation(ref tri, teleportSettings.NavAreaMask, out vert_size, out tri_size); Mesh m = ConvertNavmeshToMesh(tri, vert_size, tri_size); // Can't use SerializedProperties here because BorderPointSet doesn't derive from UnityEngine.Object mesh.SelectableMeshBorder = FindBorderEdges(m); teleportSettings.SelectableMesh = m; mesh.SelectableMesh = mesh.SelectableMesh; // Make sure that setter is called }
public static void ClearNavMesh(NavMeshRenderer mesh, SerializedObject serializedObject, ArcTeleportData teleportSettings) { //Undo.RecordObject(mesh, "Clear Navmesh Data"); // Note: Unity does not serialize "null" correctly so we set everything to empty objects Mesh m = new Mesh(); m = teleportSettings.SelectableMesh; //serializedObject.Update(); //SerializedProperty p_mesh = serializedObject.FindProperty("_SelectableMesh"); //p_mesh.objectReferenceValue = m; //serializedObject.ApplyModifiedPropertiesWithoutUndo(); mesh.SelectableMesh = mesh.SelectableMesh; // Make sure setter is called mesh.SelectableMeshBorder = new BorderPointSet[0]; }
// Sample a bunch of points along a parabolic curve until you hit gnd. At that point, cut off the parabola // p0: starting point of parabola // v0: initial parabola velocity // a: initial acceleration // dist: distance between sample points // points: number of sample points // gnd: height of the ground, in meters above y=0 // outPts: List that will be populated by new points private static bool CalculateParabolicCurve(Vector3 p0, Vector3 v0, Vector3 a, float dist, int points, int areaMask, List <Vector3> outPts, int collisionLayers) { outPts.Clear(); outPts.Add(p0); Vector3 last = p0; float t = 0; for (int i = 0; i < points; i++) { t += dist / ParabolicCurveDeriv(v0, a, t).magnitude; Vector3 next = ParabolicCurve(p0, v0, a, t); Vector3 castHit; Vector3 hitParentPosition; bool endOnNavmesh; bool doSnapTeleport; bool cast = NavMeshRenderer.Linecast(last, next, out endOnNavmesh, out doSnapTeleport, out castHit, out hitParentPosition, collisionLayers, areaMask); if (cast) { outPts.Add(castHit); if (doSnapTeleport) { outPts.Clear(); outPts.AddRange(CalculateParabolicSnap(p0, hitParentPosition, v0, a, dist, points)); } return(endOnNavmesh); } else { outPts.Add(next); } last = next; } return(false); }