public void generateNeighborLinks(OpenHeightfield field) { if( field == null ) { Logger.LogError("[OpenHeightfieldBuilder][generateNeighborLinks]field Empty"); return; } OpenHeightfield.OpenHeightFieldIterator iter = field.GetEnumerator(); while( iter.MoveNext() ) { OpenHeightSpan span = iter.Current; for(int dir = 0; dir < 4; ++dir) { //邻居的GirdIndex int nWidthIndex = (iter.widthIndex() + BoundeField.getDirOffsetWidth(dir)); int nDepthIndex = (iter.depthIndex() + BoundeField.getDirOffsetDepth(dir)); for(OpenHeightSpan nSpan = field.getData(nWidthIndex,nDepthIndex); nSpan != null; nSpan = nSpan.next()) { int maxFloor = Math.Max(span.floor(), nSpan.floor()); int minCeling = Math.Min(span.ceiling(), nSpan.ceiling()); if( (minCeling - maxFloor) >= mMinTraversableHeight //邻居之间的通道足够高,可以通过 && Math.Abs(nSpan.floor() - span.floor()) <= mMaxTraversableStep ) //两邻居之间的落差足够小 { span.setNeighbor(dir, nSpan); break; } } } } }
public bool MoveNext() { if (mOpenHeightfield == null) { Logger.LogError("[OpenHeightfield][OpenHeightFieldIterator][MoveNext]Null"); return(false); } //公有逻辑 if (mNext != null) { if (mNext.next() != null) { mNext = mNext.next(); return(true); } else { if (mIsReverseIter) { mNextWidth--; } else { mNextWidth++; } } } if (mIsReverseIter) { #region 反向遍历 for (int depthIndex = mNextDepth; depthIndex >= 0; --depthIndex) { for (int widthIndex = mNextWidth; widthIndex >= 0; --widthIndex) { OpenHeightSpan span = mOpenHeightfield.getData(widthIndex, depthIndex); if (span != null) { mNext = span; mNextWidth = widthIndex; mNextDepth = depthIndex; return(true); } } mNextWidth = 0; } mNext = null; mNextDepth = -1; mNextWidth = -1; return(false); #endregion } else { #region 正向遍历 for (int depthIndex = mNextDepth; depthIndex < mOpenHeightfield.depth(); ++depthIndex) { for (int widthIndex = mNextWidth; widthIndex < mOpenHeightfield.width(); widthIndex++) { OpenHeightSpan span = mOpenHeightfield.getData(widthIndex, depthIndex); if (span != null) { mNext = span; mNextWidth = widthIndex; mNextDepth = depthIndex; return(true); } } mNextWidth = 0; } mNext = null; mNextDepth = -1; mNextWidth = -1; return(false); #endregion } // if-else } // MoveNext