Sign Up | Login | Log in with:

Custom A/V Processing

Dec 12, 2016

Unity is a pretty nice game engine. The license is reasonable, the out-of-the-box functionality is solid, and there are constant improvements being made.

A particularly winning aspect (which is not unique to Unity mind you) is that it is completely customizable through editor scripting - if there's functionality that you need, and it isn't there, you can add it.

This falls somewhat short when it comes to runtime importing, and due to Unity's methodology (pre-import assets and pack them on build), this makes sense.

For Roll Out though, it posed a challenge. For those of you who don't know, Roll Out is designed around runtime-loaded modules, which create the buildings, items, and encounters you may run into while playing the game. Unity has some solid support for loading other types of assets such as textures.

Unity has a solid audio importer, but it only is available in the editor. All of its support is disabled (or encapsulated to be unavailable at least) in a compiled application. For Roll Out's modular setup, audio needs to be able to be loaded at runtime when the modules are being loaded.

To add slightly to the complexity, these audio files are also contained in a zip file. The architecture is there in the engine that will convert this to a decompressed byte stream in memory, so all that was left was to convert it into an audio format and inject it into an AudioClip...simple, right?

It actually wasn't too bad. Once the file format is deciphered, the headers can be read. They tell everything about the file, such as bitrate, channels, and a couple other things. Take a look at whether the encoding was done in a Litte Endian or Big Endian system, shuffle things around accordingly, apply a little bit of bitmasking and you more or less have your raw audio data.

However, because Unity wasn't designed to be able to load audio at runtime, creating an AudioClip is a little more tricky. You need to convert the raw audio data into something that the engine expects, so you're more or less recreating the importer's functionality.

Bottom line is, it is in fact possible, and it's working! At the moment it only supports WAV files, but the plan is to expand that to include OGG and possibly other formats as well.

In addition to that, support has been added for runtime slicing of images. What this means is that sprite sheets can be loaded in through the editor and with a few simple options be added into the game as an animated sprite. An example of this functionality can be seen here (opens in a new tab).

As for the continued development of Roll Out itself, the game management code is also nearing completion. It tracks progress through the game, as well as state management. It's mostly behind the scenes stuff, so there isn't much to show in terms of screenshots.

Comments (0)

Add a Comment

Please login to comment.