Beispiel #1
0
    /// <summary>
    /// Starts the A* path finder which tries to find the shortest path from
    /// <c>startPosition</c> to <c>endPosition</c>. Returns immediately.
    /// </summary>
    public void Start(Vector3 startPosition, Vector3 endPosition)
    {
        if (IsRunning)
        {
            Debug.LogError("Path finder thread already running.");
            return;
        }

        // Create nodes for the start and end position
        _startNode = new AStarNode(startPosition);
        _endNode   = new AStarNode(endPosition);

        // Add start and end nodes into the visibility graph
        _visibilityGraph.Add(_startNode);
        _visibilityGraph.Add(_endNode);

        // Start searching for a path in a separate thread
        _thread = new Thread(FindPath);
        _thread.Start();

        IsRunning = true;
    }