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:

Binary file not shown.

View File

@ -20,12 +20,14 @@ public class FMODEvents : MonoBehaviour
[field: Header("CAR")]
[field: SerializeField] public EventReference DoorOpen { get; private set; }
[field: SerializeField] public EventReference DoorClose { get; private set; }
[field: SerializeField] public EventReference CarModulatedDriving { get; private set; }
[field: Header("UI")]
[field: SerializeField] public EventReference Click { get; private set; }
[field: SerializeField] public EventReference MapOpen { get; private set; }
[field: SerializeField] public EventReference Hover { get; private set; }
[field: SerializeField] public EventReference LetterEnter { get; private set; }
[field: SerializeField] public EventReference LetterHover { get; private set; }
[field: Header("Initial events")]
[field: SerializeField] public EventReference PortalSpacial { get; private set; }

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<objects serializationModel="Studio.02.03.00">
<object class="AudioFile" id="{9eaeebc1-c010-44b0-9fa7-19a155286115}">
<object class="AudioFile" id="{f08195f0-52fa-42ed-9119-6f6530f5a576}">
<property name="assetPath">
<value>Vehicles, Electric, Car, Tesla, Model 3, Idle, Engine Compartment 03 SND66189.wav</value>
<value>Vehicles, Electric, Car, Tesla, Model 3, Idle, Engine Compartment 03 SND66189 7.wav</value>
</property>
<property name="isStreaming">
<value>true</value>
@ -14,7 +14,7 @@
<value>2</value>
</property>
<property name="length">
<value>16.656541666666666</value>
<value>13.224645833333334</value>
</property>
<relationship name="masterAssetFolder">
<destination>{0fbc34f9-6022-42da-8b3b-f18344a8ea0f}</destination>

View File

@ -97,6 +97,9 @@
</relationship>
</object>
<object class="EventMixerMaster" id="{f65a5ce4-c06c-46df-9a06-859ff71e3316}">
<property name="overridingInputFormat">
<value>1</value>
</property>
<relationship name="automators">
<destination>{577898e3-8d39-419b-8a71-df165b29fdb3}</destination>
</relationship>
@ -165,7 +168,7 @@
</object>
<object class="EventMixerGroup" id="{d606328d-d47d-42d7-8be4-de72450a50d8}">
<property name="volume">
<value>-7.5</value>
<value>1</value>
</property>
<property name="name">
<value>Audio 1</value>
@ -426,7 +429,7 @@
<value>ApplyDA</value>
</property>
<property name="value">
<value>2</value>
<value>1</value>
</property>
<property name="minimumValue">
<value>0</value>
@ -454,7 +457,7 @@
<value>ApplyDir</value>
</property>
<property name="value">
<value>2</value>
<value>1</value>
</property>
<property name="minimumValue">
<value>0</value>
@ -814,10 +817,10 @@
</object>
<object class="AutomationPoint" id="{c22d4e22-49ba-4f40-b2ef-ddc8dd15ce81}">
<property name="position">
<value>1</value>
<value>0.81000000000000005</value>
</property>
<property name="value">
<value>65</value>
<value>20</value>
</property>
</object>
<object class="AutomationPoint" id="{56dbb96b-e49d-4a8b-a678-97662e9bd824}">

View File

@ -415,7 +415,7 @@
<value>ApplyDA</value>
</property>
<property name="value">
<value>2</value>
<value>1</value>
</property>
<property name="minimumValue">
<value>0</value>

View File

@ -89,14 +89,26 @@
</object>
<object class="MixerBusPanner" id="{3e854fc1-ef39-4841-82a1-28333142fdfa}" />
<object class="SingleSound" id="{1db0440c-6a8a-470f-850a-d2fd0dd070cb}">
<property name="length">
<value>3.6240000000000001</value>
<property name="start">
<value>1.4000000000000001</value>
</property>
<property name="length">
<value>1.3899999999999999</value>
</property>
<property name="timelockedOffset">
<value>1.4600000000000002</value>
</property>
<relationship name="fadeInCurve">
<destination>{111a1b6f-a8ed-41dc-b6a8-69d90e344aff}</destination>
</relationship>
<relationship name="audioFile">
<destination>{e5c8c7bf-afb1-4055-a1b0-a2c3f583f42c}</destination>
</relationship>
</object>
<object class="EventMixerGroup" id="{b8ab8648-8ab9-4b07-a6af-76d508502d9c}">
<property name="volume">
<value>-12.5</value>
</property>
<property name="name">
<value>Audio 1</value>
</property>
@ -118,6 +130,14 @@
</object>
<object class="MixerBusPanner" id="{8c9b02e7-f90b-4752-a4e4-83ee09e606aa}" />
<object class="MixerBusFader" id="{dd2e9fd6-8bd5-4eb8-b8ce-47de21bb361a}" />
<object class="FadeCurve" id="{111a1b6f-a8ed-41dc-b6a8-69d90e344aff}">
<relationship name="startPoint">
<destination>{87542ae9-e834-42d6-b53e-cf380095bc2c}</destination>
</relationship>
<relationship name="endPoint">
<destination>{d80a7e09-dd1f-41d9-90aa-23da2eca0c0e}</destination>
</relationship>
</object>
<object class="MixerBusEffectChain" id="{05f7269b-c6ed-40fa-bf0d-0e876d16211a}">
<relationship name="effects">
<destination>{553d7eb6-4fc1-4128-b274-2710e4417f56}</destination>
@ -126,5 +146,24 @@
<object class="MixerBusPanner" id="{f60beb25-525d-4fc6-b87c-9a879e4d76c0}" />
<object class="MixerBusFader" id="{3736e3ae-7ec8-45fc-8a21-17a45aa7e86a}" />
<object class="SpatialiserEffect" id="{e2c1f77e-3ab7-4be7-bdbd-65a35dcc99c5}" />
<object class="AutomationPoint" id="{87542ae9-e834-42d6-b53e-cf380095bc2c}">
<property name="position">
<value>1.4000000000000001</value>
</property>
<property name="value">
<value>0</value>
</property>
<property name="curveShape">
<value>-0.220267966</value>
</property>
</object>
<object class="AutomationPoint" id="{d80a7e09-dd1f-41d9-90aa-23da2eca0c0e}">
<property name="position">
<value>1.4600000000000002</value>
</property>
<property name="value">
<value>1</value>
</property>
</object>
<object class="MixerBusFader" id="{553d7eb6-4fc1-4128-b274-2710e4417f56}" />
</objects>

View File

@ -37,7 +37,6 @@
<relationship name="parameters">
<destination>{94ac9330-6c0b-421a-b3ab-8fe75d998e5d}</destination>
<destination>{117ce9aa-a267-47a1-b0ef-0042e96b99a8}</destination>
<destination>{2713ce2d-100c-41d4-985a-d3867f5d58e0}</destination>
</relationship>
<relationship name="banks">
<destination>{9d1145b0-e099-4ee4-ab1d-23cc274af901}</destination>
@ -70,7 +69,11 @@
<destination>{7ec75b45-6865-4d1b-bfab-f8e3ca952cf8}</destination>
</relationship>
</object>
<object class="EventAutomatableProperties" id="{01a7c570-5ee5-451c-b338-2928032226a4}" />
<object class="EventAutomatableProperties" id="{01a7c570-5ee5-451c-b338-2928032226a4}">
<property name="maximumDistance">
<value>30</value>
</property>
</object>
<object class="MarkerTrack" id="{831858f0-f689-4710-9a40-3246f1e5b327}" />
<object class="GroupTrack" id="{55bdfbf8-a2dd-4cc5-86c7-80692745b042}">
<relationship name="modules">
@ -90,7 +93,7 @@
</object>
<object class="GroupTrack" id="{3d7ce8f4-7410-4f5c-b929-d83426361e39}">
<relationship name="modules">
<destination>{b1566735-f30a-4149-b6df-61e3a48e06be}</destination>
<destination>{824fb99e-7e5f-4ef4-8601-72fea554b368}</destination>
</relationship>
<relationship name="mixerGroup">
<destination>{da10e6fc-66e6-44ac-b520-558594949a15}</destination>
@ -113,8 +116,8 @@
<relationship name="modules">
<destination>{36301cbf-6264-435e-9b58-1a68610df7e6}</destination>
<destination>{c7b9e72f-b880-4a15-81d4-5a2dcae36f8f}</destination>
<destination>{b1566735-f30a-4149-b6df-61e3a48e06be}</destination>
<destination>{193251eb-f70e-4eb8-9d6e-7fa209353b5f}</destination>
<destination>{824fb99e-7e5f-4ef4-8601-72fea554b368}</destination>
</relationship>
<relationship name="preset">
<destination>{a9a726c5-2680-484a-916a-fa6ab1499915}</destination>
@ -125,12 +128,10 @@
<destination>{7f93562b-4c20-4f1d-9c68-6a145d8afb6d}</destination>
</relationship>
</object>
<object class="ParameterProxy" id="{2713ce2d-100c-41d4-985a-d3867f5d58e0}">
<relationship name="preset">
<destination>{c6ed1c8a-6317-4b6e-9c2f-a9de5d998f05}</destination>
</relationship>
</object>
<object class="EventMixerMaster" id="{11d0567a-a4de-4fe0-9531-f883ee95423b}">
<property name="volume">
<value>4</value>
</property>
<relationship name="effectChain">
<destination>{26251485-8b8f-4259-bc84-5fbf400ec338}</destination>
</relationship>
@ -175,7 +176,7 @@
<value>1000</value>
</property>
<property name="pitch">
<value>-2</value>
<value>1.20000005</value>
</property>
<property name="looping">
<value>true</value>
@ -192,7 +193,7 @@
</object>
<object class="EventMixerGroup" id="{a600a068-0e8a-488c-b911-1f7c6baf5ba6}">
<property name="volume">
<value>-6.5</value>
<value>-10</value>
</property>
<property name="name">
<value>Engine1</value>
@ -235,7 +236,7 @@
</object>
<object class="EventMixerGroup" id="{d9d0ff11-95d8-430d-921a-2b6e7fc08bc7}">
<property name="volume">
<value>-6.5</value>
<value>-6</value>
</property>
<property name="name">
<value>Engine2</value>
@ -250,39 +251,32 @@
<destination>{11d0567a-a4de-4fe0-9531-f883ee95423b}</destination>
</relationship>
</object>
<object class="SingleSound" id="{b1566735-f30a-4149-b6df-61e3a48e06be}">
<object class="SingleSound" id="{824fb99e-7e5f-4ef4-8601-72fea554b368}">
<property name="isCutoff">
<value>true</value>
</property>
<property name="start">
<value>900</value>
<value>866.52313232421875</value>
</property>
<property name="length">
<value>1300</value>
</property>
<property name="startOffset">
<value>5</value>
</property>
<property name="name" />
<property name="pitch">
<value>-0.5</value>
</property>
<property name="looping">
<value>true</value>
</property>
<relationship name="modulators">
<destination>{0635810e-9df9-4892-bf4e-e262cf200b79}</destination>
<destination>{ca2aa301-412b-4ba7-a293-4505fc14421d}</destination>
</relationship>
<relationship name="fadeInCurve">
<destination>{c4be0190-cfaa-4725-b21f-fb62e08011dc}</destination>
<destination>{ea9a2afc-2e36-4147-a29b-11acec5e67a2}</destination>
</relationship>
<relationship name="audioFile">
<destination>{75f44b88-35d2-4043-8391-c10116f2c707}</destination>
<destination>{f08195f0-52fa-42ed-9119-6f6530f5a576}</destination>
</relationship>
</object>
<object class="EventMixerGroup" id="{da10e6fc-66e6-44ac-b520-558594949a15}">
<property name="volume">
<value>-13</value>
<value>-11</value>
</property>
<property name="name">
<value>Tires</value>
@ -302,12 +296,11 @@
<value>true</value>
</property>
<property name="start">
<value>900</value>
<value>866.52313232421875</value>
</property>
<property name="length">
<value>1300</value>
</property>
<property name="name" />
<relationship name="modulators">
<destination>{c56c0d73-e43c-4a99-93a7-274e2134fe4a}</destination>
</relationship>
@ -320,7 +313,7 @@
</object>
<object class="EventMixerGroup" id="{0269f0e3-c25f-495c-ba7e-6f9a85fd2aaf}">
<property name="volume">
<value>-16</value>
<value>-19.5</value>
</property>
<property name="name">
<value>Tires</value>
@ -389,20 +382,23 @@
</relationship>
</object>
<object class="MixerBusPanner" id="{057c1d11-ed55-4327-aba2-9e85d37f6623}" />
<object class="AutopitchModulator" id="{0635810e-9df9-4892-bf4e-e262cf200b79}">
<object class="AutopitchModulator" id="{ca2aa301-412b-4ba7-a293-4505fc14421d}">
<property name="nameOfPropertyBeingModulated">
<value>pitch</value>
</property>
<property name="root">
<value>3650</value>
<value>5000</value>
</property>
<property name="pitchAtMinimum">
<value>0.104999997</value>
</property>
</object>
<object class="FadeCurve" id="{c4be0190-cfaa-4725-b21f-fb62e08011dc}">
<object class="FadeCurve" id="{ea9a2afc-2e36-4147-a29b-11acec5e67a2}">
<relationship name="startPoint">
<destination>{25fd1d63-74f7-49ec-a025-968572352e6f}</destination>
<destination>{285b0f69-7d07-463d-8fd7-c011d6c84260}</destination>
</relationship>
<relationship name="endPoint">
<destination>{ccda9bd9-8fb3-49d7-ba2d-5a8d01c1367d}</destination>
<destination>{6ea1b1be-1b88-41d4-aef4-73f0f83ada89}</destination>
</relationship>
</object>
<object class="MixerBusEffectChain" id="{7d30f8f1-daff-400c-9b32-c6c789fc5c6e}">
@ -417,7 +413,7 @@
<value>pitch</value>
</property>
<property name="root">
<value>2100</value>
<value>1750</value>
</property>
<property name="pitchAtMinimum">
<value>0.745000005</value>
@ -465,7 +461,7 @@
</object>
<object class="AutomationPoint" id="{760f4370-fa66-4299-ab80-74c0f7cf474a}">
<property name="position">
<value>850</value>
<value>866.52313232421875</value>
</property>
<property name="value">
<value>1</value>
@ -485,13 +481,13 @@
<object class="MixerBusFader" id="{33e852a7-e7df-40fb-90b5-7ccb84842783}" />
<object class="AutomationPoint" id="{99f393c2-34b1-4815-b583-79ad543de401}">
<property name="position">
<value>900</value>
<value>866.52313232421875</value>
</property>
<property name="value">
<value>1</value>
</property>
<property name="curveShape">
<value>0.25471893</value>
<value>0.203604177</value>
</property>
</object>
<object class="AutomationPoint" id="{c81f9cd7-d130-40dc-8809-80f551762262}">
@ -503,18 +499,18 @@
</property>
</object>
<object class="MixerBusFader" id="{9948c96d-f4ed-4f3f-9ad5-8d42784f5cbc}" />
<object class="AutomationPoint" id="{25fd1d63-74f7-49ec-a025-968572352e6f}">
<object class="AutomationPoint" id="{285b0f69-7d07-463d-8fd7-c011d6c84260}">
<property name="position">
<value>900</value>
<value>866.52313232421875</value>
</property>
<property name="value">
<value>0</value>
</property>
<property name="curveShape">
<value>-0.2547189</value>
<value>-0.203604087</value>
</property>
</object>
<object class="AutomationPoint" id="{ccda9bd9-8fb3-49d7-ba2d-5a8d01c1367d}">
<object class="AutomationPoint" id="{6ea1b1be-1b88-41d4-aef4-73f0f83ada89}">
<property name="position">
<value>1000</value>
</property>
@ -536,18 +532,18 @@
</object>
<object class="AutomationPoint" id="{01c20889-6721-40bc-b3d9-337716305643}">
<property name="position">
<value>900</value>
<value>866.52313232421875</value>
</property>
<property name="value">
<value>0</value>
</property>
<property name="curveShape">
<value>-0.2547189</value>
<value>-0.203604087</value>
</property>
</object>
<object class="AutomationPoint" id="{01e7b796-a9a0-48ef-a286-b424e5c98487}">
<property name="position">
<value>1200</value>
<value>1000</value>
</property>
<property name="value">
<value>1</value>

View File

@ -328,7 +328,7 @@
<value>ApplyDA</value>
</property>
<property name="value">
<value>2</value>
<value>1</value>
</property>
<property name="minimumValue">
<value>0</value>
@ -356,7 +356,7 @@
<value>ApplyDir</value>
</property>
<property name="value">
<value>0</value>
<value>1</value>
</property>
<property name="minimumValue">
<value>0</value>

View File

@ -27,7 +27,13 @@
<value>cursorPosition</value>
</property>
<property name="speedAscending">
<value>0.17999999225139618</value>
<value>0.079999998211860657</value>
</property>
<property name="speedDescending">
<value>0.059999998658895493</value>
</property>
<property name="asymmetric">
<value>true</value>
</property>
</object>
</objects>

View File

@ -13,7 +13,7 @@
</object>
<object class="GameParameter" id="{fb894807-eb7f-48db-b3de-e2f5dd3322a2}">
<property name="initialValue">
<value>1</value>
<value>0</value>
</property>
<relationship name="modulators">
<destination>{a1523d7a-fecc-424f-8e27-bd2c5cb9a80f}</destination>

View File

@ -16,7 +16,7 @@
<value>-1</value>
</property>
<property name="initialValue">
<value>-1</value>
<value>-0.5</value>
</property>
</object>
</objects>