/// <summary> /// Returns true if a building has a sensitive usage type (e.g. it is a school), false /// otherwise. /// </summary> private bool IsSensitiveBuilding(ExtrudedStructure feature) { if (feature.Metadata.Usage == StructureMetadata.UsageType.School) { return(true); } if (feature.Metadata.Usage == StructureMetadata.UsageType.Shopping) { return(true); } return(false); }
/// <summary> /// Store a created building so it can be checked to be over a segment (after all segments are /// loaded). /// </summary> /// <param name="buildingGameObject"><see cref="GameObject"/> of building.</param> /// <param name="buildingFeature"><see cref="MapFeature"/> defining building's shape.</param> private void StoreBuilding(GameObject buildingGameObject, ExtrudedStructure buildingFeature) { // Generate a set of points to test whether they are over a segment. We start with the center // point of the building. Vector3 buildingCenter = buildingGameObject.transform.position; List <Vector3> buildingVertices = new List <Vector3> { buildingCenter }; // Get all the parts of this building, accessing the vertices making up the base of each part. // We use these vertices to generate more points to test whether the building is over a segment. // This is to avoid false negatives, where the building is over a segment, but its very center // is over a gap in the segment, resulting in the building not being considered to be over a // segment. foreach (ExtrudedArea.Extrusion extrusion in buildingFeature.Shape.Extrusions) { // Vertices in the building FootPrint are relative to FootPrint.Origin. We add this origin // to make these vertices in the local coordinates of this building's GameObject, then add // the buildings world space position to make these local coordinates into world space // coordinates, ultimately resulting in an array of world space points for all the vertices // defining the base of this building. Vector2 origin2D = extrusion.FootPrint.Origin; foreach (Vector2 vertex in extrusion.FootPrint.Vertices) { Vector2 localPosition = vertex + origin2D; // Convert from 2D x, z coordinate to 3D x, z coordinates, and add the building's position // to get the world space position of this vertex. Vector3 worldPosition = new Vector3( localPosition.x + buildingGameObject.transform.position.x, 0f, localPosition.y + buildingGameObject.transform.position.z); // Store the average of the actual world space position of this vertex, and the center of // the building. This is to avoid declaring a building as over a segment if one of its // corners is slightly over a segment, instead requiring a point towards the center of the // building be over the segment for the building to be considered as over a segment, and // removed. buildingVertices.Add(new Vector3( (worldPosition.x + buildingGameObject.transform.position.x) / 2f, 0f, (worldPosition.z + buildingGameObject.transform.position.z) / 2f)); } } // Store the GameObject and vertices of this building, so that after all geometry is loaded // we can check if any of this GameObject's vertices are over a segment. BuildingsToRaycast.AddLast(new Building { GameObject = buildingGameObject, TestPoints = buildingVertices.ToArray() }); }
/// <summary>Show a name for a newly created extruded building.</summary> /// <param name="buildingGameObject"><see cref="GameObject"/> containing created building.</param> /// <param name="buildingData"> /// <see cref="ExtrudedStructure"/> containing building's data, passed as eventArgs.MapFeature in /// <see cref="Google.Maps.Event.ExtrudedStructureEvents.DidCreate"/> event. /// </param> internal void NameExtrudedBuilding(GameObject buildingGameObject, ExtrudedStructure buildingData) { NameBuilding(buildingGameObject, buildingData.Metadata.PlaceId, buildingData.Shape.BoundingBox, buildingData.Metadata.Name); }