コード例 #1
0
    public List <Vector3> UpdatePath(Vector3 from, Vector3 to, Action <List <Vector3> > onPathUpdated = null)
    {
        if (_map == null)
        {
            return(null);
        }

        int targetX = Mathf.RoundToInt(to.x);
        int targetY = Mathf.RoundToInt(to.z);

        if (MazeHelper.IsWall(_map, targetX, targetY))
        {
            return(null);
        }

        int fromX = Mathf.RoundToInt(from.x);
        int fromY = Mathf.RoundToInt(from.z);

        if (MazeHelper.IsWall(_map, fromX, fromY))
        {
            return(null);
        }

        var path = GetPath(fromX, fromY, targetX, targetY);

        if (path != null & path.Count > 0)
        {
            onPathUpdated?.Invoke(path);
        }

        return(path);
    }