Esempio n. 1
0
    private bool ConnectSpeakers(PropagatingAudioSource host)
    {
        if (!IsConnected(host))
        {
            PropagatingSoundGateway[] gateways = RoomToNeighbourPositions[host.HostRoom];
            PropagatingSpeaker[]      speakers = new PropagatingSpeaker[gateways.Length];

            for (int i = 0; i < speakers.Length; i++)
            {
                PropagatingSpeaker speaker = GetNextFree(speakers.Length);
                if (speaker == null)
                {
                    FreeSpeakers(speakers);
                    return(false);
                }
                else
                {
                    speaker.Dampening = gateways[i].Dampening;
                    speakers[i]       = speaker;
                }
            }

            // All required speakers are available - position them correctly
            for (int i = 0; i < speakers.Length; i++)
            {
                speakers[i].audioSource.transform.position = gateways[i].SoundTarget;
                SpeakerToOrigin[speakers[i]] = host;
            }

            ConnectedSpeakers[host] = speakers;
        }

        return(true);
    }
Esempio n. 2
0
 public void Disconnect(PropagatingAudioSource host)
 {
     if (ConnectedSpeakers.ContainsKey(host))
     {
         PropagatingSpeaker[] speakers = ConnectedSpeakers[host];
         FreeSpeakers(speakers);
     }
 }
Esempio n. 3
0
 public void ForwardPlayOneShot(PropagatingAudioSource host, AudioClip clip, float volume)
 {
     if (ConnectSpeakers(host))
     {
         PropagatingSpeaker[] speakers = ConnectedSpeakers[host];
         foreach (PropagatingSpeaker speaker in speakers)
         {
             speaker.audioSource.PlayOneShot(clip, volume * speaker.Dampening);
         }
     }
 }
Esempio n. 4
0
 public void UpdateClip(PropagatingAudioSource host, AudioClip clip)
 {
     if (IsConnected(host))
     {
         PropagatingSpeaker[] speakers = ConnectedSpeakers[host];
         foreach (PropagatingSpeaker speaker in speakers)
         {
             speaker.audioSource.clip = clip;
         }
     }
 }
Esempio n. 5
0
 public void UpdateVolume(PropagatingAudioSource host, float volume)
 {
     if (IsConnected(host))
     {
         PropagatingSpeaker[] speakers = ConnectedSpeakers[host];
         foreach (PropagatingSpeaker speaker in speakers)
         {
             speaker.audioSource.volume = volume * speaker.Dampening;
         }
     }
 }
Esempio n. 6
0
 public void ForwardStop(PropagatingAudioSource host)
 {
     if (IsConnected(host))
     {
         PropagatingSpeaker[] speakers = ConnectedSpeakers[host];
         foreach (PropagatingSpeaker speaker in speakers)
         {
             speaker.audioSource.Stop();
         }
         FreeSpeakers(speakers);
     }
 }
Esempio n. 7
0
 public void ForwardPlay(PropagatingAudioSource host, AudioClip clip, float volume, bool loop)
 {
     if (ConnectSpeakers(host))
     {
         PropagatingSpeaker[] speakers = ConnectedSpeakers[host];
         foreach (PropagatingSpeaker speaker in speakers)
         {
             speaker.audioSource.clip   = clip;
             speaker.audioSource.volume = volume * speaker.Dampening;
             speaker.audioSource.loop   = loop;
             speaker.audioSource.Play();
         }
     }
 }
Esempio n. 8
0
    private void FreeSpeaker(PropagatingSpeaker speaker)
    {
        if (SpeakerToOrigin.ContainsKey(speaker))
        {
            PropagatingAudioSource origin = SpeakerToOrigin[speaker];
            SpeakerToOrigin.Remove(speaker);

            if (ConnectedSpeakers.ContainsKey(origin))
            {
                ConnectedSpeakers.Remove(origin);
            }
        }

        speaker.Connected = false;
    }
Esempio n. 9
0
    private bool GarbageCollect(int required)
    {
        int collected = 0;

        for (int i = 0; i < audioSourcePool.Length; i++)
        {
            if (!audioSourcePool[i].IsPlaying)
            {
                PropagatingSpeaker registered = audioSourcePool[i];
                if (SpeakerToOrigin.ContainsKey(registered))
                {
                    PropagatingAudioSource origin = SpeakerToOrigin[registered];
                    FreeSpeakers(ConnectedSpeakers[origin]);
                    collected++;
                }
            }
        }

        return(collected >= required);
    }
Esempio n. 10
0
 private bool IsConnected(PropagatingAudioSource host) => ConnectedSpeakers.ContainsKey(host);