protected virtual void OnEnable() { if (Collider) { Radar2D.AddDetectableObject2D(this); } }
protected virtual void OnDisable() { if (Collider) { Radar2D.RemoveDetectableObject2D(this); } }
private void HandleDetection(Radar2D radar) { /* * Neighbors are cached on radar detection. * * This means that IsInNeighborhood is evaluated when * detected, not every time that the behavior is going to * calculate its forces. * * This helps in lowering the processing load, but could * lead to a case where a vehicle is beyond the set parameters * but still considered a neighbor. * * If this is a concern, make sure that vehicles are detected * as often as the vehicle updates is forces. * */ _neighbors.Clear(); // I'd prefer an iterator, but trying to cut down on allocations for (var i = 0; i < radar.Vehicles.Count; i++) { var other = radar.Vehicles[i]; if (Vehicle.IsInNeighborhood(other, MinRadius, MaxRadius, AngleCos)) { _neighbors.Add(other); } } }