Example #1
0
    // Asynchronous loading to improve game load times
    IEnumerator PreloadAudioClip(AudioFile audioFile)
    {
        ResourceRequest request = AudioLoader.GetClipAsync(audioFile.Name);

        while (!request.isDone)
        {
            if (audioFile.ClipIsSet())
            {
                yield break;
            }
            yield return(new WaitForEndOfFrame());
        }
        if (!audioFile.ClipIsSet())
        {
            try {
                audioFile.SetClip((AudioClip)request.asset);
            } catch (Exception e) {
                Debug.LogError(e + ": " + request.asset + " is not a valid AudioClip");
            }
        }
    }