示例#1
0
 private void Awake()
 {
     //------------------------------------------------------
     //Erstelle eine Instanz falls nicht vorhanden
     //------------------------------------------------------
     if (Instance == null)
     {
         Instance = this;
     }
     //------------------------------------------------------
     //Oder lösche falls diese Instanz nicht die Instanz ist
     //------------------------------------------------------
     else if (Instance != this)
     {
         Destroy(this);
     }
     //------------------------------------------------------
     //Füge eine Standartsource hinzu
     //------------------------------------------------------
     m_MustnPlay = SoundUtilities.AddSourceToObject(gameObject, false, 1.0f, false);
     //------------------------------------------------------
     //Starte Cleanup Routine
     //------------------------------------------------------
     StartCoroutine(CleanUp());
 }
示例#2
0
 /// <summary>
 /// Spielt einen zufälligen Clip
 /// </summary>
 /// <param name="pi_Clips">Clips</param>
 /// <param name="pi_Volume">Optional Lautstärke</param>
 /// <param name="pi_HasToPlay">Optional muss gespielt werden</param>
 private void PlayRandomSound(AudioClip[] pi_Clips, float pi_Volume = 1.0f, bool pi_HasToPlay = true)
 {
     //------------------------------------------------------
     //Falls der Sound unterbrechen darf
     //------------------------------------------------------
     if (!pi_HasToPlay)
     {
         //------------------------------------------------------
         //Spiele Sound auf der entsprechenden Quelle
         //------------------------------------------------------
         float l_OldVol = m_MustnPlay.volume;
         m_MustnPlay.volume = pi_Volume;
         SoundUtilities.PlayRandomSound(m_MustnPlay, pi_Clips);
         m_MustnPlay.volume = l_OldVol;
         return;
     }
     //------------------------------------------------------
     //Versuche eine Source zu finden die nicht benutzt wird
     //------------------------------------------------------
     foreach (AudioSource b_Source in m_AddedSources)
     {
         if (!b_Source.isPlaying)
         {
             //------------------------------------------------------
             //Spiele ggf.
             //------------------------------------------------------
             float l_OldVol = b_Source.volume;
             b_Source.volume = pi_Volume;
             SoundUtilities.PlayRandomSound(b_Source, pi_Clips);
             b_Source.volume = l_OldVol;
             return;
         }
     }
     //------------------------------------------------------
     //Füge neue Source hinzu
     //------------------------------------------------------
     m_AddedSources.Add(SoundUtilities.AddSourceToObject(gameObject, false, 1.0f, false));
     //------------------------------------------------------
     //Versuche erneut
     //------------------------------------------------------
     PlayRandomSound(pi_Clips, pi_Volume);
 }