Exemplo n.º 1
0
 public void UpdateDestroyBlockQueueUI()
 {
     for (var i = 0; i < _blocksToDestroy.Count; i++)
     {
         int3   blockWorldPos = _blocksToDestroy[i].c0;
         int3   block         = _blocksToDestroy[i].c1;
         string text          = (i).ToString();
         if (i == 0)
         {
             text = "";
         }
         if (i < blockUIs.Count)
         {
             Vector3 pos = Utils.CenterOfBlockWithWorldPos(blockWorldPos);
             blockUIs[i].gameObject.SetActive(true);
             blockUIs[i].Setup(pos, block, text);
         }
         else
         {
             BlockUI bUI = BlockUI.Create(blockWorldPos, block, text);
             blockUIs.Add(bUI);
         }
     }
     if (blockUIs.Count > _blocksToDestroy.Count)
     {
         var remains = blockUIs.GetRange(_blocksToDestroy.Count, blockUIs.Count - _blocksToDestroy.Count);
         foreach (var r in remains)
         {
             r.gameObject.SetActive(false);
         }
     }
 }
Exemplo n.º 2
0
    public void HandlePathFindingInput(Vector3 blockCenter, int3 block)
    {
        if (!didStartPathFinding)
        {
            didStartPathFinding = true;
            Vector3 pos = Utils.CentrifyPosition(new Vector3(transform.position.x, transform.position.y + 0.5f, transform.position.z));
            currentPathFinding = new PathFinding(pos, blockCenter);
            if (isOnManualPathFinding)
            {
                var moves = currentPathFinding.OpenPossibleNewMoves(pos);
                RemoveFromBlocksUIIfExists(moves);
                foreach (var node in moves)
                {
                    var bUI = BlockUI.Create(Utils.WorldBlockPosForCenter(node.pos), int3.zero, String.Format("{0}\n{1}\n{2}", node.startValue, node.value, node.endValue));
                    blocksUI.Add(bUI);
                }
                var sbUI = BlockUI.Create(Utils.WorldBlockPosForCenter(pos), int3.zero, "Start");
                sbUI.ToggleSelection();
                blocksUI.Add(sbUI);
                var fbUI = BlockUI.Create(Utils.WorldBlockPosForCenter(blockCenter), int3.zero, "Finish");
                fbUI.ToggleSelection();
                blocksUI.Add(fbUI);
            }
            else
            {
                StartCoroutine(currentPathFinding.BuildPathToTarget(() =>
                {
                    if (currentPathFinding.isClosed)
                    {
                        foreach (var bbbUI in blocksUI)
                        {
                            GameObject.Destroy(bbbUI.gameObject);
                        }
                        foreach (var node in currentPathFinding.pathNodes)
                        {
                            var bbUI = BlockUI.Create(Utils.WorldBlockPosForCenter(node.pos), int3.zero, String.Format("{0}\n{1}\n{2}", node.startValue, node.value, node.endValue));
                            blocksUI.Add(bbUI);
                        }
                        var sbUI = BlockUI.Create(Utils.WorldBlockPosForCenter(currentPathFinding.startPos), int3.zero, "Start");
                        sbUI.ToggleSelection();
                        blocksUI.Add(sbUI);
                        var fbUI = BlockUI.Create(Utils.WorldBlockPosForCenter(currentPathFinding.endPos), int3.zero, "Finish");
                        fbUI.ToggleSelection();
                        blocksUI.Add(fbUI);
                    }
                    else
                    {
                        var poppedBottom = currentBlockDestroying.PopBottomBlock();
                        selectionController.Deselect();
                        aiState.mode = AIStateMode.Idle;
                        currentBlockDestroying.UpdateDestroyBlockQueueUI();
                    }
                }));
            }
        }
        else if (blocksUI.Find(b => b.pos.Equals(blockCenter)) != null)
        {
            var n   = currentPathFinding.SuggestNextNode();
            var bUI = blocksUI.Find(b => b.pos.Equals(n.pos));
            bUI.ToggleSelection();
            var moves = currentPathFinding.OpenPossibleNewMoves(bUI.pos, n);

            RemoveFromBlocksUIIfExists(moves);
            foreach (var node in moves)
            {
                var bbUI = BlockUI.Create(Utils.WorldBlockPosForCenter(node.pos), int3.zero, String.Format("{0}\n{1}\n{2}", node.startValue, node.value, node.endValue));
                blocksUI.Add(bbUI);
            }
            if (currentPathFinding.CheckIfEnd(n))
            {
                foreach (var bbbUI in blocksUI)
                {
                    GameObject.Destroy(bbbUI.gameObject);
                }
                foreach (var node in currentPathFinding.pathNodes)
                {
                    var bbUI = BlockUI.Create(Utils.WorldBlockPosForCenter(node.pos), int3.zero, String.Format("{0}\n{1}\n{2}", node.startValue, node.value, node.endValue));
                    blocksUI.Add(bbUI);
                }
                var sbUI = BlockUI.Create(Utils.WorldBlockPosForCenter(currentPathFinding.startPos), int3.zero, "Start");
                sbUI.ToggleSelection();
                blocksUI.Add(sbUI);
                var fbUI = BlockUI.Create(Utils.WorldBlockPosForCenter(currentPathFinding.endPos), int3.zero, "Finish");
                fbUI.ToggleSelection();
                blocksUI.Add(fbUI);
            }
        }
        else
        {
            didStartPathFinding = false;
            foreach (var bUI in blocksUI)
            {
                GameObject.Destroy(bUI.gameObject);
            }
            blocksUI = new List <BlockUI>();
        }
    }