mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-10 06:34:16 +00:00
small optimization for finding closest vehicle/seat
This commit is contained in:
parent
0e130999f4
commit
4d646c853d
3 changed files with 15 additions and 8 deletions
|
@ -101,7 +101,7 @@ namespace SanAndreasUnity.Behaviours
|
|||
if (null == vehicle)
|
||||
return null;
|
||||
|
||||
var seat = vehicle.FindClosestSeat(this.transform.position);
|
||||
var seat = vehicle.GetSeatAlignmentOfClosestSeat(this.transform.position);
|
||||
|
||||
this.EnterVehicle(vehicle, seat);
|
||||
|
||||
|
|
|
@ -244,7 +244,7 @@ namespace SanAndreasUnity.Behaviours
|
|||
|
||||
// draw closest seat
|
||||
|
||||
var closestSeat = vehicle.FindClosestSeat(transform.position);
|
||||
var closestSeat = vehicle.GetSeatAlignmentOfClosestSeat(transform.position);
|
||||
|
||||
if (closestSeat != Vehicle.SeatAlignment.None)
|
||||
{
|
||||
|
|
|
@ -334,18 +334,25 @@ namespace SanAndreasUnity.Behaviours.Vehicles
|
|||
m_rearRightLightOk = m_rearRightLight != null;
|
||||
}
|
||||
|
||||
public SeatAlignment FindClosestSeat(Vector3 position)
|
||||
public SeatAlignment GetSeatAlignmentOfClosestSeat(Vector3 position)
|
||||
{
|
||||
var seat = _seats.Select((s, i) => new { s, i })
|
||||
.OrderBy(x => Vector3.Distance(position, x.s.Parent.position))
|
||||
.FirstOrDefault();
|
||||
var seat = FindClosestSeat(position);
|
||||
return seat != null ? seat.Alignment : SeatAlignment.None;
|
||||
}
|
||||
|
||||
return (seat == null ? SeatAlignment.None : seat.s.Alignment);
|
||||
public Seat FindClosestSeat(Vector3 position)
|
||||
{
|
||||
if (this.Seats.Count < 1)
|
||||
return null;
|
||||
|
||||
return this.Seats.Aggregate((a, b) =>
|
||||
Vector3.Distance(position, a.Parent.position) < Vector3.Distance(position, b.Parent.position) ? a : b);
|
||||
}
|
||||
|
||||
public Transform FindClosestSeatTransform(Vector3 position)
|
||||
{
|
||||
return GetSeatTransform(FindClosestSeat(position));
|
||||
var seat = FindClosestSeat(position);
|
||||
return seat != null ? seat.Parent : null;
|
||||
}
|
||||
|
||||
public Seat GetSeat(SeatAlignment alignment)
|
||||
|
|
Loading…
Reference in a new issue