private void UpdatePotentialTracks() { potentialTracks.Clear(); var num = 1f; while (true) { foreach (var allTrack in TrackFinder.AllTracks) { if (RailTrack.GetPointWithinRangeWithYOffset(allTrack, transform.position, num * 200f) .HasValue) { potentialTracks.Add(allTrack); } } if (potentialTracks.Count <= 0 && num <= 4.0) { Debug.LogWarning( string.Format("No tracks in {0} radius. Expanding radius!", (float)(num * 200.0)), this); num += 0.2f; } else { break; } } if (potentialTracks.Count != 0) { return; } Debug.LogError("No near tracks found. Can't spawn crew vehicle"); }
public void OnUpdate() { if (potentialTracks.Count == 0 || (uint)(state - 1) > 1U) { return; } if (Physics.Raycast(signalOrigin.position, signalOrigin.forward, out hit, 100f, trackMask)) { var point = hit.point; foreach (var potentialTrack in potentialTracks) { var rangeWithYoffset = RailTrack.GetPointWithinRangeWithYOffset(potentialTrack, point, 3f, -1.75f); if (rangeWithYoffset.HasValue) { destinationTrack = potentialTrack; var startingFromIndex = CarSpawner.FindClosestValidPointForCarStartingFromIndex( potentialTrack.GetPointSet().points, rangeWithYoffset.Value.index, carBounds.extents); var hasValue = startingFromIndex.HasValue; closestPointOnDestinationTrack = !hasValue ? rangeWithYoffset : startingFromIndex; canSpawnAtPoint = hasValue; var position = (Vector3)closestPointOnDestinationTrack.Value.position + WorldMover.currentMove; var forward = closestPointOnDestinationTrack.Value.forward; if (!spawnWithTrackDirection) { forward *= -1f; } destHighlighter.Highlight(position, forward, carBounds, canSpawnAtPoint ? validMaterial : invalidMaterial); display.SetAction(canSpawnAtPoint ? "confirm" : "cancel"); if (canSpawnAtPoint && state == State.PickDestination) { UpdateLCDRerailDirectionArrow(); return; } lcdArrow.TurnOff(); return; } } } canSpawnAtPoint = false; destinationTrack = null; destHighlighter.Highlight(signalOrigin.position + signalOrigin.forward * 20f, signalOrigin.right, carBounds, invalidMaterial); display.SetAction("cancel"); lcdArrow.TurnOff(); }