Esempio n. 1
0
    public byte      neighbors; // bitmask indicating which sides have neighbors

    public void AddNeighbor(ref SelectionTile other)
    {
        IVector3 delta = other.center - center;

        // Left-handed coordinate system means +x is to the left when +z points out of surface
        if (delta.x == -SIDE_CM && delta.y == 0)
        {
            neighbors       |= (byte)Edge.Right;
            other.neighbors |= (byte)Edge.Left;
        }
        else if (delta.x == +SIDE_CM && delta.y == 0)
        {
            neighbors       |= (byte)Edge.Left;
            other.neighbors |= (byte)Edge.Right;
        }
        else if (delta.x == 0 && delta.y == +SIDE_CM)
        {
            neighbors       |= (byte)Edge.Top;
            other.neighbors |= (byte)Edge.Bottom;
        }
        else if (delta.x == 0 && delta.y == -SIDE_CM)
        {
            neighbors       |= (byte)Edge.Bottom;
            other.neighbors |= (byte)Edge.Top;
        }
    }
 //TODO: this is really pretty terrible
 private void RemoveExcessTiles()
 {
     while (m_tiles.Count > m_maxTiles)
     {
         IVector3 position = m_tiles[0].center;
         // Remove tile 0 and unlink it from neighbors
         for (int i = 1; i < m_tiles.Count; i++)
         {
             SelectionTile tmp = m_tiles[i];
             tmp.RemoveNeighbor(position);
             m_tiles[i] = tmp;
         }
         m_tiles.RemoveAt(0);
     }
 }
    private void AddTile(IVector3 position)
    {
        SelectionTile tile = new SelectionTile(position);

        for (int i = 0; i < m_tiles.Count; i++)
        {
            if (tile.center == m_tiles[i].center)
            {
                return;
            }
            SelectionTile tmp = m_tiles[i]; // annoyingly, [] is a function call that returns a copy
            tmp.AddNeighbor(ref tile);
            m_tiles[i] = tmp;               // write back to list
        }
        m_tiles.Add(tile);
    }
Esempio n. 4
0
 /// <summary>
 /// Selects the specified tile.
 /// Raises the TileSelected event using the passed tile.
 /// </summary>
 /// <param name="tile">The tile to select.</param>
 public void SelectTile(SelectionTile tile)
 {
     OnTileSelected(new TileSelectedArgs(tile.Address));
 }
	void Awake(){
		instance = this;
	}