Here's how to play your first audio with Introloop.
First you should license this plugin from Unity's Asset Store. After importing, a folder
Asset/Introloop will appear in your project's Root, along with
Asset/Resources/Introloop/IntroloopPlayer.prefab in your Resources folder. This is the template prefab. It is required to be in Resources folder with this exact name and location so that Introloop can start without any preparation.
After you got an audio that you would like to play we will need 2 time points. The first point is called "Intro Boundary" which is the point that separates an intro from the rest of the song. The 2nd point is "Looping Boundary". When the playhead arrives at this point it will go back to Intro Boundary. Ideally the audio bits after both boundary should sound exactly the same, so you have to be precise here.
If possible you should ask these point directly from your composer, since in the Digital Audio Workstation (DAW) there is a beat grid to snap to and it is a sure fire way to get the exact time!
In this situation you can use a free program like Audacity to find the Intro and Looping Boundary by yourself. Timing might be difficult since there is no snap, but zooming closely to the waveform you should see a meaningful transient that you can match. There is an article from the Audacity team of how to make a looping audio. If you follow the guide and successfully cut a looping part, you have already got 2 time points required for Introloop which is the begining and end point that you cut.
Correct, but you should leave some tail after that boundary anyway (like 1 second) just in case an unexpected lag happen and for small compression artifact. Tell your composer to render a bit more after the planned Looping Boundary.
Next please right click the audio file in Unity, you will notice a new entry Introloop > Create IntroloopAudio. Select it and a new asset file should appear alongside your original audio file.
This is called an
IntroloopAudio file. You will use this file instead of original audio to issue
Play. (But don't delete the original audio file from the project!) Notice that if you click it, there is a custom inspector displayed.
The Audio Clip field has already been connected for you to the file you right clicked. Next, you should enter the Intro Boundary and Looping Boundary time value you got earlier in seconds. You can also set a default volume here which is convenience for balancing music level, since normally Unity cannot store playback volume information in the
AudioClip directly. It's not in the screenshot but starting from v2.0 here you can also set a pitch.
There are 3 playback modes to choose from which you can set per audio. The Introloop mood is the point of this plugin. Loop and Non looping is also provided to play music like Unity normally did with Loop checked and unchecked in
AudioSource respectively. For these 2 modes the boundaries will be disregarded, but you will get Introloop's crossfade, auto audio unloading, etc. benefits.
You can either declare
public IntroloopAudio myIntroloopAudio; in your script to expose the variable and then drag the IntroloopAudio file to the slot, or place the file in Resources folder and dynamically load it via
Resources.Load(string). (not recommended) Either way you will get an instance of type
IntroloopAudio in your script. Next, there is a player that can play this
It uses singleton pattern, so you can simply get it via the static property
IntroloopPlayer.Instance then you can call a method like
You should be able to hear your audio now! Do the same with other audio files. The image below demonstrate a simple class that can choose to play one of many
IntroloopAudio that I have.
The first time reference to
IntroloopPlayer.Instance will create a set of
GameObject named IntroloopPlayer on your scene which will then persist throughout your game. It is made from 4
AudioSource with additional complex scripts that cooperate together to achieve continuous scheduling and looping. You should not have to worry about the inside but in the FAQ section I have explained the inner workings just in case you want to know.
This IntroloopPlayer game object is being cloned from
Assets/Resources/Introloop/IntroloopPlayer.prefab which I call it the template prefab. (It is installed at the same time along with the plugin) Cloning rather than creating allows us to setup a default audio mixer routing in an Inspector.
As explained earlier you should drag your audio mixer group to the template prefab in
Assets/Resources/Introloop/IntroloopPlayer.prefab and the first time
IntroloopPlayer.Instance was called, the settings will also be copied too.
On that template prefab you can find other settings such as default fade length, used when calling method with the word
fadeLengthSeconds argument and even an option to turn on logging.
I recommend you to uncheck Preload Audio Data for all audio you planned to use with Introloop. Since if checked, merely having reference to
IntroloopAudio in any
GameObject's inspector slot will cause the audio to be loaded into memory at scene start even if you are not going to play it yet. (The same happen if you connect a vanilla
AudioClip to the slot with Preload Audio Data checked)