Beispiel #1
0
    public void PlayLoop(int soundID, Surface.Substance substance, Surface.Cue cue, float volume,
                         Vector3 position = new Vector3(), Transform transformToFollow = null)
    {
        if (loopSoundEventDict.ContainsKey(soundID))
        {
            //we've already created our loop, so merely update it with the current volume
            if (loopSoundEventDict[soundID] != null)
            {
                loopSoundEventDict[soundID].volume = volume;
            }
        }
        else
        {
            //Debug.Log("new loop created.");
            //TODO: Check the type of substance and only create a new AudioSource for new types of sounds

            //create entry for our looped sound so we can end it later
            GameObject go = new GameObject(substance + ":" + cue);
            SoundEvent se = go.AddComponent <SoundEvent>();
            se.Initialize(surfaceDataDict[substance].GetSound(cue), SoundEvent.Category.Loop);

            if (transformToFollow != null)
            {
                //if we are following a transform position, the position should be ignored
                se.SetFollowTransform(transformToFollow);
            }
            else
            {
                se.SetPosition(position);
            }
            se.volume = volume;
            loopSoundEventDict.Add(soundID, se);
            loopSoundEventDict[soundID].Play();
        }
    }
Beispiel #2
0
 public void PlayOneShot(Surface.Substance substance, Surface.Cue cue, float volume, Vector3 position)
 {
     if (surfaceDataDict.ContainsKey(substance))
     {
         GameObject go = new GameObject(substance + ":" + cue);
         SoundEvent se = go.AddComponent <SoundEvent>();
         se.Initialize(surfaceDataDict[substance].GetSound(cue), SoundEvent.Category.OneShot);
         se.SetPosition(position);
         se.volume = volume;
         se.Play();
     }
 }