Пример #1
0
    /// <returns>The standard source volume</returns>
    static private float Internal_PlayMusic(AudioPlayable playable, bool looping, float volumeMultiplier = 1)
    {
        if (!CheckResources_Instance() || !CheckResources_MusicSource())
        {
            return(0);
        }

        AudioSource source = GetAndIncrementMusicSource();

        source.volume = 1;

        if (looping)
        {
            playable.PlayLoopedOn(source, 1);
        }
        else
        {
            playable.PlayOn(source);
        }

        float stdVolume = source.volume;

        source.volume *= volumeMultiplier;
        return(stdVolume);
    }
Пример #2
0
 /// <summary>
 /// Plays the audioplayable. Leave source to 'null' to play on the standard 2D SFX audiosource.
 /// </summary>
 static public void PlaySFX(AudioPlayable playable, float delay = 0, float volumeMultiplier = 1, AudioSource source = null)
 {
     if (CheckResources_Instance())
     {
         PlayNonMusic(playable, delay, volumeMultiplier, source, Instance.SFXSource);
     }
 }
Пример #3
0
    static private void Internal_PlayMusicFaded(AudioPlayable playable, float fadeInDuration, bool looping = true, float startingVolume = 0)
    {
        if (!CheckResources_Instance() || !CheckResources_MusicSource())
        {
            return;
        }

        float stdVolume = Internal_PlayMusic(playable, looping, startingVolume);

        Instance.musicTransitionTweens.Add(
            GetMusicSource().DOFade(stdVolume, fadeInDuration).SetEase(AUDIOFADE_EASE));
    }
Пример #4
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        AudioPlayable playable = target as AudioPlayable;

        EditorGUI.BeginDisabledGroup(serializedObject.isEditingMultipleObjects);

        GUILayoutOption largeHeight = GUILayout.Height(18 * 2 + 3);

        GUILayout.BeginHorizontal(largeHeight);

        GUI.enabled = _previewer.isPlaying;
        if (GUILayout.Button("Stop", largeHeight))
        {
            _previewer.Stop();
        }
        GUI.enabled = true;

        GUILayout.BeginVertical();
        if (GUILayout.Button("Preview"))
        {
            playable.PlayOnAndIgnoreCooldown(_previewer);
        }
        if (GUILayout.Button("Preview looped"))
        {
            if (_previewer.isPlaying)
            {
                _previewer.Stop();
            }
            playable.PlayLoopedOn(_previewer);
        }
        GUILayout.EndVertical();

        GUILayout.EndHorizontal();
        EditorGUI.EndDisabledGroup();
    }
Пример #5
0
    private static void PlayNonMusic(AudioPlayable playable, float delay, float volumeMultiplier, AudioSource source, AudioSource defaultSource)
    {
        if (playable == null)
        {
            return;
        }

        AudioSource theSource = source;

        if (theSource == null)
        {
            theSource = defaultSource;
        }

        if (delay > 0)
        {
            Instance.StartCoroutine(PlayNonMusicIn(playable, delay, volumeMultiplier, theSource));
            return;
        }
        else
        {
            playable.PlayOn(theSource, volumeMultiplier);
        }
    }
Пример #6
0
    private void PlayNonMusic(AudioPlayable playable, float delay, float volumeMultiplier, AudioSource source, AudioSource defaultSource)
    {
        if (playable == null)
        {
            return;
        }

        AudioSource selectedSource = source;

        if (selectedSource == null)
        {
            selectedSource = defaultSource;
        }

        if (delay > 0)
        {
            StartCoroutine(PlayNonMusicIn(playable, delay, volumeMultiplier, selectedSource));
            return;
        }
        else
        {
            playable.PlayOn(selectedSource, volumeMultiplier);
        }
    }
Пример #7
0
    /// <summary>
    /// Transitionne vers une nouvelle musique
    /// </summary>
    /// <param name="clip">Le clip a faire jouer</param>
    /// <param name="looping">Est-ce qu'on loop</param>
    /// <param name="volume">Le volume de la 2e musique</param>
    /// <param name="fadingDuration">La duree de fading par musique. ATTENTION, ceci n'est pas necessairement == duree total de la transition</param>
    /// <param name="overlap">L'overlapping des deux musiques en transition (en %). 0 = la 1ere stoppe, puis la 2e commence.   0.5 = les 2 tansitionne en meme temps   1 = la deuxieme commence, puis la 1ere stoppe</param>
    /// <param name="startingVolume">Volume initiale de la 2e musique</param>
    static public void TransitionToMusic(AudioPlayable playable, bool looping = true, float fadingDuration = 1.5f, float overlap = 0.5f, float startingVolume = 0)
    {
        Action action = () => Internal_PlayMusicFaded(playable, fadingDuration, looping, startingVolume);

        Internal_TransitionToMusic(action, fadingDuration, overlap);
    }
Пример #8
0
 static public void PlayMusic(AudioPlayable playable, bool looping = true)
 {
     StopMusic();
     Internal_PlayMusic(playable, looping);
 }
Пример #9
0
    private static IEnumerator PlayNonMusicIn(AudioPlayable playable, float delay, float volumeMultiplier, AudioSource source)
    {
        yield return(new WaitForSecondsRealtime(delay));

        playable.PlayOn(source, volumeMultiplier);
    }
 public void PlayMusic_AudioPlayable(AudioPlayable playable)
 {
     DefaultAudioSources.PlayMusic(playable);
 }
 public void PlayStaticSFX_AudioPlayable(AudioPlayable playable)
 {
     DefaultAudioSources.PlayStaticSFX(playable);
 }
 public void PlayVoice_AudioPlayable(AudioPlayable playable)
 {
     DefaultAudioSources.PlayVoice(playable);
 }
Пример #13
0
 /// <summary>
 /// Plays the audioplayable. Leave source to 'null' to play on the standard 2D SFX audiosource.
 /// </summary>
 public void PlaySFX(AudioPlayable playable, float delay = 0, float volumeMultiplier = 1, AudioSource source = null)
 {
     PlayNonMusic(playable, delay, volumeMultiplier, source, SFXSource);
 }
 public void PlayMusic_AudioPlayable(AudioPlayable playable)
 {
     DefaultAudioSourceService.Instance.PlayMusic(playable);
 }
 public void PlayStaticSFX_AudioPlayable(AudioPlayable playable)
 {
     DefaultAudioSourceService.Instance.PlayStaticSFX(playable);
 }
 public void PlayVoice_AudioPlayable(AudioPlayable playable)
 {
     DefaultAudioSourceService.Instance.PlayVoice(playable);
 }