コード例 #1
0
 private void AddNodes(HexagonNode node)
 {
     if (node.X < 0)
     {
         if (node.Y < 0)
         {
             _botLeftNodes.Add(node);
         }
         else
         {
             _topLeftNodes.Add(node);
         }
     }
     else
     {
         if (node.Y < 0)
         {
             _botRightNodes.Add(node);
         }
         else
         {
             _topRightNodes.Add(node);
         }
     }
 }
コード例 #2
0
 private List <HexagonNode> GetNodesByPos(HexagonNode node)
 {
     if (node.X < 0)
     {
         if (node.Y < 0)
         {
             return(_botLeftNodes);
         }
         else
         {
             return(_topLeftNodes);
         }
     }
     else
     {
         if (node.Y < 0)
         {
             return(_botRightNodes);
         }
         else
         {
             return(_topRightNodes);
         }
     }
 }
コード例 #3
0
        private IEnumerator GenerateNodeRecursive(HexagonNode node)
        {
            yield return(new WaitForSeconds(0.075f));

            GameObjectEntity nodeEntity = Instantiate(_tileEntityPrefab);

            nodeEntity.transform.position = new Vector2(node.X, node.Y);
            AddNodes(node);

            HexagonNode curNode;

            Vector2[] adjacentNodes = node.GetAdjacentNodes(CellSize, MapSize);
            for (int i = 0; i < adjacentNodes.Length; i++)
            {
                curNode = new HexagonNode(adjacentNodes[i].x, adjacentNodes[i].y);
                if (SearchNodeByPosition(curNode))
                {
                    continue;
                }
                yield return(StartCoroutine(GenerateNodeRecursive(curNode)));
            }
        }
コード例 #4
0
 private bool SearchNodeByPosition(HexagonNode cell)
 {
     return(GetNodesByPos(cell).Contains(cell));
 }