2020-05-31 17:07:22 +00:00
|
|
|
using UnityEngine;
|
|
|
|
using SanAndreasUnity.Utilities;
|
|
|
|
using SanAndreasUnity.Behaviours.Vehicles;
|
|
|
|
using SanAndreasUnity.Importing.Animation;
|
|
|
|
|
|
|
|
namespace SanAndreasUnity.Behaviours.Peds.States
|
|
|
|
{
|
|
|
|
|
|
|
|
public class VehicleExitingState : BaseVehicleState
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
public override void OnBecameActive() {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ExitVehicle(bool immediate = false)
|
|
|
|
{
|
|
|
|
if (!m_ped.IsInVehicle || !m_ped.IsInVehicleSeat)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// obtain current vehicle from Ped
|
|
|
|
this.CurrentVehicle = m_ped.CurrentVehicle;
|
|
|
|
this.CurrentVehicleSeat = m_ped.CurrentVehicleSeat;
|
|
|
|
|
|
|
|
// after obtaining parameters, switch to this state
|
|
|
|
m_ped.SwitchState<VehicleExitingState> ();
|
|
|
|
|
2019-04-29 00:26:44 +00:00
|
|
|
VehicleEnteringState.PreparePedForVehicle(m_ped, this.CurrentVehicle, this.CurrentVehicleSeat);
|
|
|
|
|
2019-04-28 23:49:21 +00:00
|
|
|
if (this.CurrentVehicleSeat.IsDriver)
|
|
|
|
this.CurrentVehicle.StopControlling();
|
2019-04-28 23:51:12 +00:00
|
|
|
|
2020-05-31 17:07:22 +00:00
|
|
|
StartCoroutine (ExitVehicleAnimation (immediate));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private System.Collections.IEnumerator ExitVehicleAnimation(bool immediate)
|
|
|
|
{
|
|
|
|
|
|
|
|
var seat = this.CurrentVehicleSeat;
|
|
|
|
|
|
|
|
var animIndex = seat.IsLeftHand ? AnimIndex.GetOutLeft : AnimIndex.GetOutRight;
|
|
|
|
|
2019-04-29 00:04:16 +00:00
|
|
|
m_model.VehicleParentOffset = Vector3.Scale(m_model.GetAnim(AnimGroup.Car, animIndex).RootStart, new Vector3(-1, -1, -1));
|
2020-05-31 17:07:22 +00:00
|
|
|
|
|
|
|
if (!immediate)
|
|
|
|
{
|
2019-04-29 00:04:16 +00:00
|
|
|
var animState = m_model.PlayAnim(AnimGroup.Car, animIndex, PlayMode.StopAll);
|
2020-05-31 17:07:22 +00:00
|
|
|
animState.wrapMode = WrapMode.Once;
|
|
|
|
|
|
|
|
// wait until anim finishes or stops
|
|
|
|
while (animState.enabled)
|
|
|
|
yield return new WaitForEndOfFrame();
|
|
|
|
}
|
|
|
|
|
2019-04-29 00:04:16 +00:00
|
|
|
// ped now completely exited the vehicle
|
2020-05-31 17:07:22 +00:00
|
|
|
|
2019-04-29 00:04:16 +00:00
|
|
|
m_model.IsInVehicle = false;
|
2020-05-31 17:07:22 +00:00
|
|
|
|
|
|
|
this.CurrentVehicle = null;
|
|
|
|
this.CurrentVehicleSeat = null;
|
|
|
|
seat.OccupyingPed = null;
|
|
|
|
|
2019-04-29 00:04:16 +00:00
|
|
|
m_ped.transform.localPosition = m_model.VehicleParentOffset;
|
2020-05-31 17:07:22 +00:00
|
|
|
m_ped.transform.localRotation = Quaternion.identity;
|
|
|
|
|
|
|
|
m_ped.transform.SetParent(null);
|
|
|
|
|
|
|
|
m_ped.characterController.enabled = true;
|
|
|
|
|
2019-04-29 00:04:16 +00:00
|
|
|
m_model.VehicleParentOffset = Vector3.zero;
|
2020-05-31 17:07:22 +00:00
|
|
|
|
|
|
|
// switch to stand state
|
|
|
|
m_ped.SwitchState<StandState> ();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|