From e50a1e70e23235460455103439073dab65ce08c7 Mon Sep 17 00:00:00 2001 From: in0finite Date: Wed, 12 Feb 2020 18:26:25 +0100 Subject: [PATCH] drive-by WIP --- Assets/Prefabs/Ped.prefab | 19 ++++-- .../Behaviours/Ped/States/DriveByState.cs | 61 +++++++++++++++++++ .../Ped/States/DriveByState.cs.meta | 11 ++++ .../Ped/States/VehicleSittingState.cs | 14 ++++- 4 files changed, 97 insertions(+), 8 deletions(-) create mode 100644 Assets/Scripts/Behaviours/Ped/States/DriveByState.cs create mode 100644 Assets/Scripts/Behaviours/Ped/States/DriveByState.cs.meta diff --git a/Assets/Prefabs/Ped.prefab b/Assets/Prefabs/Ped.prefab index d76c979c..01abc333 100644 --- a/Assets/Prefabs/Ped.prefab +++ b/Assets/Prefabs/Ped.prefab @@ -29,6 +29,7 @@ GameObject: - component: {fileID: 114803762585694722} - component: {fileID: 114244562150032294} - component: {fileID: 114293662543306134} + - component: {fileID: 7181738364298022858} m_Layer: 11 m_Name: States m_TagString: Untagged @@ -297,6 +298,18 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 4e111211033b048ca9ca00766168ed4b, type: 3} m_Name: m_EditorClassIdentifier: +--- !u!114 &7181738364298022858 +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: 603044a9ff214434db928f6a43fd0b8a, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &1273918895060814 GameObject: m_ObjectHideFlags: 0 @@ -368,12 +381,9 @@ MonoBehaviour: m_EditorClassIdentifier: syncInterval: 0.1 shouldPlayAnims: 1 - TurnSpeed: 10 - jumpSpeed: 8 - m_cameraDistance: 3 - m_cameraDistanceVehicle: 6 m_cameraClampValue: {x: 60, y: 60} m_maxHealth: 100 + m_inputSendInterval: 0.033333335 m_enterVehicleRadius: 2 --- !u!114 &114173420020992462 MonoBehaviour: @@ -387,7 +397,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 57e796a954503384dbd1282729710af5, type: 3} m_Name: m_EditorClassIdentifier: - CursorSensitivity: {x: 7, y: 7} clampInDegrees: {x: 60, y: 60} smoothing: {x: 10, y: 10} m_doSmooth: 0 diff --git a/Assets/Scripts/Behaviours/Ped/States/DriveByState.cs b/Assets/Scripts/Behaviours/Ped/States/DriveByState.cs new file mode 100644 index 00000000..43bc9272 --- /dev/null +++ b/Assets/Scripts/Behaviours/Ped/States/DriveByState.cs @@ -0,0 +1,61 @@ +using UnityEngine; +using SanAndreasUnity.Behaviours.Vehicles; + +namespace SanAndreasUnity.Behaviours.Peds.States +{ + + public class DriveByState : VehicleSittingState, IAimState + { + + public override void EnterVehicle(Vehicle vehicle, Vehicle.Seat seat) + { + this.CurrentVehicle = vehicle; + this.CurrentVehicleSeatAlignment = seat.Alignment; + + m_ped.SwitchState (); + } + + protected override void EnterVehicleInternal() + { + if (m_isServer) + m_vehicleParentOffset = m_model.VehicleParentOffset; + else if (m_isClientOnly) + m_model.VehicleParentOffset = m_vehicleParentOffset; + + BaseVehicleState.PreparePedForVehicle(m_ped, this.CurrentVehicle, this.CurrentVehicleSeat); + + PlayAnims(); + + } + + protected override void UpdateAnims() + { + PlayAnims(); + } + + void PlayAnims() + { + if (this.CurrentVehicleSeat != null) + m_model.PlayAnim(new Importing.Animation.AnimId("ped", "DrivebyL_" + (this.CurrentVehicleSeat.IsLeftHand ? "L" : "R"))); + } + + void IAimState.StartFiring() + { + // switch to firing state + + } + + // camera + + public override void OnAimButtonPressed() + { + // switch to sitting state + if (m_isServer) + m_ped.GetStateOrLogError().EnterVehicle(this.CurrentVehicle, this.CurrentVehicleSeatAlignment); + else + base.OnAimButtonPressed(); + } + + } + +} diff --git a/Assets/Scripts/Behaviours/Ped/States/DriveByState.cs.meta b/Assets/Scripts/Behaviours/Ped/States/DriveByState.cs.meta new file mode 100644 index 00000000..37ee331d --- /dev/null +++ b/Assets/Scripts/Behaviours/Ped/States/DriveByState.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 603044a9ff214434db928f6a43fd0b8a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Behaviours/Ped/States/VehicleSittingState.cs b/Assets/Scripts/Behaviours/Ped/States/VehicleSittingState.cs index 95d79b3f..ee029cb0 100644 --- a/Assets/Scripts/Behaviours/Ped/States/VehicleSittingState.cs +++ b/Assets/Scripts/Behaviours/Ped/States/VehicleSittingState.cs @@ -9,7 +9,7 @@ namespace SanAndreasUnity.Behaviours.Peds.States public class VehicleSittingState : BaseVehicleState { - Vector3 m_vehicleParentOffset = Vector3.zero; + protected Vector3 m_vehicleParentOffset = Vector3.zero; //Vector3 m_rootFramePos = Vector3.zero; @@ -51,7 +51,7 @@ namespace SanAndreasUnity.Behaviours.Peds.States this.EnterVehicle(vehicle, vehicle.GetSeat(seatAlignment)); } - public void EnterVehicle(Vehicle vehicle, Vehicle.Seat seat) + public virtual void EnterVehicle(Vehicle vehicle, Vehicle.Seat seat) { this.CurrentVehicle = vehicle; this.CurrentVehicleSeatAlignment = seat.Alignment; @@ -59,7 +59,7 @@ namespace SanAndreasUnity.Behaviours.Peds.States m_ped.SwitchState (); } - void EnterVehicleInternal() + protected virtual void EnterVehicleInternal() { Vehicle vehicle = this.CurrentVehicle; Vehicle.Seat seat = this.CurrentVehicleSeat; @@ -118,6 +118,14 @@ namespace SanAndreasUnity.Behaviours.Peds.States } + public override void OnAimButtonPressed() + { + if (m_isServer) + m_ped.GetStateOrLogError().EnterVehicle(this.CurrentVehicle, this.CurrentVehicleSeatAlignment); + else + base.OnAimButtonPressed(); + } + public override void UpdateState() { base.UpdateState();