/// <summary> /// Adds a parapet of a specifically chosen cross-section to the given building. /// </summary> /// <param name="buildingGameObject"> /// The Maps Unity SDK created <see cref="GameObject"/> containing this building. /// </param> /// <param name="buildingShape"> /// The Maps Unity SDK <see cref="MapFeature"/> data defining this building's shape and height. /// </param> /// <param name="parapetMaterial"> /// The <see cref="Material"/> to apply to the parapet once it is created. /// </param> /// <param name="parapetType"> /// Optional index of parapet to cross-section to use. Will use a randomly chosen cross-section if /// no index given, or if given index is invalid (in which case an error will also be printed). /// </param> /// <param name="defaultBuildingHeight"> /// Default height applied to Maps Unity SDK generated buildings that do not have stored height /// information. If left blank, a value of 10f matches the default value used inside the Maps /// Unity SDK for buildings without stored heights. /// <para> /// The Maps Unity SDK default height can be overriden with styling options, specifically /// <see cref="GameObjectOptions.ExtrudedStructureStyle"/>'s ExtrudedBuildingFootprintHeight. If /// this default height is overriden when calling <see cref="MapsService.LoadMap"/>, then this new /// default height value should also be used here to make sure that building parapets appear at /// the roof-level of all buildings, even if these buildings don't have a stored height. /// </para></param> /// <returns> /// Newly created <see cref="GameObject"/>s containing created parapet geometry. /// <para> /// One <see cref="GameObject"/> will be returned for each part of the given building. /// </para></returns> public static GameObject[] AddBuildingParapet(GameObject buildingGameObject, ExtrudedArea buildingShape, Material parapetMaterial, int parapetType, float defaultBuildingHeight = ExtrudedBuildingFootprintHeight) { return(AddBuildingParapet(buildingGameObject, buildingShape, parapetMaterial, defaultBuildingHeight, parapetType)); }
/// <summary>Updates the parapet decoration on a building.</summary> /// <remarks> /// This method removes any existing parapet decoration and builds a new parapet child object in /// the same manner as the <see cref="AddRandomBuildingParapet"/> method. No attempt is made to /// retain the same parapet type. In a more sophisticated implementation, the assigned parapet /// type would be stored on the building GameObject to be retrieved here. /// </remarks> /// <param name="buildingGameObject"> /// The Maps Unity SDK created <see cref="GameObject"/> containing this building. /// </param> /// <param name="buildingShape"> /// The Maps Unity SDK <see cref="MapFeature"/> data defining this building's shape and height. /// </param> /// <param name="parapetMaterial"> /// The <see cref="Material"/> to apply to the parapet once it is created. /// </param> /// <param name="defaultBuildingHeight"> /// Default height applied to Maps Unity SDK generated buildings that do not have stored height /// information. If left blank, a value of 10f matches the default value used inside the Maps /// Unity SDK for buildings without stored heights. /// </param> /// <returns> /// Newly created <see cref="GameObject"/>s containing created parapet geometry. /// <para> /// One <see cref="GameObject"/> will be returned for each part of the given building. /// </para></returns> public static GameObject[] UpdateBuildingParapet(GameObject buildingGameObject, ExtrudedArea buildingShape, Material parapetMaterial, float defaultBuildingHeight = ExtrudedBuildingFootprintHeight) { RemoveCurrentParapet(buildingGameObject); return(AddRandomBuildingParapet( buildingGameObject, buildingShape, parapetMaterial, defaultBuildingHeight)); }
/// <summary> /// Adds a parapet of a randomly chosen cross-section to the given building. /// </summary> /// <param name="buildingGameObject"> /// The Maps Unity SDK created <see cref="GameObject"/> containing this building. /// </param> /// <param name="buildingShape"> /// The Maps Unity SDK <see cref="MapFeature"/> data defining this building's shape and height. /// </param> /// <param name="parapetMaterial"> /// The <see cref="Material"/> to apply to the parapet once it is created. /// </param> /// <param name="defaultBuildingHeight"> /// Default height applied to Maps Unity SDK generated buildings that do not have stored height /// information. If left blank, a value of 10f matches the default value used inside the Maps /// Unity SDK for buildings without stored heights. /// <para> /// The Maps Unity SDK default height can be overriden with styling options, specifically /// <see cref="GameObjectOptions.ExtrudedStructureStyle"/>'s ExtrudedBuildingFootprintHeight. If /// this default height is overriden when calling <see cref="MapsService.LoadMap"/>, then this new /// default height value should also be used here to make sure that building parapets appear at /// the roof-level of all buildings, even if these buildings don't have a stored height. /// </para></param> /// <param name="parapetType"> /// Optional index of parapet to cross-section to use. Will use a randomly chosen cross-section if /// no index given, or if given index is invalid (in which case an error will also be printed). /// </param> /// <returns> /// Newly created <see cref="GameObject"/>s containing created parapet geometry. /// <para> /// One <see cref="GameObject"/> will be returned for each part of the given building. /// </para></returns> private static GameObject[] AddBuildingParapet(GameObject buildingGameObject, ExtrudedArea buildingShape, Material parapetMaterial, float defaultBuildingHeight, int?parapetType) { // Create list to store all created parapets. List <GameObject> extrudedParapets = new List <GameObject>(); for (int i = 0; i < buildingShape.Extrusions.Length; i++) { // Use ExtrudedBuildingFootPrintHeight constant for buildings that don't have any specified // height. The Maps Unity SDK currently generates geometry using the default height, but does // not modify the actual MapFeature data passed to the callback. This may be addressed in // future Maps Unity SDK releases. float height = buildingShape.Extrusions[i].MaxZ > 0.1f ? buildingShape.Extrusions[i].MaxZ : defaultBuildingHeight; // If a specific parapet type was given, verify it is valid. if (parapetType.HasValue) { if (parapetType.Value < 0 || parapetType.Value >= ParapetShapes.Length) { int invalidParapetType = parapetType.Value; parapetType = Random.Range(0, ParapetShapes.Length); Debug.LogErrorFormat("{0} parapetType index given to {1}.AddBuildingParapet.\nValid " + "indices are in the range of 0 to {2} based on {3} cross-sections defined in {1}" + "class.\nDefaulting to randomly chosen parapetType index of {4}.", invalidParapetType < 0 ? "Negative" : "Invalid", typeof(Extruder), ParapetShapes.Length - 1, ParapetShapes.Length, parapetType.Value); } } else { // If no parapet type given, choose one at random. parapetType = Random.Range(0, ParapetShapes.Length); } // Use general-purpose building-extrusion function to add parapet around building. Do this // with a randomly chosen parapet shape for more variation throughout all created building // parapets. AddBuildingExtrusion(buildingGameObject, parapetMaterial, buildingShape.Extrusions[i], ParapetShapes[parapetType.Value], height, ref extrudedParapets, true, i, buildingShape.Extrusions.Length, DefaultWidth); } // Return all created parapets. return(extrudedParapets.ToArray()); }
/// <summary>Adds a extruded border around the base of a given building.</summary> /// <param name="buildingGameObject"> /// The Maps Unity SDK created <see cref="GameObject"/> containing this building. /// </param> /// <param name="buildingShape"> /// The Maps Unity SDK <see cref="MapFeature"/> data defining this building's shape and height. /// </param> /// <param name="borderMaterial"> /// The <see cref="Material"/> to apply to the extrusion once it is created. /// </param> /// <returns> /// Newly created <see cref="GameObject"/>s containing created extrusion geometry. /// <para> /// One <see cref="GameObject"/> will be returned for each part of the given building. /// </para></returns> public static GameObject[] AddBuildingBorder(GameObject buildingGameObject, ExtrudedArea buildingShape, Material borderMaterial, float thickness = DefaultWidth) { // Create list to store all created borders. List <GameObject> extrudedBorders = new List <GameObject>(); for (int i = 0; i < buildingShape.Extrusions.Length; i++) { // Use general-purpose building-extrusion function to add border around building. AddBuildingExtrusion(buildingGameObject, borderMaterial, buildingShape.Extrusions[i], BorderShape, 0f, ref extrudedBorders, false, i, buildingShape.Extrusions.Length, thickness); } // Return all created extrusions. return(extrudedBorders.ToArray()); }
/// <summary> /// Adds a extruded border around the base of a given building /// </summary> /// <param name="buildingGameObject">The Maps SDK for Unity created <see cref="GameObject"/> containing this /// building</param> /// <param name="buildingShape">The Maps SDK for Unity <see cref="MapFeature"/> data defining this building's /// shape and height</param> /// <param name="borderMaterial">The <see cref="Material"/> to apply to the extrusion once it is created</param> /// <param name="thickness">Thickness of extrusion</param> /// <param name="yOffset">Amount to raise created shape vertically</param> /// <returns></returns> public List <GameObject> AddBuildingBorder(GameObject buildingGameObject, ExtrudedArea buildingShape, Material borderMaterial, float?thickness = null, float?yOffset = null) { // Create list to store all created borders var extrudedBorders = new List <GameObject>(); var resultThickness = thickness ?? defaultThickness; var resultYOffset = yOffset ?? 0; // Use general-purpose building-extrusion function to add border around building foreach (var extrusion in buildingShape.Extrusions) { var extrusions = AddExtrusionToBuilding(buildingGameObject, borderMaterial, extrusion, BorderShape, resultYOffset, resultThickness); extrudedBorders.AddRange(extrusions); } return(extrudedBorders); }
/// <summary> /// Adds a parapet of a randomly chosen cross-section to the given building /// </summary> /// <param name="buildingGameObject">The Maps SDK for Unity created <see cref="GameObject"/> containing this /// building</param> /// <param name="buildingShape">The Maps SDK for Unity <see cref="MapFeature"/> data defining this building's /// shape and height</param> /// <param name="parapetMaterial">The <see cref="Material"/> to apply to the parapet once it is created</param> /// <param name="parapetType">Optional index of parapet to cross-section to use. Will use a randomly chosen /// cross-section if no index given, or if given index is invalid</param> /// <returns></returns> public List <GameObject> AddBuildingParapet(GameObject buildingGameObject, ExtrudedArea buildingShape, Material parapetMaterial, int?parapetType = null) { // Create list to store all created parapets var extrudedParapets = new List <GameObject>(); foreach (var extrusion in buildingShape.Extrusions) { var height = extrusion.MaxZ > 0.1f ? extrusion.MaxZ : defaultBuildingHeight; var resultParapetType = parapetType >= 0 && parapetType.Value < ParapetShapes.Length ? parapetType.Value : Random.Range(0, ParapetShapes.Length); var extrusions = AddExtrusionToBuilding(buildingGameObject, parapetMaterial, extrusion, ParapetShapes[resultParapetType], height, defaultThickness, true); extrudedParapets.AddRange(extrusions); } return(extrudedParapets); }