Ejemplo n.º 1
0
        /// <summary>
        /// This function is called by the SearchGrid to update which cell this search object belongs to.
        /// </summary>
        public void UpdateSearchCell()
        {
            //get current position
            Vector3 currentPosition = transform.position;

            //check if its position has changed
            if (currentPosition.x != m_oLastPosition.x ||
                currentPosition.y != m_oLastPosition.y ||
                currentPosition.z != m_oLastPosition.z)
            {
                //update which cell this search object is in
                if (SearchCell != null &&
                    SearchCell.Grid != null)
                {
                    //make sure it is still in this cell
                    if (SearchCell.IsPointInCell(transform.position) == false)
                    {//it is outside the cell
                     //get the cell it is to belong in
                        SearchCell cell = SearchCell.Grid.GetCell(transform.position);

                        //make sure this cell was not returned
                        if (cell != SearchCell)
                        {
                            //remove from this cell and add to new one
                            SearchCell.Objects.Remove(this);
                            cell.Objects.Add(this);
                            SearchCell = cell;
                        }
                    }
                }

                //update last position
                m_oLastPosition = transform.position;
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// This checks if a cell is adjacent to this one.
 /// </summary>
 /// <param name="oCell">The cell to check.</param>
 public bool IsCellAdjacent(SearchCell oCell)
 {
     for (int x = 0; x < 3; x++)
     {
         for (int y = 0; y < 3; y++)
         {
             for (int z = 0; z < 3; z++)
             {
                 if (oCell == m_aoAdjacentCells[x, y, z])
                 {
                     return(true);
                 }
             }
         }
     }
     return(false);
 }