2020-05-31 17:07:22 +00:00
|
|
|
using UnityEngine;
|
|
|
|
using SanAndreasUnity.Utilities;
|
|
|
|
using SanAndreasUnity.Behaviours.Vehicles;
|
|
|
|
using SanAndreasUnity.Importing.Animation;
|
2019-04-28 23:46:13 +00:00
|
|
|
using System.Linq;
|
2020-05-31 17:07:22 +00:00
|
|
|
|
|
|
|
namespace SanAndreasUnity.Behaviours.Peds.States
|
|
|
|
{
|
|
|
|
|
|
|
|
public class VehicleSittingState : BaseVehicleState
|
|
|
|
{
|
2019-07-13 15:38:07 +00:00
|
|
|
Vector3 m_vehicleParentOffset = Vector3.zero;
|
|
|
|
|
2020-05-31 17:07:22 +00:00
|
|
|
|
|
|
|
|
2019-05-25 22:08:56 +00:00
|
|
|
public override void OnBecameActive()
|
|
|
|
{
|
|
|
|
base.OnBecameActive();
|
2019-07-11 23:18:34 +00:00
|
|
|
if (m_isServer) // clients will do this when vehicle gets assigned
|
|
|
|
this.EnterVehicleInternal();
|
2019-05-25 22:08:56 +00:00
|
|
|
}
|
|
|
|
|
2019-04-28 22:37:00 +00:00
|
|
|
public override void OnBecameInactive()
|
|
|
|
{
|
2019-07-13 15:38:07 +00:00
|
|
|
m_vehicleParentOffset = Vector3.zero;
|
2019-04-28 23:15:24 +00:00
|
|
|
this.Cleanup();
|
2020-05-31 17:07:22 +00:00
|
|
|
|
2019-04-28 22:37:00 +00:00
|
|
|
base.OnBecameInactive();
|
2020-05-31 17:07:22 +00:00
|
|
|
}
|
|
|
|
|
2019-07-11 23:18:34 +00:00
|
|
|
protected override void OnVehicleAssigned()
|
|
|
|
{
|
|
|
|
this.EnterVehicleInternal();
|
|
|
|
}
|
|
|
|
|
2019-04-28 23:46:13 +00:00
|
|
|
public void EnterVehicle(Vehicle vehicle, Vehicle.SeatAlignment seatAlignment)
|
|
|
|
{
|
|
|
|
this.EnterVehicle(vehicle, vehicle.GetSeat(seatAlignment));
|
|
|
|
}
|
|
|
|
|
2020-05-31 17:07:22 +00:00
|
|
|
public void EnterVehicle(Vehicle vehicle, Vehicle.Seat seat)
|
|
|
|
{
|
|
|
|
this.CurrentVehicle = vehicle;
|
2019-07-11 20:54:48 +00:00
|
|
|
this.CurrentVehicleSeatAlignment = seat.Alignment;
|
2020-05-31 17:07:22 +00:00
|
|
|
|
|
|
|
m_ped.SwitchState<VehicleSittingState> ();
|
2019-05-25 22:08:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EnterVehicleInternal()
|
|
|
|
{
|
|
|
|
Vehicle vehicle = this.CurrentVehicle;
|
|
|
|
Vehicle.Seat seat = this.CurrentVehicleSeat;
|
2019-07-13 15:38:07 +00:00
|
|
|
m_vehicleParentOffset = m_model.VehicleParentOffset;
|
2020-05-31 17:07:22 +00:00
|
|
|
|
2019-07-11 23:04:41 +00:00
|
|
|
BaseVehicleState.PreparePedForVehicle(m_ped, vehicle, seat);
|
2019-04-28 23:46:13 +00:00
|
|
|
|
2019-07-13 15:38:07 +00:00
|
|
|
//this.UpdateAnimsWhilePassenger();
|
2020-05-31 17:07:22 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-28 22:37:00 +00:00
|
|
|
public override void OnSubmitPressed()
|
|
|
|
{
|
2020-05-31 17:07:22 +00:00
|
|
|
// exit the vehicle
|
2019-04-28 22:37:00 +00:00
|
|
|
|
|
|
|
if (m_isServer)
|
|
|
|
m_ped.ExitVehicle();
|
|
|
|
else
|
|
|
|
base.OnSubmitPressed();
|
2020-05-31 17:07:22 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void UpdateState() {
|
|
|
|
|
|
|
|
base.UpdateState();
|
|
|
|
|
2019-07-11 21:18:25 +00:00
|
|
|
if (!this.IsActiveState)
|
|
|
|
return;
|
2019-04-28 22:37:00 +00:00
|
|
|
|
2019-07-11 21:16:26 +00:00
|
|
|
var seat = this.CurrentVehicleSeat;
|
2019-07-11 22:02:16 +00:00
|
|
|
if (seat != null)
|
|
|
|
{
|
|
|
|
if (seat.IsDriver)
|
|
|
|
this.UpdateWheelTurning ();
|
|
|
|
else
|
|
|
|
this.UpdateAnimsWhilePassenger();
|
|
|
|
}
|
2020-05-31 17:07:22 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual void UpdateWheelTurning()
|
|
|
|
{
|
|
|
|
|
2019-04-28 22:25:45 +00:00
|
|
|
m_model.VehicleParentOffset = Vector3.zero;
|
2020-05-31 17:07:22 +00:00
|
|
|
|
2019-04-28 22:25:45 +00:00
|
|
|
var driveState = this.CurrentVehicle.Steering > 0 ? AnimIndex.DriveRight : AnimIndex.DriveLeft;
|
2020-05-31 17:07:22 +00:00
|
|
|
|
2019-04-28 22:25:45 +00:00
|
|
|
var state = m_model.PlayAnim(AnimGroup.Car, driveState, PlayMode.StopAll);
|
2020-05-31 17:07:22 +00:00
|
|
|
|
|
|
|
state.speed = 0.0f;
|
|
|
|
state.wrapMode = WrapMode.ClampForever;
|
2019-04-28 22:25:45 +00:00
|
|
|
state.time = Mathf.Lerp(0.0f, state.length, Mathf.Abs(this.CurrentVehicle.Steering));
|
2020-05-31 17:07:22 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-07-11 21:53:34 +00:00
|
|
|
protected virtual void UpdateAnimsWhilePassenger()
|
|
|
|
{
|
2019-07-11 22:02:16 +00:00
|
|
|
// if (this.CurrentVehicleSeat.IsDriver)
|
|
|
|
// {
|
|
|
|
// m_model.PlayAnim(AnimGroup.Car, AnimIndex.Sit, PlayMode.StopAll);
|
|
|
|
// }
|
|
|
|
// else
|
2019-07-11 21:53:34 +00:00
|
|
|
{
|
2019-07-13 15:44:53 +00:00
|
|
|
// we have to assign offset every frame, because it can be changed when ped model changes
|
|
|
|
m_model.VehicleParentOffset = m_vehicleParentOffset;
|
|
|
|
|
2019-07-11 21:53:34 +00:00
|
|
|
m_model.PlayAnim(AnimGroup.Car, AnimIndex.SitPassenger, PlayMode.StopAll);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-31 17:07:22 +00:00
|
|
|
|
|
|
|
public override void UpdateCameraZoom()
|
|
|
|
{
|
|
|
|
m_ped.CameraDistanceVehicle = Mathf.Clamp(m_ped.CameraDistanceVehicle - m_ped.MouseScrollInput.y, 2.0f, 32.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void CheckCameraCollision ()
|
|
|
|
{
|
|
|
|
BaseScriptState.CheckCameraCollision(m_ped, this.GetCameraFocusPos(), -m_ped.Camera.transform.forward,
|
|
|
|
m_ped.CameraDistanceVehicle);
|
|
|
|
}
|
|
|
|
|
|
|
|
public new Vector3 GetCameraFocusPos()
|
|
|
|
{
|
2019-07-11 21:00:08 +00:00
|
|
|
if (m_ped.CurrentVehicle != null)
|
|
|
|
return m_ped.CurrentVehicle.transform.position;
|
|
|
|
else
|
|
|
|
return base.GetCameraFocusPos();
|
2020-05-31 17:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|