Esempio n. 1
0
    public void AddNeighbour(NavCubeNode current, Vector3Int end, Vector3Int dir, float cost, NavCubeType searchType, NavCubeAgent agent)
    {
        Vector3Int pos = current.position + dir;

        NavCubeChunk.NavCubeData data = GetData(pos);

        if (agent != null)
        {
            for (int i = 0; i < agent.height; i++)
            {
                int ii = i - agent.offset;
                if (GetData(pos + Vector3Int.up * ii).type == NavCubeType.Blocked)
                {
                    return;
                }
            }
        }
        else
        {
            if (data.type == NavCubeType.Blocked)
            {
                return;
            }
        }


        float       heuristic = pos.Manhattan(end);
        NavCubeNode ncn       = new NavCubeNode(pos, current.cost + data.cost * cost, heuristic, current);

        if (closedList.Contains(ncn))
        {
            return;
        }
        if (openList.Contains(ncn))
        {
            NavCubeNode ol_ncn = openList.Find(x => x.position.Equals(pos));
            if (ol_ncn.total > ncn.total)
            {
                ol_ncn.cost      = ncn.cost;
                ol_ncn.heuristic = ncn.heuristic;
                ol_ncn.parent    = ncn.parent;
            }
            return;
        }

        if (searchType == NavCubeType.Walking)
        {
            if (data.type == NavCubeType.Walking)
            {
                openList.Add(ncn);
            }
        }
        else
        {
            openList.Add(ncn);
        }
    }
Esempio n. 2
0
    public static int Manhattan(this Vector3Int A, Vector3Int B)
    {
        Vector3Int vec = B - A;

        return(vec.Manhattan());
    }