private async Task Init() { _siraLog.Debug("Loading music."); var badMusic = new List <FileInfo>(); var stopwatch = Stopwatch.StartNew(); var loadedCustoms = new List <AudioContainer>(); foreach (var musicPath in _config.EnabledMusicFiles) { if (!musicPath.Exists || musicPath.Extension != ".ogg") { badMusic.Add(musicPath); continue; } try { _siraLog.Debug($"Loading {musicPath.FullName}"); AudioClip audioClip = await _cachedMediaAsyncLoader.LoadAudioClipAsync(musicPath.FullName, _cancellationTokenSource.Token); var name = musicPath.Name.Remove(musicPath.Name.IndexOf(musicPath.Extension)); var maybeImage = musicPath.Directory.EnumerateFiles().FirstOrDefault(ef => ef.Name.Remove(ef.Name.IndexOf(ef.Extension)) == name && (ef.Extension == ".png" || ef.Extension == ".jpg")); Texture2D?texHolder = null; if (maybeImage != null && maybeImage.Exists) { texHolder = (await _cachedMediaAsyncLoader.LoadSpriteAsync(maybeImage !.FullName, _cancellationTokenSource.Token)).texture; } loadedCustoms.Add(new AudioContainer(name, audioClip, texHolder)); } catch (Exception e) { _siraLog.Error(e.Message); badMusic.Add(musicPath); } } foreach (var bad in badMusic) { // If any of the music files failed to load or do not exist, remove them. _config.EnabledMusicFiles.Remove(bad); } stopwatch.Stop(); _siraLog.Debug($"Finished Loading Music in {stopwatch.Elapsed} seconds"); _randomObjectPicker = new RandomObjectPicker <AudioContainer>(loadedCustoms.ToArray(), 0.07f); Loaded?.Invoke(); }
public async Task <Tuple <Sprite, AudioClip> > GetProfileAssets(Profile profile) { Sprite spr = null; AudioClip clip = null; if (!(string.IsNullOrEmpty(profile.ImagePath) || !File.Exists(Path.Combine(IMAGE_FOLDER, profile.ImagePath)) || profile.ImagePath.EndsWith("gif") || profile.ImagePath.EndsWith("apng"))) { try { spr = await _spriteLoader.LoadSpriteAsync(Path.Combine(IMAGE_FOLDER, profile.ImagePath), _cancellationTokenSource.Token); } catch { } } if (!string.IsNullOrEmpty(profile.AudioPath) && File.Exists(Path.Combine(AUDIO_FOLDER, profile.AudioPath))) { try { clip = await _mediaLoader.LoadAudioClipAsync(Path.Combine(AUDIO_FOLDER, profile.AudioPath), _cancellationTokenSource.Token); } catch { } } return(new Tuple <Sprite, AudioClip>(spr, clip)); }