car's sound was updated: fmod modulation, integration into Unity and fixing the overall sound through a different script

This commit is contained in:
Timur Nizamov
2025-11-29 18:53:11 +02:00
parent 1727379952
commit bcf7e3121d
50 changed files with 184 additions and 97 deletions

View File

@@ -1,9 +1,9 @@
using FishNet.Object;
using FMOD.Studio;
using System.Collections;
using System.Collections.Generic;
using Unity.XR.CoreUtils;
using UnityEngine;
using FMOD.Studio;
using static MouseLook;
public class CarDrivingRoutine : NetworkBehaviour
@@ -25,37 +25,12 @@ public class CarDrivingRoutine : NetworkBehaviour
public List<GameObject> FrontTires;
public List<GameObject> BackTires;
private EventInstance CarMovement;
private FirstPersonOcclusion occlusion;
private void Awake()
{
//Debug.LogError("AUDIO MANAGER:");
//Debug.LogError(AudioManager.Instance);
//Debug.LogError("FMOD EVENTS INSTANCE:");
//Debug.LogError(FMODEvents.Instance);
//Debug.LogError("Car Simple Driving:");
//Debug.LogError(FMODEvents.Instance.BoltCarSimpleDriving);
CarMovement = AudioManager.Instance.CreateInstance(FMODEvents.Instance.BoltCarSimpleDriving); //initialising the variable
CarMovement.setParameterByName("EasyBoltLogic", 0); //"Driving - 0 in FMOD"
CarMovement.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(gameObject)); //setting 3d attributes
occlusion = GetComponent<FirstPersonOcclusion>();
if (occlusion != null)
{
occlusion.InitialiseWithInstance(CarMovement);
}
}
public CarAudioController AudioController;
private void Start()
{
targetSpeed = StraightSpeed;
targetRotationSpeed = rotationSpeed;
CarMovement.start(); //starting the car sound here
AudioManager.Instance.SetGlobalParameter("CarPassengerLogic", 0.0f); //change the value of the global parameter in FMOD, initial value
}
// Update is called once per frame
@@ -80,6 +55,7 @@ public class CarDrivingRoutine : NetworkBehaviour
{
if (!isTurning)
{
AudioController.SetRPM(1300); //set externally in CarAudioController.cs
setTireRotation(tireTurnAngle);
}
@@ -89,6 +65,7 @@ public class CarDrivingRoutine : NetworkBehaviour
{
if (isTurning)
{
AudioController.SetRPM(1450);
setTireRotation(-tireTurnAngle);
}
@@ -102,8 +79,6 @@ public class CarDrivingRoutine : NetworkBehaviour
// Proceed to the next waypoint
_waypoint = _waypoint.Next;
}
CarMovement.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(gameObject)); //updating the attributes
}
private void rollTires()
@@ -138,7 +113,8 @@ public class CarDrivingRoutine : NetworkBehaviour
_tireSound.Stop();
_stopSound.Play();
CarMovement.setParameterByName("EasyBoltLogic", 1);
AudioController.SetRPM(475);
AudioController.PlayStopSound();
}
@@ -149,8 +125,8 @@ public class CarDrivingRoutine : NetworkBehaviour
_stopSound.Stop();
_tireSound.Play();
CarMovement.setParameterByName("EasyBoltLogic", 0);
CarMovement.start();
AudioController.SetRPM(1450);
}
private IEnumerator SmoothAdjustSpeed(float targetStraightSpeed, float targetRotationSpeed, float duration)

View File

@@ -0,0 +1,54 @@
using UnityEngine;
using FMOD.Studio;
public class CarAudioController : MonoBehaviour
{
private EventInstance carMovementInstance;
private FirstPersonOcclusion occlusion;
private void Awake()
{
//Debug.LogError("AUDIO MANAGER:");
//Debug.LogError(AudioManager.Instance);
//Debug.LogError("FMOD EVENTS INSTANCE:");
//Debug.LogError(FMODEvents.Instance);
//Debug.LogError("Car Simple Driving:");
//Debug.LogError(FMODEvents.Instance.BoltCarSimpleDriving);
carMovementInstance = AudioManager.Instance.CreateInstance(FMODEvents.Instance.CarModulatedDriving);
carMovementInstance.setParameterByName("RPM", 1450);
carMovementInstance.setParameterByName("Load", 0);
carMovementInstance.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(gameObject));
occlusion = GetComponent<FirstPersonOcclusion>();
if (occlusion != null)
occlusion.InitialiseWithInstance(carMovementInstance);
}
private void Start()
{
carMovementInstance.start();
AudioManager.Instance.SetGlobalParameter("CarPassengerLogic", 0.0f); //change the value of the global parameter in FMOD, initial value
}
private void Update()
{
// Always update 3D position to follow the car model transform
carMovementInstance.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(gameObject));
}
// These methods are called externally by CarDrivingRoutine
public void SetRPM(float value)
{
carMovementInstance.setParameterByName("RPM", value);
}
public void PlayStopSound()
{
carMovementInstance.getParameterByName("RPM", out float currentRPM);
if (currentRPM == 475)
{
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.BoltCarStopSound, gameObject);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bfb4dce81082ebf46801139bdb2ce8ad
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: