Esempio n. 1
0
 void Start()
 {
     for (int i = m_min.x; i <= m_max.x; i++)
     {
         for (int j = m_min.y; j <= m_max.y; j++)
         {
             IntVector2   pos  = new IntVector2(i, j);
             CellRenderer cell = GameObject.Instantiate <GameObject>(m_cellPrefab).GetComponent <CellRenderer>();
             GridNode     node = new GridNode(this, pos, 0, cell);
             cell.Init(node);
             cell.transform.parent = transform;
             m_gridNodes[pos]      = node;
         }
     }
     for (int i = m_min.x; i <= m_max.x; i++)
     {
         for (int j = m_min.y; j <= m_max.y; j++)
         {
             foreach (Direction dir in Enum.GetValues(typeof(Direction)))
             {
                 IntVector2 pos       = new IntVector2(i, j);
                 IntVector2 targetPos = pos + GridLink.GetDirectionVector(dir);
                 if (m_gridNodes.ContainsKey(targetPos))
                 {
                     m_gridNodes[targetPos].SetLink(new GridLink(this, pos, targetPos, dir));
                 }
             }
         }
     }
 }