Is Device Connected#
Input / Is Device Connected
Can Read
Cannot Write
Description#
Returns true if the specified type of input device is available
Parameters#
| Name | Description |
|---|---|
| Device | The type of input device that is checked |
Code#
using System;
using UnityEngine;
using UnityEngine.InputSystem;
using VisualScript.Icons;
namespace VisualScript.Runtime
{
[Get]
[Inline(nameof(m_Device))]
[Title("Is Device Connected")]
[Category("Input/Is Device Connected")]
[Description("Returns true if the specified type of input device is available")]
[Image(typeof(IconComputer), ColorTheme.Type.Blue)]
[Parameter("Device", "The type of input device that is checked")]
[Keywords("Keyboard", "Mouse", "Gamepad", "Touch", "Pen", "Plugged")]
[Serializable]
public class TypeBoolInputDeviceConnected : TypeBool
{
[SerializeField] private InputDeviceType m_Device = InputDeviceType.Gamepad;
public override bool Get(Args args)
{
return this.m_Device switch
{
InputDeviceType.Keyboard => Keyboard.current != null,
InputDeviceType.Mouse => Mouse.current != null,
InputDeviceType.Gamepad => Gamepad.current != null,
InputDeviceType.Touchscreen => Touchscreen.current != null,
InputDeviceType.Pen => Pen.current != null,
_ => throw new ArgumentOutOfRangeException()
};
}
public override string ToString()
{
return $"{this.m_Device} is Connected";
}
protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
}
}