Example #1
0
    public AudioClip LoadAudioClip(string resourcePath)
    {
        resourcePath = prefix + resourcePath;

        AudioClip audioClip;

        if (audioClips.ContainsKey(resourcePath))
        {
            audioClip = audioClips[resourcePath];
        }
        else
        {
            audioClip = Resources.Load(resourcePath) as AudioClip;

            if (audioClip == null)
            {
                TODebug.Log("FXManager couldn't find sound at: " + resourcePath);
                return(null);                //can't play the sound because we can't find it!
            }
            else
            {
                audioClips[resourcePath] = audioClip;
            }
        }

        return(audioClip);
    }
Example #2
0
    public AudioClip LoadAudioClip(string resourcePath)
    {
        resourcePath = prefix + resourcePath;

        for (int a = 0; a < audioClipInfos.Count; a++)
        {
            AudioClipInfo clipInfo = audioClipInfos[a];

            if (clipInfo.resourcePath == resourcePath)
            {
                //make sure this clip is at the top of the stack now
                audioClipInfos.RemoveAt(a);
                audioClipInfos.Add(clipInfo);
                return(clipInfo.clip);
            }
        }

        AudioClip audioClip = Resources.Load(resourcePath) as AudioClip;

        if (audioClip == null)
        {
            TODebug.Log("MusicManager couldn't find music at: " + resourcePath);
            return(null);            //can't play the sound because we can't find it!
        }

        AudioClipInfo newClipInfo = new AudioClipInfo();

        newClipInfo.clip         = audioClip;
        newClipInfo.resourcePath = resourcePath;

        audioClipInfos.Add(newClipInfo);

        while (audioClipInfos.Count > NUM_CLIPS_TO_CACHE)
        {
            AudioClipInfo clipInfoToRemove = audioClipInfos[0];
            Resources.UnloadAsset(clipInfoToRemove.clip);
            audioClipInfos.RemoveAt(0);
        }

        return(newClipInfo.clip);
    }