diff --git a/osu.Game/Rulesets/UI/Playfield.cs b/osu.Game/Rulesets/UI/Playfield.cs index f2c9b49900..43999e3d29 100644 --- a/osu.Game/Rulesets/UI/Playfield.cs +++ b/osu.Game/Rulesets/UI/Playfield.cs @@ -1,10 +1,13 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System; using System.Collections.Generic; +using System.Linq; using osu.Framework.Graphics; using osu.Game.Rulesets.Objects.Drawables; using osu.Framework.Allocation; +using osu.Framework.Extensions.IEnumerableExtensions; namespace osu.Game.Rulesets.UI { @@ -15,11 +18,8 @@ namespace osu.Game.Rulesets.UI /// public HitObjectContainer HitObjects { get; private set; } - /// - /// All the s nested inside this playfield. - /// - public IReadOnlyList NestedPlayfields => nestedPlayfields; - private List nestedPlayfields; + private readonly Lazy> nestedPlayfields = new Lazy>(); + public IEnumerable NestedPlayfields => nestedPlayfields.IsValueCreated ? nestedPlayfields.Value : Enumerable.Empty(); /// /// A container for keeping track of DrawableHitObjects. @@ -48,7 +48,7 @@ namespace osu.Game.Rulesets.UI /// /// Performs post-processing tasks (if any) after all DrawableHitObjects are loaded into this Playfield. /// - public virtual void PostProcess() => nestedPlayfields?.ForEach(p => p.PostProcess()); + public virtual void PostProcess() => NestedPlayfields.ForEach(p => p.PostProcess()); /// /// Adds a DrawableHitObject to this Playfield. @@ -67,13 +67,7 @@ namespace osu.Game.Rulesets.UI /// This does not add the to the draw hierarchy. /// /// The to add. - protected void AddNested(Playfield otherPlayfield) - { - if (nestedPlayfields == null) - nestedPlayfields = new List(); - - nestedPlayfields.Add(otherPlayfield); - } + protected void AddNested(Playfield otherPlayfield) => nestedPlayfields.Value.Add(otherPlayfield); /// /// Creates the container that will be used to contain the s.