Пример #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
        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;
            }
            ;
        }
Пример #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;
			};
		}