public Mesh GetMesh(Sprite sprite) { Mesh mesh; if (map.ContainsKey(sprite)) { mesh = map[sprite]; } else { mesh = new Mesh(); NavMeshBuilder2d.sprite2mesh(sprite, mesh); map.Add(sprite, mesh); } return mesh; }
public Mesh GetMesh(Sprite sprite, Transform transform) { Mesh mesh; if (map.ContainsKey(sprite)) { mesh = map[sprite]; } else { var shapeCount = sprite.GetPhysicsShapeCount(); if (shapeCount > 0) { mesh = new Mesh(); var combine = new CombineInstance[shapeCount]; for (var i = 0; i < shapeCount; i++) { var shape = new List <Vector2>(); sprite.GetPhysicsShape(i, shape); var vertices = shape.Select(point => new Vector3(point.x, point.y, 0.0f)).ToList(); combine[i].mesh = CreateMeshFromPolygon(vertices); combine[i].transform = transform.localToWorldMatrix; } mesh.CombineMeshes(combine); map.Add(sprite, mesh); } else { mesh = new Mesh(); NavMeshBuilder2d.sprite2mesh(sprite, mesh); map.Add(sprite, mesh); } } return(mesh); }