38 lines
903 B
Markdown
38 lines
903 B
Markdown
---
|
|
uid: input-system-step-5-optional
|
|
---
|
|
|
|
# Step 5 current and all (optional)
|
|
|
|
For convenience, you can quickly access the last used device of a given type, or list all devices of a specific type. To do this, add support for a `current` and for an `all` getter to the API of `MyDevice`.
|
|
|
|
```CSharp
|
|
public class MyDevice : InputDevice, IInputCallbackReceiver
|
|
{
|
|
//...
|
|
|
|
public static MyDevice current { get; private set; }
|
|
|
|
public static IReadOnlyList<MyDevice> all => s_AllMyDevices;
|
|
private static List<MyDevice> s_AllMyDevices = new List<MyDevice>();
|
|
|
|
public override void MakeCurrent()
|
|
{
|
|
base.MakeCurrent();
|
|
current = this;
|
|
}
|
|
|
|
protected override void OnAdded()
|
|
{
|
|
base.OnAdded();
|
|
s_AllMyDevices.Add(this);
|
|
}
|
|
|
|
protected override void OnRemoved()
|
|
{
|
|
base.OnRemoved();
|
|
s_AllMyDevices.Remove(this);
|
|
}
|
|
}
|
|
```
|