2020-05-31 17:07:22 +00:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using SanAndreasUnity.Behaviours.Vehicles;
|
|
|
|
|
using SanAndreasUnity.Behaviours.World;
|
|
|
|
|
using SanAndreasUnity.Importing.Animation;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using SanAndreasUnity.Behaviours.Peds.States;
|
2019-04-25 19:58:21 +00:00
|
|
|
|
using SanAndreasUnity.Net;
|
2020-05-31 17:07:22 +00:00
|
|
|
|
|
|
|
|
|
namespace SanAndreasUnity.Behaviours
|
|
|
|
|
{
|
|
|
|
|
|
2019-04-23 23:25:49 +00:00
|
|
|
|
public partial class Ped {
|
2020-05-31 17:07:22 +00:00
|
|
|
|
|
|
|
|
|
[SerializeField] private float m_enterVehicleRadius = 2.0f;
|
2019-06-23 00:52:48 +00:00
|
|
|
|
public float EnterVehicleRadius { get { return m_enterVehicleRadius; } set { m_enterVehicleRadius = value; } }
|
2020-05-31 17:07:22 +00:00
|
|
|
|
|
|
|
|
|
public Vehicle CurrentVehicle {
|
|
|
|
|
get {
|
|
|
|
|
if (this.CurrentState != null && this.CurrentState is IVehicleState)
|
|
|
|
|
{
|
|
|
|
|
return ((IVehicleState)this.CurrentState).CurrentVehicle;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Vehicle.Seat CurrentVehicleSeat {
|
|
|
|
|
get {
|
|
|
|
|
if (this.CurrentState != null && this.CurrentState is IVehicleState)
|
|
|
|
|
{
|
|
|
|
|
return ((IVehicleState)this.CurrentState).CurrentVehicleSeat;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsInVehicle { get { return CurrentVehicle != null; } }
|
|
|
|
|
|
|
|
|
|
public bool IsInVehicleSeat { get { return this.CurrentState != null && this.CurrentState.RepresentsState (typeof(VehicleSittingState)); } }
|
|
|
|
|
|
|
|
|
|
public bool IsDrivingVehicle { get { return this.IsInVehicleSeat && this.CurrentVehicleSeat.IsDriver && this.IsInVehicle; } }
|
|
|
|
|
|
|
|
|
|
public Vehicle.SeatAlignment CurrentVehicleSeatAlignment { get { return CurrentVehicleSeat.Alignment; } }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void EnterVehicle(Vehicle vehicle, Vehicle.SeatAlignment seatAlignment, bool immediate = false)
|
|
|
|
|
{
|
2019-04-25 19:58:21 +00:00
|
|
|
|
NetStatus.ThrowIfNotOnServer();
|
2020-05-31 17:07:22 +00:00
|
|
|
|
// find state script, and call it's method
|
|
|
|
|
this.GetStateOrLogError<VehicleEnteringState>().TryEnterVehicle( vehicle, seatAlignment, immediate );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ExitVehicle(bool immediate = false)
|
|
|
|
|
{
|
2019-04-25 19:58:21 +00:00
|
|
|
|
NetStatus.ThrowIfNotOnServer();
|
2020-05-31 17:07:22 +00:00
|
|
|
|
this.GetStateOrLogError<VehicleExitingState> ().ExitVehicle (immediate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static List<Vehicle.SeatAlignment> GetFreeSeats( Vehicle vehicle )
|
|
|
|
|
{
|
|
|
|
|
return vehicle.Seats.Where (s => !s.IsTaken).Select (s => s.Alignment).ToList ();
|
|
|
|
|
|
|
|
|
|
// var freeSeats = new List<Vehicle.SeatAlignment> (vehicle.Seats.Select (s => s.Alignment));
|
|
|
|
|
//
|
|
|
|
|
// var players = FindObjectsOfType<Player> ();
|
|
|
|
|
//
|
|
|
|
|
// foreach (var p in players) {
|
|
|
|
|
// if (p.IsInVehicle && p.CurrentVehicle == vehicle) {
|
|
|
|
|
// freeSeats.Remove (p.CurrentVehicleSeatAlignment);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// return freeSeats;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateWheelTurning()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Vehicle FindVehicleInRange ()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// find any vehicles that have a seat inside the checking radius and sort by closest seat
|
|
|
|
|
return FindObjectsOfType<Vehicle>()
|
|
|
|
|
.Where(x => Vector3.Distance(transform.position, x.FindClosestSeatTransform(transform.position).position) < EnterVehicleRadius)
|
|
|
|
|
.OrderBy(x => Vector3.Distance(transform.position, x.FindClosestSeatTransform(transform.position).position))
|
|
|
|
|
.FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Vehicle TryEnterVehicleInRange ()
|
|
|
|
|
{
|
|
|
|
|
var vehicle = this.FindVehicleInRange ();
|
|
|
|
|
if (null == vehicle)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
var seat = vehicle.FindClosestSeat(this.transform.position);
|
|
|
|
|
|
|
|
|
|
this.EnterVehicle(vehicle, seat);
|
|
|
|
|
|
|
|
|
|
return vehicle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|