2020-05-31 17:07:22 +00:00
|
|
|
using UnityEngine;
|
|
|
|
using SanAndreasUnity.Utilities;
|
|
|
|
using SanAndreasUnity.Importing.Animation;
|
|
|
|
|
|
|
|
namespace SanAndreasUnity.Behaviours.Peds.States
|
|
|
|
{
|
|
|
|
|
|
|
|
public class CrouchState : BaseMovementState
|
|
|
|
{
|
|
|
|
public override AnimId movementAnim { get { return new AnimId ("ped", "WEAPON_crouch"); } }
|
|
|
|
public override AnimId movementWeaponAnim { get { return this.movementAnim; } }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override void SwitchToMovementState ()
|
|
|
|
{
|
|
|
|
// can only switch to CrouchMove state
|
|
|
|
if( m_ped.Movement.sqrMagnitude > float.Epsilon )
|
|
|
|
{
|
|
|
|
m_ped.SwitchState<CrouchMoveState>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void SwitchToAimState ()
|
|
|
|
{
|
|
|
|
CrouchState.SwitchToAimState(m_ped);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void SwitchToAimState(Ped ped)
|
|
|
|
{
|
|
|
|
// can only switch to CrouchAim state
|
|
|
|
if( ped.IsAimOn && ped.IsHoldingWeapon )
|
|
|
|
{
|
|
|
|
ped.SwitchState<CrouchAimState>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-13 14:11:37 +00:00
|
|
|
protected override void UpdateAnims ()
|
|
|
|
{
|
|
|
|
base.UpdateAnims();
|
|
|
|
|
|
|
|
// if( !this.IsActiveState )
|
|
|
|
// return;
|
|
|
|
|
|
|
|
CrouchState.AdjustRootFramePosition(m_ped);
|
2019-07-13 14:19:59 +00:00
|
|
|
|
2019-07-13 14:11:37 +00:00
|
|
|
}
|
|
|
|
|
2019-07-13 13:54:49 +00:00
|
|
|
public static void AdjustRootFramePosition(Ped ped)
|
|
|
|
{
|
|
|
|
// we need to adjust local position of some bones - root frame needs to be 0.5 units below the ped
|
|
|
|
|
|
|
|
var model = ped.PlayerModel;
|
|
|
|
|
2019-07-13 14:19:59 +00:00
|
|
|
if (null == model.RootFrame)
|
|
|
|
return;
|
|
|
|
if (null == model.UnnamedFrame)
|
|
|
|
return;
|
|
|
|
|
2019-07-13 13:54:49 +00:00
|
|
|
// for some reason, y position always remains 0.25
|
|
|
|
// m_model.UnnamedFrame.transform.localPosition = m_model.UnnamedFrame.transform.localPosition.WithXAndZ();
|
|
|
|
|
|
|
|
Vector3 pos = model.RootFrame.transform.localPosition;
|
|
|
|
pos.y = -0.5f - model.UnnamedFrame.transform.localPosition.y;
|
|
|
|
model.RootFrame.transform.localPosition = pos;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-05-31 17:07:22 +00:00
|
|
|
public override void OnJumpPressed ()
|
|
|
|
{
|
|
|
|
// switch to stand state
|
|
|
|
// it's better to do this event-based, because after switching to stand state, we may enter
|
|
|
|
// jump state right after it
|
|
|
|
|
|
|
|
// we can't switch to stand state, because that will cause ped to jump (jump button will be on)
|
|
|
|
|
|
|
|
// m_ped.SwitchState<StandState>();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void OnCrouchButtonPressed ()
|
|
|
|
{
|
|
|
|
// switch to stand state
|
|
|
|
|
2019-04-28 16:20:33 +00:00
|
|
|
if (m_isServer)
|
|
|
|
m_ped.SwitchState<StandState>();
|
2019-04-28 17:13:01 +00:00
|
|
|
else
|
|
|
|
base.OnCrouchButtonPressed();
|
2020-05-31 17:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|