1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 18:23:04 +08:00
This commit is contained in:
smoogipoo 2020-11-19 20:38:36 +09:00
parent 812d5d59b1
commit 70cb197957
3 changed files with 21 additions and 12 deletions

View File

@ -156,7 +156,7 @@ namespace osu.Game.Rulesets.Objects.Drawables
config.BindWith(OsuSetting.PositionalHitSounds, userPositionalHitSounds); config.BindWith(OsuSetting.PositionalHitSounds, userPositionalHitSounds);
// Explicit non-virtual function call. // Explicit non-virtual function call.
base.AddInternal(Samples = new PausableSkinnableSound(Array.Empty<ISampleInfo>())); base.AddInternal(Samples = new PausableSkinnableSound());
} }
protected override void LoadAsyncComplete() protected override void LoadAsyncComplete()
@ -266,7 +266,8 @@ namespace osu.Game.Rulesets.Objects.Drawables
// In order to stop this needless update, the event is unbound and re-bound as late as possible in Apply(). // In order to stop this needless update, the event is unbound and re-bound as late as possible in Apply().
samplesBindable.CollectionChanged -= onSamplesChanged; samplesBindable.CollectionChanged -= onSamplesChanged;
Samples.Samples = Array.Empty<ISampleInfo>(); // Release the samples for other hitobjects to use.
Samples.Samples = null;
if (nestedHitObjects.IsValueCreated) if (nestedHitObjects.IsValueCreated)
{ {
@ -334,8 +335,6 @@ namespace osu.Game.Rulesets.Objects.Drawables
/// </summary> /// </summary>
protected virtual void LoadSamples() protected virtual void LoadSamples()
{ {
Samples.Samples = Array.Empty<ISampleInfo>();
var samples = GetSamples().ToArray(); var samples = GetSamples().ToArray();
if (samples.Length <= 0) if (samples.Length <= 0)

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic; using System.Collections.Generic;
using JetBrains.Annotations;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Threading; using osu.Framework.Threading;
@ -14,16 +15,20 @@ namespace osu.Game.Skinning
{ {
protected bool RequestedPlaying { get; private set; } protected bool RequestedPlaying { get; private set; }
public PausableSkinnableSound(ISampleInfo sample) public PausableSkinnableSound()
: base(sample)
{ {
} }
public PausableSkinnableSound(IEnumerable<ISampleInfo> samples) public PausableSkinnableSound([NotNull] IEnumerable<ISampleInfo> samples)
: base(samples) : base(samples)
{ {
} }
public PausableSkinnableSound([NotNull] ISampleInfo sample)
: base(sample)
{
}
private readonly IBindable<bool> samplePlaybackDisabled = new Bindable<bool>(); private readonly IBindable<bool> samplePlaybackDisabled = new Bindable<bool>();
private ScheduledDelegate scheduledStart; private ScheduledDelegate scheduledStart;

View File

@ -4,6 +4,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio; using osu.Framework.Audio;
using osu.Framework.Audio.Track; using osu.Framework.Audio.Track;
@ -38,18 +39,23 @@ namespace osu.Game.Skinning
[Resolved(CanBeNull = true)] [Resolved(CanBeNull = true)]
private IPooledSampleProvider pooledProvider { get; set; } private IPooledSampleProvider pooledProvider { get; set; }
public SkinnableSound(ISampleInfo sample) public SkinnableSound()
: this(new[] { sample })
{ {
} }
public SkinnableSound(IEnumerable<ISampleInfo> samples) public SkinnableSound([NotNull] IEnumerable<ISampleInfo> samples)
: this()
{ {
this.samples = samples.ToArray(); this.samples = samples.ToArray();
InternalChild = SamplesContainer = new AudioContainer<PoolableSkinnableSample>(); InternalChild = SamplesContainer = new AudioContainer<PoolableSkinnableSample>();
} }
public SkinnableSound([NotNull] ISampleInfo sample)
: this(new[] { sample })
{
}
private ISampleInfo[] samples; private ISampleInfo[] samples;
public ISampleInfo[] Samples public ISampleInfo[] Samples
@ -57,8 +63,7 @@ namespace osu.Game.Skinning
get => samples; get => samples;
set set
{ {
if (value == null) value ??= Array.Empty<ISampleInfo>();
throw new ArgumentNullException(nameof(value));
if (samples == value) if (samples == value)
return; return;