public static StreamableAudioComponent CreateFrom(StreamableAudio audioInfo) { GameObject o = new GameObject(); if (Player.player != null) { o.transform.position = Player.player.transform.position; } var audioSource = o.AddComponent <AudioSource>(); audioSource.loop = false; audioSource.rolloffMode = AudioRolloffMode.Logarithmic; audioSource.priority = 0; audioSource.spatialBlend = 0f; StreamableAudioComponent comp = o.AddComponent <StreamableAudioComponent>(); comp.AudioInfo = audioInfo; return(comp); }
private void Update() { if (_queuedAudio.Count == 0) { return; } var nextItem = _queuedAudio.Dequeue(); bool isNew = true; var audio = _audios.FirstOrDefault(c => c.Handle == nextItem.Handle); if (audio != null) { DestroyImmediate(audio.StreamableAudioComponent.gameObject); DestroyImmediate(audio.StreamableAudioComponent); isNew = false; } else { audio = nextItem; } var obj = StreamableAudioComponent.CreateFrom(audio); if (!audio.AutoStart) { obj.Pause(); } audio.StreamableAudioComponent = obj; if (isNew) { _audios.Add(audio); } }