/// <summary>
        /// Adds a extruded shape for a given <see cref="ExtrudedArea.Extrusion"/> of a given building
        /// </summary>
        /// <param name="buildingGameObject">The Maps SDK for Unity created <see cref="GameObject"/> containing this
        /// building</param>
        /// <param name="extrusionMaterial">The <see cref="Material"/> to apply to the extrusion once it is created</param>
        /// <param name="extrusion">Current <see cref="ExtrudedArea.Extrusion"/> to extrude in given building</param>
        /// <param name="crossSection">The 2D crossSection of the shape to loft along the path</param>
        /// <param name="yOffset">Amount to raise created shape vertically</param>
        /// <param name="thickness">Thickness of extrusion</param>
        /// <param name="isParapet">Whether or not desired extrusion is a parapet</param>
        /// <returns></returns>
        private IEnumerable <GameObject> AddExtrusionToBuilding(GameObject buildingGameObject, Material extrusionMaterial,
                                                                ExtrudedArea.Extrusion extrusion, IList <Vector2> crossSection, float yOffset, float thickness,
                                                                bool isParapet = false)
        {
            // Build resultant extrusions list
            var extrusionGameObjects = new List <GameObject>();
            // Build an extrusion in local space
            var loops = PadEdgeSequences(extrusion.FootPrint.GenerateBoundaryEdges());

            foreach (var sequence in loops)
            {
                // Try to make extrusion
                var extrusionGameObjectName = isParapet ? parapetName : borderName;
                var extrusionGameObject     = GenerateExtrusionGameObject(extrusionGameObjectName, extrusionMaterial,
                                                                          sequence.Vertices, crossSection, thickness);

                if (extrusionGameObject)
                {
                    // Parent extrusion to the building object
                    extrusionGameObject.transform.SetParent(buildingGameObject.transform);

                    // Align created extrusion to the building world position
                    extrusionGameObject.transform.localPosition = Vector3.up * yOffset;

                    // Add to extrusion resultant list
                    extrusionGameObjects.Add(extrusionGameObject);
                }
                else
                {
                    Debug.LogError("Not able to create extrusion for a building!");
                }
            }

            return(extrusionGameObjects);
        }
Example #2
0
    /// <summary>
    /// Adds a extruded shape for a given <see cref="ExtrudedArea.Extrusion"/> of a given building.
    /// </summary>
    /// <param name="buildingGameObject">
    /// The Maps Unity SDK created <see cref="GameObject"/> containing this building.
    /// </param>
    /// <param name="extrusionMaterial">
    /// The <see cref="Material"/> to apply to the extrusion once it is created. </param>
    /// <param name="extrusion">
    /// Current <see cref="ExtrudedArea.Extrusion"/> to extrude in given building.
    /// </param>
    /// 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>
    /// <param name="crossSection">The 2D crossSection of the shape to loft along the path.</param>
    /// <param name="yOffset">
    /// Amount to raise created shape vertically (e.g. amount to move parapet upwards so it sits at
    /// the top of a building).
    /// </param>
    /// <param name="extrusions">
    /// Reference to list used to store all extruded geometry created by this function.
    /// </param>
    /// <param name="isParapet">
    /// Whether or not desired extrusion is a parapet (used in error message if a problem occurs).
    /// </param>
    /// <param name="extrusionIndex">
    /// Index of current extrusion (used in error message if a problem occurs).
    /// </param>
    /// <param name="totalExtrusions">
    /// Total extrusions for this building (used in error message if a problem occurs).
    /// </param>
    /// <param name="thickness">Thickness of extrusion.</param>
    private static void AddBuildingExtrusion(GameObject buildingGameObject,
                                             Material extrusionMaterial, ExtrudedArea.Extrusion extrusion, Vector2[] crossSection,
                                             float yOffset, ref List <GameObject> extrusions, bool isParapet, int extrusionIndex,
                                             int totalExtrusions, float thickness)
    {
        // Build an extrusion in local space (at origin). Note that GenerateBoundaryEdges currently
        // incorrectly handles some pathological cases, for example, building chunks with a single
        // edge starting and ending outside the enclosing tile, so some very occasional misaligned
        // extrusions are to be expected.
        List <Area.EdgeSequence> loops = PadEdgeSequences(extrusion.FootPrint.GenerateBoundaryEdges());

        for (int i = 0; i < loops.Count; i++)
        {
            // Try to make extrusion.
            GameObject extrusionGameObject;
            String     objectName = isParapet ? ParapetName : BorderName;
            if (CanMakeLoft(loops[i].Vertices.ToArray(), extrusionMaterial, crossSection, thickness,
                            objectName, out extrusionGameObject))
            {
                // Parent the extrusion to the building object.
                extrusionGameObject.transform.parent = buildingGameObject.transform;

                // Move created extrusion to align with the building in world space (offset vertically if
                // required).
                extrusionGameObject.transform.localPosition = Vector3.up * yOffset;

                // Add to list of extrusions that will be returned for this building.
                extrusions.Add(extrusionGameObject);
            }
            else
            {
                // If extrusion failed for any reason, print an error to this effect.
                Debug.LogErrorFormat("{0} class was not able to create a {1} for building \"{2}\", "
                                     + "parent \"{3}\", extrusion {4} of {5}, loop {6} of {7}.\nFailure was caused by "
                                     + "there being not enough vertices to make a {0}.",
                                     typeof(Extruder), isParapet ? ParapetName : BorderName, buildingGameObject.name,
                                     buildingGameObject.transform.parent.name, extrusionIndex + 1, totalExtrusions, i + 1,
                                     loops.Count);
            }
        }
    }