Пример #1
0
        /// <summary>
        /// Finds all <see cref="PolygonCollider2D"/>s in <paramref name="objectContainingObstacles"/> (and its children)
        /// and creates corresponding 3D colliders.
        /// If a <see cref="PolygonCollider2D"/> instance is found but "usedByComposite" is set to true, the collider will be ignored by this function.
        /// </summary>
        /// <param name="objectContainingObstacles">Object to search for colliders in.</param>
        /// <param name="parentToAttachTemporaryObjectsTo">Object which will be made the parent of the created 3D colliders.</param>
        /// <returns></returns>
        private static IEnumerable <GameObject> ProcessPolygonColliders(GameObject objectContainingObstacles, Transform parentToAttachTemporaryObjectsTo)
        {
            var createdGameObjects = new List <GameObject>();
            var polyColliders      = objectContainingObstacles.GetComponentsInChildren <PolygonCollider2D>();

            foreach (var col in polyColliders)
            {
                if (!col.usedByComposite)
                {
                    createdGameObjects.Add(MeshFromPolygonCreator.CreateMesh(col.points, col.transform, parentToAttachTemporaryObjectsTo));
                }
            }

            return(createdGameObjects);
        }
Пример #2
0
        /// <summary>
        /// Finds all <see cref="CompositeCollider2D"/>s in <paramref name="objectContainingObstacles"/> (and its children)
        /// and creates corresponding 3D colliders.
        /// </summary>
        /// <param name="objectContainingObstacles">Object to search for colliders in.</param>
        /// <param name="parentToAttachTemporaryObjectsTo">Object which will be made the parent of the created 3D colliders.</param>
        /// <returns></returns>
        private static IEnumerable <GameObject> ProcessCompositeColliders(GameObject objectContainingObstacles, Transform parentToAttachTemporaryObjectsTo)
        {
            var createdGameObjects = new List <GameObject>();
            var compositeColliders = objectContainingObstacles.GetComponentsInChildren <CompositeCollider2D>();

            foreach (var col in compositeColliders)
            {
                for (var i = 0; i < col.pathCount; i++)
                {
                    var pathNodes = new Vector2[col.GetPathPointCount(i)];
                    col.GetPath(i, pathNodes);
                    createdGameObjects.Add(MeshFromPolygonCreator.CreateMesh(pathNodes, col.transform, parentToAttachTemporaryObjectsTo));
                }
            }

            return(createdGameObjects);
        }