Seconds since Last Input#
Input / Seconds since Last Input
Can Read
Cannot Write
Description#
Returns the amount of seconds since any input device was last used
Code#
using System;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.LowLevel;
using VisualScript.Icons;
namespace VisualScript.Runtime
{
[Get]
[Title("Seconds since Last Input")]
[Category("Input/Seconds since Last Input")]
[Description("Returns the amount of seconds since any input device was last used")]
[Image(typeof(IconTimer), ColorTheme.Type.Blue)]
[Keywords("Idle", "Away", "Attract", "Inactive", "Time")]
[Serializable]
public class TypeNumberInputSecondsSinceLastInput : TypeNumber
{
public override double Get(Args args)
{
double lastUpdateTime = 0d;
foreach (InputDevice device in InputSystem.devices)
{
if (device.lastUpdateTime > lastUpdateTime) lastUpdateTime = device.lastUpdateTime;
}
return Math.Max(0d, InputState.currentTime - lastUpdateTime);
}
public override string ToString()
{
return "Seconds since last Input";
}
protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
}
}