Game Development Reference
In-Depth Information
ControlPoints.Add(child.gameObject);
}
8. The ComputeDebugPath() method iterates over the waypoints array be-
fore the game starts and fills in the lineRenderer component on the
NPC. The lineRenderer component is then used to display the path if the
showPath flag is set.
1. Before the method starts, it caches the playback mode and playback
type that the user sets in the editor. We do this so that the system can
set playbackMode to ComputePath while the debugPath is calcu-
lated:
// store settings
ePlaybackMode pbm =
this.playbackMode;
ePlaybackType pbt = this.type;
2. We then loop over a preset number of samples in the lineRen-
derer component, sampling the splinePath and storing these
samples in the debugPath :
SetPlaybackMode(splineMgr.ePlaybackMode.computingDebugPath);
for (int i = 0 ; i < 1024; i++)
{
Vector3 p = getPointOnCurve();
debugPath.SetPosition(i, p);
if (IsFinished() == true)
{
debugPath.SetVertexCount(i-1);
break;
}
}
3. Once the path is calculated and the lineRenderer component
is filled with values of line segments (from the de-
bugPath.SetPosition() call earlier), we restore playbackMode
and playbacktype from the user:
Search WWH ::




Custom Search