Пример #1
0
    // Use this for initialization
    void Start()
    {
        // Initial state
        StepForward            = false;
        StepBack               = false;
        ContinueToSelectedNode = false;
        Repeat         = false;
        VisualsOn      = true;
        DisableMaze    = false;
        GenerateNewMap = false;
        sequentialA    = new PathfindingSequentialA(spawnNode, destinationNode);

        bidirectionalStart = new PathfindingBidirectionalA(spawnNode, destinationNode);
        bidirectionalGoal  = new PathfindingBidirectionalA(destinationNode, spawnNode);
        bidirectionalStart.brotherThread = bidirectionalGoal;
        bidirectionalGoal.brotherThread  = bidirectionalStart;

        InitMap();

        StartCoroutine(makeVisuals());

        if (RunSequentialAStar)
        {
            StartCoroutine(RunSequentialA());
        }
        else if (RunBidirectionalAStar)
        {
            StartCoroutine(RunBidirectionalA());
        }
    }
Пример #2
0
    void Update()
    {
        if (Input.GetMouseButtonUp(0) && (Input.mousePosition.x > UiPanel.rect.size.x || Screen.height - Input.mousePosition.y > UiPanel.rect.size.y))
        {
            selectedNode = GetNodeFromLocation(Camera.main.ScreenToWorldPoint(Input.mousePosition));
        }

        if (GenerateNewMap)
        {
            GenerateNewMap = false;

            foreach (Node node in nodes)
            {
                node.isWalkable = true;
            }

            if (!DisableMaze)
            {
                MakeWalls(0, size_x - 1, 0, size_z - 1);
            }

            destinationNode = nodes[size_x - 1, 0];
            spawnNode       = nodes[0, size_z - 1];

            destinationNode.isWalkable = true;
            spawnNode.isWalkable       = true;

            sequentialA        = new PathfindingSequentialA(spawnNode, destinationNode);
            bidirectionalStart = new PathfindingBidirectionalA(spawnNode, destinationNode);
            bidirectionalGoal  = new PathfindingBidirectionalA(destinationNode, spawnNode);
            bidirectionalStart.brotherThread = bidirectionalGoal;
            bidirectionalGoal.brotherThread  = bidirectionalStart;

            Repeat = true;
        }

        if (Repeat)
        {
            Repeat = false;

            JoinThreads();
            InitMap();

            if (RunSequentialAStar)
            {
                StartCoroutine(RunSequentialA());
            }
            else if (RunBidirectionalAStar)
            {
                StartCoroutine(RunBidirectionalA());
            }
        }
    }