private void UpdatePosition(Vector3 newPos)
    {
        if (filter == null)
        {
            return;
        }

        Vector3Int blockPos;
        bool       success = BlockLaser.GetBlockPositionAtMouse(newPos, out blockPos, -0.0001f);

        if (!success)
        {
            RenderNothing();
            return;
        }

        Block block;

        success = GridMap.Instance.TryGetBlock(blockPos, out block);
        if (!success)
        {
            RenderNothing();
            return;
        }

        if (!(block is AirBlock))
        {
            RenderNothing();
            return;
        }
        transform.position        = blockPos;
        this.meshRenderer.enabled = true;
    }
    void UpdateBlock(Vector3 newMousePos)
    {
        Vector3Int blockPos;
        bool       success = BlockLaser.GetBlockPositionAtMouse(newMousePos, out blockPos, -0.0001f);

        if (!success)
        {
            RenderNothing();
            return;
        }

        Block block;

        success = GridMap.Instance.TryGetBlock(blockPos, out block);
        if (!success)
        {
            RenderNothing();
            return;
        }

        if (!(block is AirBlock))
        {
            RenderNothing();
            return;
        }

        transform.position = blockPos;
        if (visualizer)
        {
            visualizer.RenderBlock(plannedBlock);
        }
    }
Пример #3
0
    void Update()
    {
        if (astarTask == null)
        {
            // foreach (GameObject g in mPathShowerObjs)
            // {
            //     g.SetActive(false);
            // }

            Vector3Int blockPos;
            bool       success = BlockLaser.GetBlockPositionAtMouse(Input.mousePosition, out blockPos);
            blockPos += new Vector3Int(0, 1, 0);
            if (success)
            {
                Vector3Int start = new Vector3Int(0, 1, 0);
                astarTask = Task.Run(() => new Astar().CalculatePath(start, blockPos));
                startBlock.SetActive(true);
                startBlock.transform.position = start;
                endBlock.SetActive(true);
                endBlock.transform.position = blockPos;
            }
        }
        else
        {
            if (astarTask.IsCompleted)
            {
                foreach (GameObject g in pathShowerObjs)
                {
                    g.SetActive(false);
                }
                Astar.Result result = astarTask.Result;
                if (result.foundPath)
                {
                    int gObjIndex = 0;
                    while (result.path.Count > 0)
                    {
                        Vector3Int step = result.path.Pop();
                        pathShowerObjs[gObjIndex].transform.position = step;
                        pathShowerObjs[gObjIndex].SetActive(true);
                        gObjIndex++;
                    }
                }
                else
                {
                    Debug.Log(result.failReason.ToString());
                }
                startBlock.SetActive(false);
                endBlock.SetActive(false);
                astarTask = null;
            }
        }
    }
Пример #4
0
    static private void ShootDeathLaser(Vector3 origin)
    {
        Vector3Int blockPosition;
        bool       success = BlockLaser.GetBlockPositionAtMouse(origin, out blockPosition);

        if (success)
        {
            Block block;
            GridMap.Instance.TryGetBlock(blockPosition, out block);
            print("Blockpos at " + blockPosition);
            if (block != null)
            {
                print("Destroyed a " + block.GetName());
                Block newBlock = new AirBlock();
                GridMap.Instance.SetBlock(blockPosition, newBlock);
            }
            else
            {
                Debug.LogError("Hit block, but no block was found at that position");
            }
        }
    }