public override float length(float lane) { return(Highway1.GetCurvePieceLength(lane)); }
public unsafe void CreateHighway(float lane0Length) { if (lane0Length < Highway1.MinHighwayLane0Length) { Debug.LogError("Highway length must be longer than " + Highway1.MinHighwayLane0Length); return; } int tempNumCars = GetNumCars(); if (lane0Length < highway1.innerLaneLength) { ClearCars(); } float straightPieceLength = Highway1.GetStraightPieceLength(highway1.innerLaneLength); Vector3 pos = Vector3.zero; float rot = 0; for (int i = 0; i < 8; i++) { if (i % 2 == 0) { // straight piece if (pieces[i] == null) { pieces[i] = Instantiate(straightPiecePrefab, transform).GetComponent <StraightPiece>(); } StraightPiece straightPiece = pieces[i] as StraightPiece; straightPiece.SetStartPosition(pos); straightPiece.startRotation = rot; straightPiece.SetLength(straightPieceLength); pos += straightPiece.startRotationQ * new Vector3(0, 0, straightPieceLength); } else { // curve piece if (pieces[i] == null) { pieces[i] = Instantiate(curvePiecePrefab, transform).GetComponent <CurvePiece>(); } CurvePiece curvePiece = pieces[i] as CurvePiece; curvePiece.SetStartPosition(pos); curvePiece.startRotation = rot; pos += curvePiece.startRotationQ * new Vector3(Highway1.MidRadius, 0, Highway1.MidRadius); rot = Mathf.PI / 2 * (i / 2 + 1); } } highway1.innerLaneLength = Mathf.Max(Highway1.MinHighwayLane0Length, lane0Length); if (highway1.pieces.IsCreated) { highway1.pieces.Dispose(); } highway1.pieces = new NativeArray <HighwayPiece1>(8, Allocator.Persistent); for (int i = 0; i < 8; ++i) { HighwayPiece1 piece1; piece1.startX = pieces[i].startX; piece1.startZ = pieces[i].startZ; piece1.startRotation = pieces[i].startRotation; for (int j = 0; j < 4; ++j) { piece1.length[j] = pieces[i].length(j); } highway1.pieces[i] = piece1; } SetNumCars(tempNumCars); }