예제 #1
0
        private static void ComputePortal(Vector3 startPos, Vector3 endPos, PathGrid grid, out Vector3 leftPoint, out Vector3 rightPoint)
        {
            leftPoint  = Vector3.zero;
            rightPoint = Vector3.zero;

            int startCellIndex = grid.GetCellIndex(startPos);
            int endCellIndex   = grid.GetCellIndex(endPos);

            Bounds startCellBounds = grid.GetCellBounds(startCellIndex);

            PathGrid.eNeighborDirection neighborDirection = grid.GetNeighborDirection(startCellIndex, endCellIndex);
            float thirdValue = ConvertUtils.ThirdValue(grid.Origin);

            switch (neighborDirection)
            {
            case PathGrid.eNeighborDirection.kTop:
                leftPoint = ConvertUtils.PosByHV(ConvertUtils.HorizontalValue(startCellBounds.min),
                                                 ConvertUtils.VerticalValue(startCellBounds.max),
                                                 thirdValue);                //new Vector3(startCellBounds.min.x, grid.Origin.y, startCellBounds.max.z);
                rightPoint = ConvertUtils.PosByHV(ConvertUtils.HorizontalValue(startCellBounds.max),
                                                  ConvertUtils.VerticalValue(startCellBounds.max),
                                                  thirdValue);               //new Vector3(startCellBounds.max.x, grid.Origin.y, startCellBounds.max. z);
                break;

            case PathGrid.eNeighborDirection.kRight:
                leftPoint = ConvertUtils.PosByHV(ConvertUtils.HorizontalValue(startCellBounds.max),
                                                 ConvertUtils.VerticalValue(startCellBounds.max),
                                                 thirdValue);                //new Vector3(startCellBounds.max.x, grid.Origin.y, startCellBounds.max. z);
                rightPoint = ConvertUtils.PosByHV(ConvertUtils.HorizontalValue(startCellBounds.max),
                                                  ConvertUtils.VerticalValue(startCellBounds.min),
                                                  thirdValue);                //new Vector3(startCellBounds.max.x, grid.Origin.y, startCellBounds.min. z);
                break;

            case PathGrid.eNeighborDirection.kBottom:
                leftPoint = ConvertUtils.PosByHV(ConvertUtils.HorizontalValue(startCellBounds.max),
                                                 ConvertUtils.VerticalValue(startCellBounds.min),
                                                 thirdValue);                //new Vector3(startCellBounds.max.x, grid.Origin.y, startCellBounds.min. z);
                rightPoint = ConvertUtils.PosByHV(ConvertUtils.HorizontalValue(startCellBounds.min),
                                                  ConvertUtils.VerticalValue(startCellBounds.min),
                                                  thirdValue);                //new Vector3(startCellBounds.min.x, grid.Origin.y, startCellBounds.min. z);
                break;

            case PathGrid.eNeighborDirection.kLeft:
                leftPoint = ConvertUtils.PosByHV(ConvertUtils.HorizontalValue(startCellBounds.min),
                                                 ConvertUtils.VerticalValue(startCellBounds.min),
                                                 thirdValue);                //new Vector3(startCellBounds.min.x, grid.Origin.y, startCellBounds.min. z);
                rightPoint = ConvertUtils.PosByHV(ConvertUtils.HorizontalValue(startCellBounds.min),
                                                  ConvertUtils.VerticalValue(startCellBounds.max),
                                                  thirdValue);                //new Vector3(startCellBounds.min.x, grid.Origin.y, startCellBounds.max. z);
                break;

            default:
                UnityEngine.Debug.LogError("ComputePortal failed to find a neighbor");
                break;
            }
            ;
        }
예제 #2
0
    public static List <Vector3> PositionsByDirection(int gridIndex, int length, PathGrid.eNeighborDirection dirction, PathGrid grid)
    {
        //	UnityEngine.Debug.Log("Origin PosIndex:" + gridIndex);
        List <Vector3> Positions = new List <Vector3>();

        for (int i = 0; i < length; i++)
        {
            gridIndex = grid.GetNeighbor(gridIndex, dirction);
            if (grid.IsBlocked(gridIndex))
            {
                return(Positions);
            }
            Positions.Add(grid.GetPathNodePos(gridIndex));
            //	UnityEngine.Debug.Log("Search PosIndex:" + gridIndex);
        }
        return(Positions);
    }
예제 #3
0
        private static void ComputePortal(Vector3 startPos, Vector3 endPos, PathGrid grid, out Vector3 leftPoint, out Vector3 rightPoint)
        {
            leftPoint  = Vector3.zero;
            rightPoint = Vector3.zero;

            int startCellIndex = grid.GetCellIndex(startPos);
            int endCellIndex   = grid.GetCellIndex(endPos);

            Bounds startCellBounds = grid.GetCellBounds(startCellIndex);

            PathGrid.eNeighborDirection neighborDirection = grid.GetNeighborDirection(startCellIndex, endCellIndex);
            switch (neighborDirection)
            {
            case PathGrid.eNeighborDirection.kTop:
                leftPoint  = new Vector3(startCellBounds.min.x, grid.Origin.y, startCellBounds.max.z);
                rightPoint = new Vector3(startCellBounds.max.x, grid.Origin.y, startCellBounds.max.z);
                break;

            case PathGrid.eNeighborDirection.kRight:
                leftPoint  = new Vector3(startCellBounds.max.x, grid.Origin.y, startCellBounds.max.z);
                rightPoint = new Vector3(startCellBounds.max.x, grid.Origin.y, startCellBounds.min.z);
                break;

            case PathGrid.eNeighborDirection.kBottom:
                leftPoint  = new Vector3(startCellBounds.max.x, grid.Origin.y, startCellBounds.min.z);
                rightPoint = new Vector3(startCellBounds.min.x, grid.Origin.y, startCellBounds.min.z);
                break;

            case PathGrid.eNeighborDirection.kLeft:
                leftPoint  = new Vector3(startCellBounds.min.x, grid.Origin.y, startCellBounds.min.z);
                rightPoint = new Vector3(startCellBounds.min.x, grid.Origin.y, startCellBounds.max.z);
                break;

            default:
                UnityEngine.Debug.LogError("ComputePortal failed to find a neighbor");
                break;
            }
            ;
        }