示例#1
0
 public void Update()
 {
     t = 0;
     foreach (var sound in sounds)
     {
         AudioSource aSource = sound.Key;
         if (sound.Value.doesLoop)
         {
             SoundDefinition musicDefinition = sound.Value;
             t = (double)aSource.timeSamples / (double)aSource.clip.frequency;
             if (t >= musicDefinition.loopPoint)
             {
                 aSource.Play();
                 aSource.timeSamples = (int)(musicDefinition.loopBackTo * ((double)aSource.clip.frequency));
             }
         }
         else
         {
             if (aSource.time > aSource.clip.length)
             {
                 Stop(aSource);
             }
         }
     }
 }
示例#2
0
 public static bool IsPlaying(SoundDefinition sound)
 {
     foreach (AudioSource audio in sounds.Keys)
     {
         if (sounds[audio] == sound)
         {
             return(true);
         }
     }
     return(false);
 }
示例#3
0
        public static GameObject Play(SoundDefinition sound, float startTime = 0, Transform parent = null)
        {
            if (!sound)
            {
                return(null);
            }
            GameObject go = new GameObject(sound.name);

            go.transform.SetParent(parent);
            AudioSource aSource = go.AddComponent <AudioSource>();

            aSource.clip   = sound.sound;
            aSource.volume = sound.volume;
            aSource.loop   = sound.doesLoop;
            aSource.outputAudioMixerGroup = sound.mixerGroup;
            aSource.time = startTime == 0 ? sound.startTime : startTime;
            aSource.Play();
            sounds.Add(aSource, sound);
            return(go);
        }