-
Notifications
You must be signed in to change notification settings - Fork 95
Introduce AudioSystem to write back the current state of an audio source #6135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from 3 commits
93bb6dd
bfced7d
7659cf0
8e2ece1
787cc40
4fd64b8
d9e0f28
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,13 @@ | ||
| using System; | ||
| | ||
| using Cysharp.Threading.Tasks; | ||
| using System; | ||
| using DCL.Controllers; | ||
| using DCL.ECS7.InternalComponents; | ||
| using DCL.ECSRuntime; | ||
| using DCL.Helpers; | ||
| using DCL.Models; | ||
| using DCL.SettingsCommon; | ||
| using System.Collections.Generic; | ||
|
||
| using UnityEngine; | ||
| using AudioSettings = DCL.SettingsCommon.AudioSettings; | ||
|
|
||
|
|
@@ -60,10 +63,7 @@ public void OnComponentCreated(IParcelScene scene, IDCLEntity entity) | |
| dataStore.virtualAudioMixer.sceneSFXVolume.OnChange += OnVirtualAudioMixerChangedValue; | ||
| sceneNumber.OnChange += OnCurrentSceneChanged; | ||
|
|
||
| audioSourceInternalComponent.PutFor(scene, entity, new InternalAudioSource() | ||
| { | ||
| audioSource = this.audioSource | ||
| }); | ||
|
|
||
|
|
||
| sbcInternalComponent.RegisterOnSceneBoundsStateChangeCallback(scene, entity, OnSceneBoundsStateChange); | ||
|
|
||
|
|
@@ -149,17 +149,13 @@ private void ApplyCurrentModel() | |
| audioSource.spatialBlend = 1; | ||
| audioSource.dopplerLevel = 0.1f; | ||
|
|
||
| if (model.Playing != audioSource.isPlaying) | ||
| { | ||
| if (audioSource.isPlaying) | ||
| audioSource.Stop(); | ||
| else if (isAudioClipReady) | ||
| audioSource.Play(); | ||
| } | ||
| else if (audioSource.isPlaying) | ||
| { | ||
| if (model.Playing == audioSource.isPlaying) | ||
| return; | ||
|
|
||
| if (!model.Playing && audioSource.isPlaying) | ||
| audioSource.Stop(); | ||
| } | ||
| if (model.Playing && !audioSource.isPlaying && isAudioClipReady) | ||
| audioSource.Play(); | ||
| } | ||
|
|
||
| private void ApplyLoadedAudioClip(AudioClip clip) | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| { | ||
| "name": "ECS7Plugin.Systems.AudioSource", | ||
| "rootNamespace": "", | ||
| "references": [ | ||
| "GUID:9cccce9925d3495d8a5e4fa5b25f54a5", | ||
| "GUID:9239602a072d4e52b5f1cae20ab2b459", | ||
| "GUID:0a17d39e1dc14c038aa3c6483a185df0", | ||
| "GUID:37d2c04574c1d480d8c817e2a7c578e7", | ||
| "GUID:97d8897529779cb49bebd400c7f402a6", | ||
| "GUID:ac62e852826a4b36aeb22931dad73edb", | ||
| "GUID:1e10040ab6604cbe8ad0921047d49e65", | ||
| "GUID:a881b57670b1d2747a6d7f9e32b63230", | ||
| "GUID:3c7b57a14671040bd8c549056adc04f5", | ||
| "GUID:acb0f5633d7c47aba96ee6b61c872d94" | ||
| ], | ||
| "includePlatforms": [], | ||
| "excludePlatforms": [], | ||
| "allowUnsafeCode": false, | ||
| "overrideReferences": false, | ||
| "precompiledReferences": [], | ||
| "autoReferenced": true, | ||
| "defineConstraints": [], | ||
| "versionDefines": [], | ||
| "noEngineReferences": false | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| using DCL.ECS7; | ||
| using DCL.ECS7.ComponentWrapper.Generic; | ||
| using DCL.ECS7.InternalComponents; | ||
| using DCL.ECSComponents; | ||
| using DCL.ECSRuntime; | ||
| using System.Collections.Generic; | ||
| using UnityEngine; | ||
|
||
|
|
||
| namespace ECSSystems.AudioSourceSystem | ||
| { | ||
| public class ECSAudioSourceSystem | ||
| { | ||
| private readonly IInternalECSComponent<InternalAudioSource> audioSourceComponent; | ||
| private readonly IReadOnlyDictionary<int, ComponentWriter> componentsWriter; | ||
| private readonly WrappedComponentPool<IWrappedComponent<PBAudioSource>> audioSourcePool; | ||
|
|
||
| public ECSAudioSourceSystem( | ||
| IInternalECSComponent<InternalAudioSource> audioSourceComponent, | ||
| IReadOnlyDictionary<int, ComponentWriter> componentsWriter, | ||
| WrappedComponentPool<IWrappedComponent<PBAudioSource>> audioSourcePool) | ||
| { | ||
| this.audioSourceComponent = audioSourceComponent; | ||
| this.componentsWriter = componentsWriter; | ||
| this.audioSourcePool = audioSourcePool; | ||
| } | ||
|
|
||
| public void Update() | ||
| { | ||
| var audioSourceComponentList = audioSourceComponent.GetForAll(); | ||
|
|
||
| // Loop through every audio source component | ||
| foreach (var component in audioSourceComponentList) | ||
|
||
| { | ||
| var scene = component.key1; | ||
| var entity = component.key2; | ||
| var model = component.value.model; | ||
|
|
||
| var wrappedComponent = audioSourcePool.Get(); | ||
| wrappedComponent.WrappedComponent.Model.Playing = model.audioSource.isPlaying; | ||
| wrappedComponent.WrappedComponent.Model.Loop = model.loop; | ||
| wrappedComponent.WrappedComponent.Model.Volume = model.volume; | ||
| wrappedComponent.WrappedComponent.Model.Pitch = model.pitch; | ||
| wrappedComponent.WrappedComponent.Model.AudioClipUrl ??= model.audioClipUrl; | ||
| wrappedComponent.WrappedComponent.Model.CurrentTime = model.audioSource.time; | ||
|
|
||
| if (componentsWriter.TryGetValue(scene.sceneData.sceneNumber, out var writer)) | ||
|
||
| { | ||
| writer.Put(entity, ComponentID.AUDIO_SOURCE, wrappedComponent); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this is a leftover?