/// <summary>
        /// Perform rescan of some area and check neighbor areas. If areas are same then concat this areas. Add resulting areas to CellTree
        /// </summary>
        /// <param name="x">x line segment of scanned area</param>
        /// <param name="y">y line segment of scanned area</param>
        /// <param name="scanAccuracy">Scan accuracy. If less then min scan accuracy return true</param>
        /// <returns>if cell is same type then return<code>true</code></returns>
        internal bool RescanArea(FloatWithSizeMath.FloatWithSize x, FloatWithSizeMath.FloatWithSize y, float scanAccuracy)
        {
            if (scanAccuracy < MinScanAccuracy)
            {
                return(true);
            }
            //var previousScanAccuracy = x.Size;
            var         size        = new Vector2(scanAccuracy, scanAccuracy);
            Vector2     lbPos       = Vector2.zero;  //left bottom position
            List <Cell> resultCells = new List <Cell>(4);
            bool        isCellsSame = true;

            for (lbPos.x = x.MinVal; lbPos.x < x.MaxVal; lbPos.x += scanAccuracy)
            {
                for (lbPos.y = y.MinVal; lbPos.y < y.MaxVal; lbPos.y += scanAccuracy)
                {
                    Cell currrentCell = scanCell(lbPos + size / 2f, size);
                    if (currrentCell == null)
                    {
                        isCellsSame = false;
                        continue;
                    }

                    if (Utils.rand.NextDouble() > 0.5)
                    {
                        isCellsSame = false;
                    }

#if UNITY_EDITOR
                    Color cellColor = Color.red;
                    if (currrentCell.Passability <= Cell.MIN_PASSABILITY)
                    {
                        cellColor = Color.black;
                    }
                    else if (currrentCell.Passability < Cell.MAX_PASSABILITY)
                    {
                        cellColor = Color.yellow;
                    }
                    else
                    {
                        cellColor = Color.white;
                    }
                    cellColor.a        = 0.5f;
                    currrentCell.Color = randomizeColor(cellColor);
#endif
                    resultCells.Add(currrentCell);
                }
            }

            if (isCellsSame)
            {
                return(true);
            }

            foreach (var resultCell in resultCells)
            {
                AddCellToTree(resultCell);
            }
            return(false);
        }
Exemple #2
0
 public void GetCellsBenchmark()
 {
     foreach (var cell in CellList)
     {
         var x = cell.Position.x;
         var y = cell.Position.y;
         FloatWithSizeMath.FloatWithSize[] aabb = new FloatWithSizeMath.FloatWithSize[]
         {
             new FloatWithSizeMath.FloatWithSize((float)x, (float)(x + Utils.rand.NextDouble() * 20f - 10f)),
             new FloatWithSizeMath.FloatWithSize((float)y, (float)(y + Utils.rand.NextDouble() * 20f - 10f)),
         };
         var result = GetCells_internal(aabb);
         Enumerate(result);
     }
 }
        //protected void ScanArea(FloatWithSizeMath.FloatWithSize x, FloatWithSizeMath.FloatWithSize y, KdTree<FloatWithSizeMath.FloatWithSize, Collider2D> hitsTree, float scanAccuracy = MinScanAccuracy * 25f, OnOperationComplete callback = null)
        /// <summary>
        /// scan area with given accuracy. If scanned cell contains some GO then perform rescan this cell with double accuracy.
        /// </summary>
        /// <param name="x">x line segment of scanned area</param>
        /// <param name="y">y line segment of scanned area</param>
        /// <param name="scanAccuracy">Scan accuracy. If less then min scan accuracy return true</param>
        /// <param name="callback"></param>
        internal void ScanArea(FloatWithSizeMath.FloatWithSize x, FloatWithSizeMath.FloatWithSize y, float scanAccuracy)
        {
            if (scanAccuracy < MinScanAccuracy)
            {
                return;
            }
            var     size  = new Vector2(scanAccuracy, scanAccuracy);
            Vector2 lbPos = Vector2.zero;            //left bottom position

            for (lbPos.x = x.MinVal; lbPos.x + scanAccuracy <= x.MaxVal; lbPos.x += scanAccuracy)
            {
                for (lbPos.y = y.MinVal; lbPos.y + scanAccuracy <= y.MaxVal; lbPos.y += scanAccuracy)
                {
                    Cell currrentCell = scanCell(lbPos + size / 2f, size);
                    if (currrentCell == null)
                    {
                        continue;
                    }
#if UNITY_EDITOR
                    Color cellColor = Color.red;
                    if (currrentCell.Passability <= Cell.MIN_PASSABILITY)
                    {
                        cellColor = Color.black;
                    }
                    else if (currrentCell.Passability < Cell.MAX_PASSABILITY)
                    {
                        cellColor = Color.yellow;
                    }
                    else
                    {
                        cellColor = Color.white;
                    }
                    cellColor.a        = 0.5f;
                    currrentCell.Color = randomizeColor(cellColor);
#endif

                    AddCellToTree(currrentCell);
                    //addNeighbours(currrentCell);
                }
            }
        }
 public Cell(FloatWithSizeMath.FloatWithSize x, FloatWithSizeMath.FloatWithSize y)
 {
     Position = new Vector2(x.MidVal, y.MidVal);
     Size     = new Vector2(x.Size, y.Size);
 }