1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-10 04:55:42 +00:00
X10D/X10D.Unity/src/WaitForKeyDown.cs

39 lines
901 B
C#

using System.Collections;
using UnityEngine;
namespace X10D.Unity;
/// <summary>
/// Represents a yield instruction that waits for a key to be pressed.
/// </summary>
public readonly struct WaitForKeyDown : IEnumerator
{
private readonly KeyCode _keyCode;
/// <summary>
/// Initializes a new instance of the <see cref="WaitForKeyDown" /> struct.
/// </summary>
/// <param name="keyCode">The key to wait for.</param>
public WaitForKeyDown(KeyCode keyCode)
{
_keyCode = keyCode;
}
/// <inheritdoc />
public object Current
{
get => _keyCode == KeyCode.None ? Input.anyKeyDown : Input.GetKeyDown(_keyCode);
}
/// <inheritdoc />
public bool MoveNext()
{
return !(_keyCode == KeyCode.None ? Input.anyKeyDown : Input.GetKeyDown(_keyCode));
}
/// <inheritdoc />
public void Reset()
{
}
}