private void Awake() { vertices2D = new List <Vector2>(); vertices2D.Add(new Vector2(0, 0)); vertices2D.Add(new Vector2(0, 25)); vertices2D.Add(new Vector2(25, 25)); vertices2D.Add(new Vector2(25, 50)); vertices2D.Add(new Vector2(0, 50)); vertices2D.Add(new Vector2(0, 75)); vertices2D.Add(new Vector2(75, 75)); vertices2D.Add(new Vector2(75, 50)); vertices2D.Add(new Vector2(50, 50)); vertices2D.Add(new Vector2(50, 25)); vertices2D.Add(new Vector2(75, 25)); vertices2D.Add(new Vector2(75, 0)); mesh = new Mesh(); mesh.name = "parkingZoneMesh"; filter = gameObject.AddComponent <MeshFilter>(); filter.mesh = mesh; var meshRender = MeshUtil.ApplyMaterial(gameObject, new Color32(165, 165, 165, 255)); meshRender.sortingOrder = SortingOrder.Is(Layer.Polygon); spheres = new List <GameObject>(); GameObject sphereHolderObj = new GameObject("SphereHolder"); sphereHolderObj.transform.SetParent(transform, false); sphereHolder = sphereHolderObj.transform; nodes = new List <PathNode>(); GameObject nodeHolderObj = new GameObject("NodeHolder"); nodeHolderObj.transform.SetParent(transform, false); nodeHolder = nodeHolderObj.transform; shapeInfos = new List <ShapeInfo>(); UpdateSelfShape(); }
public void Init(List <Vector2> vertices2D) { if (mesh != null) { throw new Exception("QuadZone mesh already inited"); } mesh = new Mesh(); mesh.name = "QuadZoneMesh"; filter = gameObject.AddComponent <MeshFilter>(); filter.mesh = mesh; MeshUtil.ApplyMaterial(gameObject, Color); int[] indices = Triangulator.Triangulate(vertices2D); Vector3[] vertices = vertices2D.Select(c => new Vector3(c.x, 0, c.y)).ToArray(); mesh.Clear(); mesh.vertices = vertices; mesh.triangles = indices; mesh.RecalculateNormals(); mesh.RecalculateBounds(); }