示例#1
0
        /// <summary>
        /// Returns the cell range for a hexagon
        /// </summary>
        /// <param name="origin"></param>
        /// <param name="n"></param>
        /// <param name="predicate"></param>
        /// <returns></returns>
        public static Dictionary <Vector3Int, float> GetRangeHexOffset(Vector3Int origin, int n, Predicate <Vector3Int> predicate = null)
        {
            GridSearch.RangeSearch search
                = new GridSearch.RangeSearch()
                {
                debug               = false,
                distanceFunction    = HexOffsetDistance,
                neighborFunction    = FindNeighboringCellsHexOffset,
                traversableFunction = predicate,
                range               = n,
                startElement        = origin
                };
            var result = search.SearchWithCosts();

            return(result);

            //List<Vector3Int> result = new List<Vector3Int>();
            //Vector3Int originc = OffsetToCube(origin);

            //for(int x = -n; x <= n; ++x)
            //{
            //    for(int y = Math.Max(- n, -x-n); y <= Math.Min(n, -x+n); ++y)
            //    {
            //        int z = -x - y;
            //        Vector3Int cellC = originc + new Vector3Int(x, y, z);
            //        Vector3Int cell = CubeToOffset(cellC);
            //        if (predicate == null || predicate(cell))
            //        {
            //            result.Add(cell);
            //        }
            //    }
            //}

            //return result.ToArray();
        }
示例#2
0
 /// <summary>
 /// Returns the cell range given an origin and a range
 /// </summary>
 /// <param name="origin"></param>
 /// <param name="n"></param>
 /// <param name="predicate"></param>
 /// <returns></returns>
 public static Dictionary <Vector3Int, float> GetRangeRectangle(Vector3Int origin, int n, Predicate <Vector3Int> predicate = null)
 {
     GridSearch.RangeSearch search
         = new GridSearch.RangeSearch()
         {
         debug               = false,
         distanceFunction    = ManhattanDistance,
         neighborFunction    = FindNeighboringCellsRectangle,
         traversableFunction = predicate,
         range               = n,
         startElement        = origin
         };
     return(search.SearchWithCosts());
 }