Sound

FMOD is used for all sounds in the project.

Installation

  1. Download the FMOD plugin from the Asset Store.

  2. Add the FMOD scripting define to the project.

  3. Select the project FMOD path in the window that appears on the Linking tab (by default DotsCity/FMOD/fmodproject/fmodproject.fspro).

    _images/FMOD-setup.png
  4. Sign up & download the FMOD Studio software from the official site (official guide).

    _images/FMODstudio-download.png
  5. Open FMOD settings.

    _images/FMOD-toolbar-settings.png
  6. By default, project path: FMOD project path DotsCity/FMOD/fmodproject/fmodproject.fspro, make sure that the FMOD project path is set correctly.

    _images/FMOD-settings.png

How To Use

  1. Open FMOD Studio installed on your computer.

    _images/FMOD-Studio-mainwindow.png
  2. Open Bank bookmark.

    _images/FMOD-Studio-bankwindow.png
  3. If you do not have an existing bank or need to create a new one, right-click in the window and press New Bank.

  4. In the bookmark Events - Create or open exist folder.

    _images/FMOD-Studio-eventswindow.png
  5. Right-click on the created folder and press Create Event, rename created event.

    _images/FMOD-Studio-NewEventExample.png
  6. Right-click on Add Timeline Sheet in the created event.

    _images/FMOD-Studio-NewTimelineExample.png _images/FMOD-Studio-NewTimelineExample2.png
  7. Drag and drop the desired sound into the timeline.

    _images/FMOD-Studio-DragNDropTimelineExample.png
  8. Customize your sound.

  9. Assign the selected FMOD event to the Bank.

    _images/FMOD-Studio-AssignToBankExample.png
  10. Build FMOD project.

    _images/FMOD-Studio-BuildExample.png
  11. Create Sound Data in the Unity project.

    _images/SoundDataCreation.png
  12. Enter trigger name event:/Vehicle/TestExample.

    _images/SoundDataExample2.png

    Note

    Sound ID is created automatically.

  13. Press Add To Service button to add sound to the FMOD sound service.

    _images/FMOD-SoundServiceAddedExample.png
  14. Now, we can trigger the sound from the code.

Sound Data

Contains data about the FMOD sound.

How To Create

Select from the project context menu:

Spirit604/City/Sound/Sound Data

_images/SoundDataCreation.png

Settings

_images/SoundDataExample.png
Id : immutable ID, by which sounds are triggered in DOTS traffic city (ID is created automatically).
Name : event name of the sound.
Parameters : event parameters .

FMOD Sound Service

Contains data on all sounds in the Unity project.

_images/FMOD-SoundServiceExample.png

Warning

If you do not add sound to the service, it cannot be activated from the code.

Code Examples

Sound Types

  • Default : default sound entity.

  • One Shot : entity played once & destroyed afterwards.

  • Tracking : entity tracks target entity.

  • Tracking Vehicle : entity tracks target vehicle entity.

  • Tracking And Loop : entity tracks target entity & loop playback.

How To Create

EntityManager methods

SoundExtension.CreateSoundEntity(ref this EntityManager entityManager, int soundId, float volume = 1f)
// Creating a default sound entity.
SoundExtension.CreateTrackedSoundEntity(ref this EntityManager entityManager, int soundId, Entity parentEntity, float volume = 1f)
// Creation of a sound entity that follows a given entity.
SoundExtension.CreateChildSoundEntity(ref this EntityManager entityManager, int soundId, Entity parentEntity, float volume = 1f)
// Creation of a sound entity that will be a child of a given entity.

CommandBuffer methods

Burst compatible methods.

SoundExtension.CreateSoundEntity(ref this EntityCommandBuffer commandBuffer, Entity soundPrefabEntity, int soundId, float volume = 1f)
// Creating a default sound entity.
SoundExtension.CreateSoundEntity(ref this EntityCommandBuffer commandBuffer, Entity soundPrefabEntity, int soundId, float3 position, float volume = 1f)
// Create a sound entity at a specific position.

Create prefab query method

SoundExtension.GetSoundQuery(EntityManager entityManager, SoundType soundType)
// Get `EntityQuery` with the selected `Sound type`.

Params

  • soundId : id of sound taken from sound data.

  • soundPrefabEntity : sound prefab entity taken from EntityQuery.

  • position : initial position of the sound.

  • volume : volume of the sound (0..1 range).

How To Play

public partial class PlayAndStopSoundExampleSystem : SystemBase
{
protected override void OnUpdate()
{

// Get world sounds
var sounds = GetComponentLookup<FMODSound>(true);

Entities
.WithBurst()
.WithReadOnly(sounds)
.ForEach((
        Entity entity
        in SoundHolder soundHolder) =>
{
        // Some play condition
        bool shouldPlay = true;

        // Some sound entity container component
        Entity soundEntity = soundHolder.Entity

        FMODSound fmodSound = sounds[soundEntity];

        if (shouldPlay)
        {
                fmodSound.Event.start();
        }
        else
        {
                fmodSound.Event.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
        }

}).Schedule();
}
}

How To Destroy

Add the PooledEventTag component to the sound entity.

How To Loop

  1. Create a Sound entity.

  2. Add a LoopSoundData component (assign a Duration value).