2020-05-31 17:07:22 +00:00
|
|
|
using UnityEngine;
|
|
|
|
using SanAndreasUnity.Utilities;
|
|
|
|
using SanAndreasUnity.Behaviours.Vehicles;
|
|
|
|
using SanAndreasUnity.Behaviours.World;
|
|
|
|
using SanAndreasUnity.Importing.Animation;
|
|
|
|
|
|
|
|
namespace SanAndreasUnity.Behaviours.Peds.States
|
|
|
|
{
|
|
|
|
|
|
|
|
public class VehicleEnteringState : BaseVehicleState
|
|
|
|
{
|
2019-04-28 20:26:12 +00:00
|
|
|
|
2020-05-31 17:07:22 +00:00
|
|
|
|
2019-04-28 20:57:04 +00:00
|
|
|
public override void OnBecameInactive()
|
|
|
|
{
|
|
|
|
// restore everything
|
|
|
|
|
2019-04-28 21:17:50 +00:00
|
|
|
if (!m_ped.IsInVehicle)
|
|
|
|
{
|
|
|
|
m_ped.characterController.enabled = true;
|
|
|
|
// restore seat's occupying ped ? - no
|
|
|
|
m_ped.transform.SetParent(null, true);
|
|
|
|
m_model.IsInVehicle = false;
|
|
|
|
}
|
2019-04-28 20:57:04 +00:00
|
|
|
|
2020-05-31 17:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public bool TryEnterVehicle(Vehicle vehicle, Vehicle.SeatAlignment seatAlignment, bool immediate = false)
|
|
|
|
{
|
2019-04-28 20:17:37 +00:00
|
|
|
// this code heavily modifies game state, so it can run only on server
|
|
|
|
Net.NetStatus.ThrowIfNotOnServer();
|
|
|
|
|
2020-05-31 17:07:22 +00:00
|
|
|
if (!this.CanEnterVehicle (vehicle, seatAlignment))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
Vehicle.Seat seat = vehicle.GetSeat (seatAlignment);
|
|
|
|
|
|
|
|
// switch state here
|
|
|
|
m_ped.SwitchState<VehicleEnteringState>();
|
|
|
|
|
|
|
|
this.CurrentVehicle = vehicle;
|
|
|
|
this.CurrentVehicleSeat = seat;
|
|
|
|
seat.OccupyingPed = m_ped;
|
|
|
|
|
|
|
|
m_ped.characterController.enabled = false;
|
|
|
|
|
|
|
|
|
2019-04-25 20:18:02 +00:00
|
|
|
if (m_ped.IsControlledByLocalPlayer)
|
2020-05-31 17:07:22 +00:00
|
|
|
{
|
|
|
|
if (m_ped.Camera != null) {
|
|
|
|
// m_ped.Camera.transform.SetParent (seat.Parent, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_ped.transform.SetParent(seat.Parent);
|
|
|
|
m_ped.transform.localPosition = Vector3.zero;
|
|
|
|
m_ped.transform.localRotation = Quaternion.identity;
|
|
|
|
|
2019-04-28 20:57:04 +00:00
|
|
|
if (seat.IsDriver)
|
2020-05-31 17:07:22 +00:00
|
|
|
{
|
2019-04-28 20:57:04 +00:00
|
|
|
// TODO: this should be done when ped enters the car
|
2020-05-31 17:07:22 +00:00
|
|
|
vehicle.StartControlling();
|
|
|
|
}
|
|
|
|
|
2019-04-28 20:26:12 +00:00
|
|
|
m_model.IsInVehicle = true;
|
2020-05-31 17:07:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (!vehicle.IsNightToggled && WorldController.IsNight)
|
|
|
|
vehicle.IsNightToggled = true;
|
|
|
|
else if (vehicle.IsNightToggled && !WorldController.IsNight)
|
|
|
|
vehicle.IsNightToggled = false;
|
|
|
|
|
|
|
|
|
2019-04-28 21:17:50 +00:00
|
|
|
// send message to clients
|
|
|
|
if (!immediate)
|
|
|
|
Net.PedSync.Local.PedStartedEnteringVehicle();
|
|
|
|
|
|
|
|
|
2020-05-31 17:07:22 +00:00
|
|
|
StartCoroutine (EnterVehicleAnimation (seat, immediate));
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private System.Collections.IEnumerator EnterVehicleAnimation(Vehicle.Seat seat, bool immediate)
|
|
|
|
{
|
|
|
|
var animIndex = seat.IsLeftHand ? AnimIndex.GetInLeft : AnimIndex.GetInRight;
|
|
|
|
|
2019-04-28 20:26:12 +00:00
|
|
|
m_model.VehicleParentOffset = Vector3.Scale(m_model.GetAnim(AnimGroup.Car, animIndex).RootEnd, new Vector3(-1, -1, -1));
|
2020-05-31 17:07:22 +00:00
|
|
|
|
|
|
|
if (!immediate)
|
|
|
|
{
|
2019-04-28 20:26:12 +00:00
|
|
|
var animState = m_model.PlayAnim(AnimGroup.Car, animIndex, PlayMode.StopAll);
|
2020-05-31 17:07:22 +00:00
|
|
|
animState.wrapMode = WrapMode.Once;
|
|
|
|
|
|
|
|
// TODO: also check if this state is still active state
|
|
|
|
while (animState.enabled)
|
|
|
|
{
|
|
|
|
yield return new WaitForEndOfFrame();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: check if this state is still active, and if vehicle is alive
|
|
|
|
|
|
|
|
|
2019-04-28 20:26:12 +00:00
|
|
|
// ped now completely entered the vehicle
|
2020-05-31 17:07:22 +00:00
|
|
|
|
2019-04-28 20:26:12 +00:00
|
|
|
// call method from VehicleSittingState - he will switch state
|
2020-05-31 17:07:22 +00:00
|
|
|
m_ped.GetStateOrLogError<VehicleSittingState> ().EnterVehicle(this.CurrentVehicle, seat);
|
|
|
|
|
|
|
|
// this variable is not needed - it can be obtained based on current state
|
|
|
|
// IsInVehicleSeat = true;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-04-28 21:17:50 +00:00
|
|
|
internal void PedStartedEnteringVehicle(Vehicle vehicle, Vehicle.SeatAlignment seatAlignment)
|
|
|
|
{
|
|
|
|
// sent from server
|
|
|
|
|
2019-04-28 21:18:39 +00:00
|
|
|
|
2019-04-28 21:17:50 +00:00
|
|
|
}
|
|
|
|
|
2020-05-31 17:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|