From 0ca8d49c68cc3bc6e94b064a38c843c845fa05de Mon Sep 17 00:00:00 2001 From: yzx Date: Thu, 11 Jan 2024 17:38:24 +0800 Subject: [PATCH] t --- .../EVP5/Scripts/VehicleStandardInput.cs | 18 +++++--- U3D_DrivingSystem/Assets/Scenes/main_.unity | 14 ++++++ .../Assets/Script/Manaegr/CarInputManager.cs | 44 +++++++++++++------ 3 files changed, 57 insertions(+), 19 deletions(-) diff --git a/U3D_DrivingSystem/Assets/EVP5/Scripts/VehicleStandardInput.cs b/U3D_DrivingSystem/Assets/EVP5/Scripts/VehicleStandardInput.cs index a6dbeb88..624c5ec9 100644 --- a/U3D_DrivingSystem/Assets/EVP5/Scripts/VehicleStandardInput.cs +++ b/U3D_DrivingSystem/Assets/EVP5/Scripts/VehicleStandardInput.cs @@ -52,6 +52,12 @@ namespace EVP // 将输入值从 0-100 范围映射到 0-1 范围 xxxx = Mathf.Clamp(value, 0, 100) / 100.0f; } + + public float steerInput; + public float forwardInput; + public float reverseInput; + + // public float xxxxxx; void FixedUpdate() { @@ -59,11 +65,11 @@ namespace EVP // Read the user input - float steerInput = Mathf.Clamp(Input.GetAxis(steerAxis), -1.0f, 1.0f); + steerInput = Mathf.Clamp(Input.GetAxis(steerAxis), -1.0f, 1.0f); float handbrakeInput = Mathf.Clamp01(Input.GetAxis(handbrakeAxis)); - float forwardInput = 0.0f; - float reverseInput = 0.0f; + forwardInput = 0.0f; + reverseInput = 0.0f; // Debug.Log("前轮控制左右的参数----->" + steerInput); if (throttleAndBrakeInput == ThrottleAndBrakeInput.SeparateAxes) @@ -79,9 +85,9 @@ namespace EVP // forwardInput = Mathf.Clamp01(xxxx); // Debug.Log(Mathf.Clamp01(xxxx)); // forwardInput = xxxxxx; - // Debug.Log("前轮控制左右的参数----->" + steerInput); - // Debug.Log("往前的参数----->" + forwardInput); - // Debug.Log("往后的参数----->" + reverseInput); + Debug.Log("前轮控制左右的参数----->" + steerInput); + Debug.Log("往前的参数----->" + forwardInput); + Debug.Log("往后的参数----->" + reverseInput); // Translate forward/reverse to vehicle input float throttleInput = 0.0f; diff --git a/U3D_DrivingSystem/Assets/Scenes/main_.unity b/U3D_DrivingSystem/Assets/Scenes/main_.unity index 73eb4d46..fb807c3c 100644 --- a/U3D_DrivingSystem/Assets/Scenes/main_.unity +++ b/U3D_DrivingSystem/Assets/Scenes/main_.unity @@ -397307,6 +397307,18 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: b4decbca4aaf413abd074ba71736660a, type: 3} m_Name: m_EditorClassIdentifier: +--- !u!114 &1276762325 stripped +MonoBehaviour: + m_CorrespondingSourceObject: {fileID: 11461196, guid: 4292160a5e1fde347934ac660b2c5d30, + type: 3} + m_PrefabInstance: {fileID: 2037673174} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1276762317} + m_Enabled: 0 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: ca79ba03ebacd504783b096c3667cfbd, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!114 &1276762328 MonoBehaviour: m_ObjectHideFlags: 0 @@ -397342,6 +397354,8 @@ MonoBehaviour: m_EditorClassIdentifier: turnSignalController: {fileID: 1276762328} vehicleController: {fileID: 2037673176} + vehicleStandardInput: {fileID: 1276762325} + accidentManager: {fileID: 1323185945} cam1: {fileID: 1136185827} cam2: {fileID: 1785647646} menuUI: {fileID: 1648579876} diff --git a/U3D_DrivingSystem/Assets/Script/Manaegr/CarInputManager.cs b/U3D_DrivingSystem/Assets/Script/Manaegr/CarInputManager.cs index dba97110..3ed6aca2 100644 --- a/U3D_DrivingSystem/Assets/Script/Manaegr/CarInputManager.cs +++ b/U3D_DrivingSystem/Assets/Script/Manaegr/CarInputManager.cs @@ -6,22 +6,22 @@ namespace Script.Manaegr { public class CarInputManager : MonoBehaviour { - public TurnSignalController turnSignalController; public VehicleController vehicleController; - + public VehicleStandardInput vehicleStandardInput; + public AccidentManager accidentManager; public GameObject cam1; public GameObject cam2; public GameObject menuUI; public GameObject carInfoUI; - - + + public AnimationController ygq; private bool isYgq = false; - + public void Init() { vehicleController.maxSpeedForward = 11; @@ -35,18 +35,18 @@ namespace Script.Manaegr { turnSignalController.SetSignal(1); } - + if (Input.GetKeyDown(KeyCode.K)) { turnSignalController.SetSignal(3); } - + if (Input.GetKeyDown(KeyCode.L)) { turnSignalController.SetSignal(2); } - - + + //切换车内视角 if (Input.GetKeyDown(KeyCode.U)) { @@ -61,6 +61,7 @@ namespace Script.Manaegr cam2.SetActive(false); } } + //雨刮器 if (Input.GetKeyDown(KeyCode.I)) { @@ -75,7 +76,7 @@ namespace Script.Manaegr ygq.StopAnimationLoop(); } } - + //菜单 if (Input.GetKeyDown(KeyCode.Escape)) { @@ -88,9 +89,26 @@ namespace Script.Manaegr menuUI.SetActive(true); } } - - - + + if (vehicleStandardInput.forwardInput >= 1) + { + if (vehicleStandardInput.steerInput >= 1) //右 + { + if (turnSignalController.turnSignalState != TurnSignalState.右转向) + { + accidentManager.PlayAnimationSequence("MsgWinAnimOpen", "MsgWinAnimClose"); + accidentManager.uis.transform.Find("UI/转向").gameObject.SetActive(true); + } + } + else if (vehicleStandardInput.steerInput <= -1) //左 + { + if (turnSignalController.turnSignalState != TurnSignalState.左转向) + { + accidentManager.PlayAnimationSequence("MsgWinAnimOpen", "MsgWinAnimClose"); + accidentManager.uis.transform.Find("UI/转向").gameObject.SetActive(true); + } + } + } } } } \ No newline at end of file