A game framework written with osu! in mind.
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2// See the LICENCE file in the repository root for full licence text.
3
4using System.Collections.Immutable;
5using System.Linq;
6using osu.Framework.Input.Handlers;
7
8namespace osu.Framework.Input
9{
10 /// <summary>
11 /// An <see cref="InputManager"/> implementation which allows managing of <see cref="InputHandler"/>s manually.
12 /// </summary>
13 public class CustomInputManager : InputManager
14 {
15 protected override ImmutableArray<InputHandler> InputHandlers => inputHandlers;
16
17 private ImmutableArray<InputHandler> inputHandlers = ImmutableArray.Create<InputHandler>();
18
19 protected void AddHandler(InputHandler handler)
20 {
21 if (!handler.Initialize(Host)) return;
22
23 inputHandlers = inputHandlers.Append(handler).ToImmutableArray();
24 }
25
26 protected void RemoveHandler(InputHandler handler)
27 {
28 inputHandlers = inputHandlers.Where(h => h != handler).ToImmutableArray();
29 }
30
31 protected override void Dispose(bool isDisposing)
32 {
33 foreach (var h in inputHandlers)
34 h.Dispose();
35
36 base.Dispose(isDisposing);
37 }
38 }
39}