Example #1
0
        /// <summary>
        /// Gets the neighbour grid component to a given position in the given direction, if one exists.
        /// The predefined directions on the <see cref="DirectionVector"/> can be combined for more combinations.
        /// </summary>
        /// <param name="mgr">The grid manager.</param>
        /// <param name="position">The position.</param>
        /// <param name="direction">The direction.</param>
        /// <returns>The neighbouring grid, or null if no neighbour exists</returns>
        public static GridComponent GetNeighbourGrid(this IGridManager mgr, Vector3 position, DirectionVector direction)
        {
            var g = mgr.GetGridComponent(position);

            var bounds = g.bounds;
            var pos    = bounds.center + ((bounds.extents + Vector3.one) * direction);

            return(mgr.GetGridComponent(pos));
        }