maanantai 3. lokakuuta 2016

Unity basics - sounds

NAV15AP

2. jakso lukuvuonna 2016-2017

Sounds are important element in games. It can be the key in setting the mood, telling story and giving feedback to the player. That is why it’s important to plan and produce sounds with great care. The direction of the sound is especially important in 3D games because it can indicate important places and events. Audio should change according to the place where player is eg. if player is passing through a cave then the audio should have an echo. This time you’re going to learn how to import sounds to Unity and how to mute those sounds using two different methods. Check out this video in which Anna Kipnis from Double Fine Games talks about dialog systems in their games: https://www.youtube.com/watch?v=o76JAP_9GkA It covers topics such as writing and implementing the dialog and what is required to make it happen.

Unity supports most common audio file types such as mp3, wav, ogg and aiff. These can be imported to the project like any other asset by just dragging and dropping. After you have imported your audio file it’s time to take a look at its settings.

From the inspector you can select multiple options that have impact on the audio quality, memory usage and efficiency. I suggest you read this article about how to increase the performance of your Unity game: http://www.paladinstudios.com/2012/07/30/4-ways-to-increase-performance-of-your-unity-game/ In the article there is valuable information about audio optimizing.  The key points are which type of load type to select for different sounds to make the game run as smoothly and efficiently as possible:
      • Short sound effects – Decompress on load uses ten times more memory than keeping files compressed in memory so use this with only small files
      • Longer or looping sound effects – Compressed in memory when decompression on load would use too much memory
      • Game music – Streaming because streaming uses the least amount of memory to buffer compressed data

The compression format is basically the sound quality:
      •        PCM – short sound effects, quality is great but file size is large
      •         Vorbis/MP3 – music and longer sound effects, file size is smaller but the quality suffers a bit
      •        ADPCM – sounds that need to be played in large quantities eg. footsteps and impacts, compression ratio is smaller than in PCM but CPU usage is smaller than in Vorbis


After you have imported and chosen right settings for the audio file it’s time to learn how to mute it using playmaker.


You’ll need two icons for sound on/off. Create atlas from these two assets. After atlas is created you can use the icons as sprites from the NGUI tab. Create sprites from there and make sure they are placed on top of each other in the scene. Deactivate the mute icon from inspector by clicking the small box to the left from sprite name. Leave the normal sound icon activated.


Create FSM that control sounds. This can be done with empty game object. Place it where you have the icons for sounds. Use normal box collider that is the same size as sound sprites. In the FSM you need two states which have the same mouse down transition event.




Then you’ll need three actions in each state. Two activate game object actions in which you choose sound on and sound off sprites. In the first state put checkmark in the sound on sprite activate section and leave the section clear for sound off sprite. Then set property for your audio source component. Select mute as the property and leave set value section clear.



The second state is similar to the first. In it you’ll need to activate the sound off sprite and deactivate the sound on sprite. Also set property for your audio source component and again select mute as property and put checkmark in the set value section. 


Ei kommentteja:

Lähetä kommentti