示例#1
0
    public void UpdatePath()
    {
        _closestNode = default;
        _exitNode    = default;

        if (_startRenderer != null)
        {
            _startRenderer.sharedMaterial.color = LineColor;
        }

        if (_endRenderer != null)
        {
            _endRenderer.sharedMaterial.color = LineColor;
        }

        if (GridManager != null && GridManager.Grid != null)
        {
            if (PathFinder == null)
            {
                PathFinder = new BurstAStarPathFinder(GridManager.Grid)
                {
                    Areas = Areas,
                    Grid  = GridManager.Grid,
                };
            }

            _closestNode = GridManager.Grid.FindClosestNode(StartTransform.position, AllowedFlags, 20);
            if (_closestNode.Equals(default))
    public void UpdatePath()
    {
        //Debug.Log("UpdatePath");
        _closestNode = default;
        _exitNode    = default;

        if (_gridManager != null && _gridManager.Grid != null)
        {
            if (pathFinder == null)
            {
                pathFinder = new BurstAStarPathFinder(_gridManager.Grid)
                {
                    Areas = Areas,
                    Grid  = _gridManager.Grid,
                };
            }

            _closestNode = _gridManager.Grid.FindClosestNode(transform.position, allowedFlags, areaSize);
            if (_closestNode.Equals(default))
    private void Awake()
    {
        nextPositions = new Queue <Vector3>();
        _gridManager  = GameObject.Find("GridManager").GetComponent <GridManager>();
        //_lineRenderer = gameObject.AddComponent<LineRenderer>();
        _mat  = new Material(Shader.Find("Diffuse"));
        Areas = new AreaDefinitions <NodeFlags>
        {
            { NodeFlags.Combat, 0.4f },
            { NodeFlags.Avoidance, -2f },
            { NodeFlags.NearEdge, -0.5f }
        };

        pathFinder = new BurstAStarPathFinder(_gridManager.Grid)
        {
            Areas = Areas,
            Grid  = _gridManager.Grid,
        };
    }
    public void GetPath()
    {
        if (_gridManager == null)
        {
            return;
        }

        if (pathFinder.Grid.InnerGrid.IsDisposed)
        {
            pathFinder.Grid = _gridManager.Grid;
        }

        pathFinder.Clear();
        pathFinder.AllowFlags = (ulong)allowedFlags;
        pathFinder            = pathFinder.GetPath(_closestNode, _exitNode);
        nextPositions.Clear();
        foreach (var pos in pathFinder.Path)
        {
            nextPositions.Enqueue(pos);
        }
    }