Пример #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
	void Awake()
	{
		m_pathTerrain = new PathGrid();
		
#if (!UNITY_IPHONE && !UNITY_ANDROID)
		HeightmapComponent_UnityTerrain heightmapComponent = GetComponent<HeightmapComponent_UnityTerrain>();
		PathGrid.Awake(transform.position, m_numberOfRows, m_numberOfColumns, m_cellSize, m_debugShow, heightmapComponent);
#else
		PathGrid.Awake(transform.position, m_numberOfRows, m_numberOfColumns, m_cellSize, m_debugShow, null);
#endif
	}
	// Use this for initialization
	void Start () 
	{
		if ( m_navigationAgent.PathTerrain == null || !(m_navigationAgent.PathTerrain is PathGrid) )
		{
			Debug.LogError("Interaction_Wander was built to work with a PathGrid terrain; can't use it on other terrain types.");
		}
		else
		{
			m_pathGrid = m_navigationAgent.PathTerrain as PathGrid;
		}
	}
Пример #4
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;
            }
            ;
        }
Пример #5
0
        public static void ComputePortals(Vector3[] roughPath, PathGrid grid, out Vector3[] aLeftEndPts, out Vector3[] aRightEndPts)
        {
            aLeftEndPts  = null;
            aRightEndPts = null;

            if (roughPath.Length < 2)
            {
                return;
            }

            aLeftEndPts  = new Vector3[roughPath.Length - 1];
            aRightEndPts = new Vector3[roughPath.Length - 1];

            for (int i = 0; i < roughPath.Length - 1; i++)
            {
                Vector3 currentPos = roughPath[i];
                Vector3 nextPos = roughPath[i + 1];
                Vector3 leftPoint, rightPoint;
                ComputePortal(currentPos, nextPos, grid, out leftPoint, out rightPoint);
                aLeftEndPts[i]  = leftPoint;
                aRightEndPts[i] = rightPoint;
            }
        }
Пример #6
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;
			};
		}
Пример #7
0
		public static void ComputePortals(Vector3[] roughPath, PathGrid grid, out Vector3[] aLeftEndPts, out Vector3[] aRightEndPts)
		{
			aLeftEndPts = null;
			aRightEndPts = null;
			
			if ( roughPath.Length < 2 )
			{
				return;
			}
			
			aLeftEndPts = new Vector3[roughPath.Length-1];
			aRightEndPts = new Vector3[roughPath.Length-1];
			
			for ( int i = 0; i < roughPath.Length - 1; i++ )
			{
				Vector3 currentPos = roughPath[i];
				Vector3 nextPos = roughPath[i+1];
				Vector3 leftPoint, rightPoint;
				ComputePortal(currentPos, nextPos, grid, out leftPoint, out rightPoint);
				aLeftEndPts[i] = leftPoint;
				aRightEndPts[i] = rightPoint;
			}
		}