Exemple #1
0
 public void Draw()
 {
     foreach (Cell cell in cells)
     {
         LineDrawer.DrawSquare(cell.bounds.min, cell.bounds.max, Color.cyan);
     }
 }
Exemple #2
0
        private int TagNeighboursPartitioned(float inRange)
        {
            Bounds expanded = new Bounds();

            expanded.min = new Vector3(transform.position.x - inRange, 0, transform.position.z - inRange);
            expanded.max = new Vector3(transform.position.x + inRange, 0, transform.position.z + inRange);

            if (drawNeighbours && Params.drawDebugLines)
            {
                LineDrawer.DrawSquare(expanded.min, expanded.max, Color.yellow);
            }

            List <Cell> cells = SteeringManager.Instance.space.cells;

            tagged.Clear();
            int myCellIndex = SteeringManager.Instance.space.FindCell(transform.position);

            if (myCellIndex == -1)
            {
                // Im outside the cells so return
                return(0);
            }
            Cell myCell = SteeringManager.Instance.space.cells[myCellIndex];

            foreach (Cell cell in myCell.adjacent)
            {
                if (cell.Intersects(expanded))
                {
                    if (drawNeighbours && Params.drawDebugLines)
                    {
                        LineDrawer.DrawSquare(cell.bounds.min, cell.bounds.max, Color.magenta);
                    }
                    List <GameObject> entities     = cell.contained;
                    float             rangeSquared = inRange * inRange;
                    foreach (GameObject neighbour in entities)
                    {
                        if (neighbour != gameObject)
                        {
                            if (drawNeighbours && Params.drawDebugLines)
                            {
                                LineDrawer.DrawLine(transform.position, neighbour.transform.position, Color.yellow);
                            }

                            if (Vector3.SqrMagnitude(transform.position - neighbour.transform.position) < rangeSquared)
                            {
                                tagged.Add(neighbour);
                            }
                        }
                    }
                }
            }

            DrawNeighbours(Color.white);

            return(this.tagged.Count);
        }