示例#1
0
        public static void play(Uri uri, SoundType type = SoundType.SoundEffect, SoundLoop loop = SoundLoop.None)
        {
            MediaPlayer player = new MediaPlayer();

            player.Open(uri);
            play(player, type, loop);
        }
示例#2
0
    public void PlayLoop(SoundLoop sound, AudioSource source, float volumeFactor = 1)
    {
        SoundLoopClip c = audioFiles.SoundLoopToClip(sound);

        source.clip   = c.Clip;
        source.volume = c.Volume * volumeFactor * globalVolume;
        source.Play();
    }
示例#3
0
 protected override void  OnProcessEntities(GameTime gameTime, IEnumerable <int> entityIdCollection)
 {
     foreach (int liveId in entityIdCollection)
     {
         SoundLoop soundLoop = soundLoopComponents.GetComponentFor(liveId);
         UpdateSound(liveId, soundLoop);
     }
 }
示例#4
0
        protected override void OnEntityAdded(Entity entity, int liveId)
        {
            base.OnEntityAdded(entity, liveId);

            SoundLoop soundLoop = soundLoopComponents.GetComponentFor(entity);

            soundEffectInstance[liveId]          = soundEffects[soundLoop.CueNameId].CreateInstance();
            soundEffectInstance[liveId].IsLooped = true;    // REVIEW: support non-looped.
            UpdateSound(liveId, soundLoop);
            soundEffectInstance[liveId].Play();
        }
示例#5
0
    public void SetLoopVolume(SoundLoop sound, float volume)
    {
        AudioSource source = loopSources.FirstOrDefault <AudioSource>(src => AudioManager.Instance.IsSameSoundLoop(sound, src.clip));

        if (!source)
        {
            Debug.LogWarning("This AudioBox do not play the sound : " + sound + ", so they cannot change volume");
            return;
        }

        AudioManager.Instance.SetLoopVolume(sound, source, volume);
    }
示例#6
0
    public void StopLoop(SoundLoop sound)
    {
        AudioSource source = loopSources.FirstOrDefault <AudioSource>(src => AudioManager.Instance.IsSameSoundLoop(sound, src.clip));

        if (!source)
        {
            Debug.LogWarning("This AudioBox do not play the sound : " + sound + ", so they cannot be stopped");
            return;
        }

        if (source.isPlaying)
        {
            source.Stop();
        }
        source.clip = null;
    }
示例#7
0
    public SoundLoopClip SoundLoopToClip(SoundLoop sound)
    {
        switch (sound)
        {
        case SoundLoop.DayMusic: return(dayMusic);

        case SoundLoop.AmbianceDay: return(ambianceDay);

        case SoundLoop.AmbianceNight: return(ambianceNight);

        case SoundLoop.AmbianceRain: return(ambianceRain);

        case SoundLoop.AmbianceSnow: return(ambianceSnow);

        default:
            Debug.LogError("SoundLoopClip : " + sound + " was not found!");
            return(null);
        }
    }
示例#8
0
    public void StopSoundLoop(SoundLoop sound)
    {
        AudioClip   clip       = audioFiles.GetLoopClip(sound);
        AudioSource findSource = null;

        foreach (AudioSource source in musicSources)
        {
            if (source.clip == clip)
            {
                findSource = source;
                break;
            }
        }

        if (findSource)
        {
            findSource.Stop();
            musicSources.Remove(findSource);
            Destroy(findSource);
        }
    }
示例#9
0
    public void PlaySoundLoop(SoundLoop sound, float volume = 1f, bool loop = true)
    {
        AudioClip clip = audioFiles.GetLoopClip(sound);

        foreach (AudioSource source in musicSources)
        {
            if (source.clip == clip)
            {
                return;
            }
        }

        AudioSource musicSource = gameObject.AddComponent <AudioSource>();

        musicSource.playOnAwake = false;
        musicSource.volume      = volume = musicGlobalVolume;
        musicSource.loop        = loop;
        musicSource.clip        = clip;
        musicSource.Play();

        musicSources.Add(musicSource);
    }
示例#10
0
    public void PlayLoop(SoundLoop sound, float volumeFactor = 1)
    {
        AudioSource source = null;

        for (int i = 0; i < nbLoopTrack; ++i)
        {
            AudioSource src = loopSources[i];
            if (!src.isPlaying)
            {
                source = src;
                break;
            }
        }

        if (!source)
        {
            Debug.LogWarning("This AudioBox do not have enough LoopTrack, " + sound + " cannot be played");
            return;
        }

        AudioManager.Instance.PlayLoop(sound, source);
    }
示例#11
0
    public AudioClip GetLoopClip(SoundLoop musicFile)
    {
        switch (musicFile)
        {
        //"Environment
        case SoundLoop.PeopleBackround: return(peopleBackground);

        case SoundLoop.HumBackground: return(humBackground);

        case SoundLoop.TrainMovement: return(trainMovement);

        case SoundLoop.TrainCloseDoorWarning: return(trainCloseDoorWarning);

        case SoundLoop.MainMenu: return(mainMenuMusic);

        case SoundLoop.Level: return(levelMusic);

        case SoundLoop.Jt: return(jtMusic);
        }

        return(null);
    }
示例#12
0
        public static void play(MediaPlayer player, SoundType type = SoundType.SoundEffect, SoundLoop loop = SoundLoop.None)
        {
            SoundConfiguration configuration = new SoundConfiguration(type, loop);

            currentMediaPlayers[player] = configuration;

            switch (type)
            {
            //todo make music transition flow correctly
            case SoundType.BattleMusic:
                player.Volume = PlayBattleTheme ? MusicVolume : 0;
                break;

            case SoundType.MenuMusic:
                player.Volume = PlayBattleTheme ? 0 : MusicVolume;
                break;

            case SoundType.SoundEffect:
                player.Volume = SoundVolume;
                break;
            }

            player.MediaEnded += on_player_end;
            player.Play();
        }
示例#13
0
 private void UpdateSound(int liveId, SoundLoop soundLoop)
 {
     soundEffectInstance[liveId].Volume = soundLoop.Volume;
     soundEffectInstance[liveId].Pitch  = soundLoop.Pitch;
 }
示例#14
0
 public SoundConfiguration(SoundType soundType, SoundLoop soundLoop)
 {
     Type = soundType;
     Loop = soundLoop;
 }
示例#15
0
    private IEnumerator StopLoopAfterTime(SoundLoop sound, float time)
    {
        yield return(new WaitForSeconds(time));

        StopLoop(sound);
    }
示例#16
0
    public void SetLoopVolume(SoundLoop sound, AudioSource source, float volume)
    {
        SoundLoopClip c = audioFiles.SoundLoopToClip(sound);

        source.volume = c.Volume * volume * globalVolume;
    }
示例#17
0
 public void Start()
 {
     soundLoop = GetComponentInParent <SoundLoop>();
 }
示例#18
0
 public bool IsSameSoundLoop(SoundLoop sound, AudioClip clip)
 {
     return(audioFiles.SoundLoopToClip(sound).Clip == clip);
 }
示例#19
0
 public void PlayLoopForTime(SoundLoop sound, float time, float volumeFactor = 1)
 {
     PlayLoop(sound, volumeFactor);
     StartCoroutine(StopLoopAfterTime(sound, time));
 }
示例#20
0
 public static void play(string uriString, SoundType type = SoundType.SoundEffect, SoundLoop loop = SoundLoop.None)
 {
     play(new Uri(uriString, UriKind.Relative), type, loop);
 }