public void init(InvisBuildingJsonRepsonse_Building building, PoiHandler poi_handler) { this.poi_handler = poi_handler; addPois(); transform = GetComponent <Transform>(); this.lat = building.startPoint[1]; this.lon = building.startPoint[0]; this.id = building.id; this.name = "fade_building_" + building.id; Vector2[] vertices2D = new Vector2[building.building.Length / 2]; for (int i = 0; i < building.building.Length; i += 2) { vertices2D[i / 2] = new Vector2(building.building[i], building.building[i + 1]); } if (map == null) { map = GameObject.Find("Map").GetComponent <Map>(); } MeshFilter filter = gameObject.AddComponent(typeof(MeshFilter)) as MeshFilter; filter.mesh = CreateMesh(vertices2D); updateInvisBuilding(); }
public void assignNewBuildings(string data) { ClipperLib.ClipperOffset co = new ClipperLib.ClipperOffset(); InvisBuildingJsonRepsonse res = JsonUtility.FromJson <InvisBuildingJsonRepsonse>(data); for (int i = 0; i < res.response.Length; ++i) { bool duplicate = false; for (int j = 0; j < all_buildings.Count; ++j) { if (res.response[i].id == all_buildings[j].id) { duplicate = true; } } if (!duplicate) { // invisible building and fade building GameObject fb = Instantiate(Resources.Load("FadeBuilding"), new Vector3(0, 0, 0), Quaternion.identity) as GameObject; fb.transform.SetParent(building_container); List <ClipperLib.IntPoint> path = new List <ClipperLib.IntPoint>(); for (int k = 0; k < res.response[i].building.Length; k += 2) { path.Add(new ClipperLib.IntPoint(res.response[i].building[k] * prec, res.response[i].building[k + 1] * prec)); } co.AddPath(path, ClipperLib.JoinType.jtRound, ClipperLib.EndType.etClosedPolygon); List <List <ClipperLib.IntPoint> > l = new List <List <ClipperLib.IntPoint> >(); co.Execute(ref l, -smaller * prec); co.Clear(); InvisBuildingJsonRepsonse_Building ibb = new InvisBuildingJsonRepsonse_Building(); ibb.startPoint = res.response[i].startPoint; ibb.id = res.response[i].id; ibb.building = new float[l[0].Count * 2]; //ibb.building = for (int k = 0; k < l[0].Count; ++k) { ibb.building[k * 2] = l[0][k].X / prec; ibb.building[k * 2 + 1] = l[0][k].Y / prec; } fb.GetComponent <InvisBuilding>().init(res.response[i], poi_handler); all_buildings.Add(fb.GetComponent <InvisBuilding>()); } } }