Beispiel #1
0
        private static void PlayLooping(AudioSource source, List <LoopingAudioSource> sources, float volumeScale, float fadeSeconds, bool persist, bool stopAll)
        {
            EnsureCreated();

            for (int i = sources.Count - 1; i >= 0; i--)
            {
                LoopingAudioSource s = sources[i];
                if (s.AudioSource == source)
                {
                    sources.RemoveAt(i);
                }
                if (stopAll)
                {
                    s.Stop();
                }
            }
            {
                source.gameObject.SetActive(true);
                LoopingAudioSource s = new LoopingAudioSource(source, fadeSeconds, fadeSeconds, persist);
                s.Play(volumeScale, true);
                s.Tag = persistTag;
                sources.Add(s);

                if (persist)
                {
                    if (!source.gameObject.name.StartsWith("PersistedBySoundManager-"))
                    {
                        source.gameObject.name = "PersistedBySoundManager-" + source.gameObject.name + "-" + source.gameObject.GetInstanceID();
                    }
                    source.gameObject.transform.parent = null;
                    GameObject.DontDestroyOnLoad(source.gameObject);
                    persistedSounds.Add(s);
                }
            }
        }
Beispiel #2
0
        private static void PlayLooping(AudioSource source, List<LoopingAudioSource> sources, float volumeScale, float fadeSeconds, bool persist, bool stopAll)
        {
            EnsureCreated();

            for (int i = sources.Count - 1; i >= 0; i--)
            {
                LoopingAudioSource s = sources[i];
                if (s.AudioSource == source)
                {
                    sources.RemoveAt(i);
                }
                if (stopAll)
                {
                    s.Stop();
                }
            }
            {
                source.gameObject.SetActive(true);
                LoopingAudioSource s = new LoopingAudioSource(source, fadeSeconds, fadeSeconds, persist);
                s.Play(volumeScale, true);
                s.Tag = persistTag;
                sources.Add(s);

                if (persist)
                {
                    if (!source.gameObject.name.StartsWith("PersistedBySoundManager-"))
                    {
                        source.gameObject.name = "PersistedBySoundManager-" + source.gameObject.name + "-" + source.gameObject.GetInstanceID();
                    }
                    source.gameObject.transform.parent = null;
                    GameObject.DontDestroyOnLoad(source.gameObject);
                    persistedSounds.Add(s);
                }
            }
        }