Example #1
0
 public void InitBoard()
 {
     ActiveNodes = new ANode[boardSize.x, boardSize.y];
     for (int i = 0; i < boardSize.x; i++)
     {
         for (int j = 0; j < boardSize.y; j++)
         {
             SpawnNode(i, j, (NodeType)Random.Range(0, System.Enum.GetNames(typeof(NodeType)).Length));
         }
     }
 }
Example #2
0
 //Check if there is another under current node if true move current node to under
 async Task UpdateBoardPositionAsync(bool isAsync = true)
 {
     //form left bottom
     for (int j = boardSize.y - 2; j >= 0; j--)
     {
         for (int i = 0; i < boardSize.x; i++)
         {
             var node = ActiveNodes[i, j];
             // if node is disable do nothing
             if (!node.IsActive)
             {
                 continue;
             }
             ANode underNode = null;
             int   nextY     = j;
             //Try to find the next node
             while (underNode == null)
             {
                 nextY++;
                 // if next one is out of board break the loop
                 if (nextY >= boardSize.y)
                 {
                     break;
                 }
                 var tmpNextNode = ActiveNodes[i, nextY];
                 // if nextNode is the bottom row and is deactive add it
                 if (nextY == boardSize.y - 1 && !tmpNextNode.IsActive)
                 {
                     underNode = tmpNextNode;
                 }
                 //if next node is active and above the next node is deactive add it
                 if (tmpNextNode.IsActive && !ActiveNodes[i, nextY - 1].IsActive)
                 {
                     underNode = ActiveNodes[i, nextY - 1];
                 }
             }
             if (underNode != null)
             {
                 if (isAsync)
                 {
                     //Caculate the distance
                     var vel = (node.RectTransform.position.y - underNode.RectTransform.position.y) / nodeFallenTime;
                     while (node.RectTransform.position.y > underNode.RectTransform.position.y)
                     {
                         var newPos = node.RectTransform.position - new Vector3(0f, vel * Time.deltaTime, 0f);
                         node.RectTransform.position = newPos;
                         await Task.Delay((int)(Time.deltaTime * 1000f));
                     }
                 }
                 Swap(node.Point, underNode.Point);
             }
         }
     }
 }
Example #3
0
 void HandleNodeDragEnd(OnNodeDragEnd e) => currentNode = null;
Example #4
0
 void HandleNodeDragBegin(OnNodeDragBegin e) => currentNode = e.Node;
 public OnNodeDragEnd(ANode node) => Node = node;
 public OnNodeDragBegin(ANode node) => Node = node;