diff --git a/Assets/Prefabs/Ped.prefab b/Assets/Prefabs/Ped.prefab index 7426c095..520b62c4 100644 --- a/Assets/Prefabs/Ped.prefab +++ b/Assets/Prefabs/Ped.prefab @@ -31,6 +31,7 @@ GameObject: - component: {fileID: 114293662543306134} - component: {fileID: 7181738364298022858} - component: {fileID: 2421064630445689714} + - component: {fileID: 986117917908478283} m_Layer: 11 m_Name: States m_TagString: Untagged @@ -330,6 +331,18 @@ MonoBehaviour: timeUntilAbleToEnterState: 0.5 timeUntilAbleToExitState: 0.5 timeUntilAbleToChangeAnim: 0.5 +--- !u!114 &986117917908478283 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1154474390377672} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 751a2e3fa7025a3448157779e2c99fe5, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &1273918895060814 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Behaviours/Ped/Ped.cs b/Assets/Scripts/Behaviours/Ped/Ped.cs index 7c888c83..b06368f7 100644 --- a/Assets/Scripts/Behaviours/Ped/Ped.cs +++ b/Assets/Scripts/Behaviours/Ped/Ped.cs @@ -662,6 +662,12 @@ namespace SanAndreasUnity.Behaviours this.CurrentState.OnFlyThroughButtonPressed (); } + public void OnSurrenderButtonPressed() + { + if (this.CurrentState != null) + this.CurrentState.OnSurrenderButtonPressed(); + } + internal void OnStartCollidingWithEnex(EntranceExitMapObject enex) { diff --git a/Assets/Scripts/Behaviours/Ped/States/BaseMovementState.cs b/Assets/Scripts/Behaviours/Ped/States/BaseMovementState.cs index 6e5e2feb..c99ec21c 100644 --- a/Assets/Scripts/Behaviours/Ped/States/BaseMovementState.cs +++ b/Assets/Scripts/Behaviours/Ped/States/BaseMovementState.cs @@ -40,12 +40,8 @@ namespace SanAndreasUnity.Behaviours.Peds.States protected virtual void SwitchToMovementState() { System.Type type = BaseMovementState.GetMovementStateToSwitchToBasedOnInput(m_ped); - var state = (BaseMovementState) m_ped.GetStateOrLogError(type); - if (!EnoughTimePassedToSwitchBetweenMovementStates(this, state)) - return; - - m_ped.SwitchState(type); + this.SwitchToMovementStateIfEnoughTimePassed(type); } public static bool EnoughTimePassedToSwitchBetweenMovementStates( @@ -61,6 +57,18 @@ namespace SanAndreasUnity.Behaviours.Peds.States return true; } + public bool SwitchToMovementStateIfEnoughTimePassed(System.Type type) + { + var state = (BaseMovementState)m_ped.GetStateOrLogError(type); + + if (!EnoughTimePassedToSwitchBetweenMovementStates(this, state)) + return false; + + m_ped.SwitchState(type); + + return true; + } + public static void SwitchToMovementStateBasedOnInput (Ped ped) { System.Type type = GetMovementStateToSwitchToBasedOnInput(ped); @@ -161,6 +169,14 @@ namespace SanAndreasUnity.Behaviours.Peds.States m_ped.GetStateOrLogError ().EnterState (true); } + public override void OnSurrenderButtonPressed() + { + if (m_isServer) + this.SwitchToMovementStateIfEnoughTimePassed(typeof(SurrenderState)); + else + base.OnSurrenderButtonPressed(); + } + } } diff --git a/Assets/Scripts/Behaviours/Ped/States/BaseScriptState.cs b/Assets/Scripts/Behaviours/Ped/States/BaseScriptState.cs index be67d0c8..af964f56 100644 --- a/Assets/Scripts/Behaviours/Ped/States/BaseScriptState.cs +++ b/Assets/Scripts/Behaviours/Ped/States/BaseScriptState.cs @@ -286,6 +286,11 @@ namespace SanAndreasUnity.Behaviours.Peds.States } + public virtual void OnSurrenderButtonPressed() + { + + } + public virtual void OnSwitchedStateByServer(byte[] data) { diff --git a/Assets/Scripts/Behaviours/Ped/States/SurrenderState.cs b/Assets/Scripts/Behaviours/Ped/States/SurrenderState.cs new file mode 100644 index 00000000..448f0a9f --- /dev/null +++ b/Assets/Scripts/Behaviours/Ped/States/SurrenderState.cs @@ -0,0 +1,47 @@ +using SanAndreasUnity.Importing.Animation; + +namespace SanAndreasUnity.Behaviours.Peds.States +{ + public class SurrenderState : BaseMovementState + { + public override AnimId movementAnim => new AnimId("ped", "handsup"); + public override AnimId movementWeaponAnim => this.movementAnim; + + + protected override void SwitchToMovementState() + { + // prevent switching to Stand state + + System.Type type = BaseMovementState.GetMovementStateToSwitchToBasedOnInput(m_ped); + + if (typeof(StandState).IsAssignableFrom(type)) + return; + + base.SwitchToMovementState(); + } + + protected override void UpdateAnims() + { + base.UpdateAnims(); + + if (!this.IsActiveState) + return; + + if (m_model.LastAnimState != null) + m_model.LastAnimState.wrapMode = UnityEngine.WrapMode.ClampForever; + } + + public override void OnSurrenderButtonPressed() + { + if (m_isServer) + this.SwitchToMovementStateIfEnoughTimePassed(typeof(StandState)); + else + base.OnSurrenderButtonPressed(); + } + } + + public static class SurrenderStatePedExtensions + { + public static bool IsSurrendering(this Ped ped) => ped.CurrentState is SurrenderState; + } +} diff --git a/Assets/Scripts/Behaviours/Ped/States/SurrenderState.cs.meta b/Assets/Scripts/Behaviours/Ped/States/SurrenderState.cs.meta new file mode 100644 index 00000000..bb155709 --- /dev/null +++ b/Assets/Scripts/Behaviours/Ped/States/SurrenderState.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 751a2e3fa7025a3448157779e2c99fe5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Behaviours/PedAI/WalkAroundState.cs b/Assets/Scripts/Behaviours/PedAI/WalkAroundState.cs index 92ff4eae..a7cb1031 100644 --- a/Assets/Scripts/Behaviours/PedAI/WalkAroundState.cs +++ b/Assets/Scripts/Behaviours/PedAI/WalkAroundState.cs @@ -1,3 +1,4 @@ +using SanAndreasUnity.Behaviours.Peds.States; using SanAndreasUnity.Importing.Items.Definitions; using SanAndreasUnity.Importing.Paths; using SanAndreasUnity.Utilities; @@ -60,8 +61,9 @@ namespace SanAndreasUnity.Behaviours.Peds.AI if (this.IsSurrendering) { - // TODO: set Surrendering button to on - + // make sure ped is surrendering + if (!_ped.IsSurrendering()) + _ped.OnSurrenderButtonPressed(); return; }