car's sound was updated: fmod modulation, integration into Unity and fixing the overall sound through a different script
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bfb4dce81082ebf46801139bdb2ce8ad
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user