wirm/Game/Assets/Samples/XR Interaction Toolkit/3.0.3/Spatial Keyboard/Scripts/KeyFunctions/ShiftFunction.cs
immaunicorn107 be4c63ba7c auth manager and log in scene (under start)
pls double cfm ui on your end
2025-02-20 00:58:27 +08:00

71 lines
2.6 KiB
C#

namespace UnityEngine.XR.Interaction.Toolkit.Samples.SpatialKeyboard.KeyFunctions
{
/// <summary>
/// Key function used to process shift and caps lock functionality.
/// </summary>
[CreateAssetMenu(fileName = "Shift Function", menuName = "XR/Spatial Keyboard/Shift Key Function", order = 1)]
public class ShiftFunction : KeyFunction
{
[SerializeField]
Sprite m_CapsLockDisplayIcon;
public Sprite capsLockDisplayIcon
{
get => m_CapsLockDisplayIcon;
set => m_CapsLockDisplayIcon = value;
}
/// <inheritdoc />
public override Sprite GetDisplayIcon(XRKeyboard keyboardContext, XRKeyboardKey key)
{
// This method won't be called unless OverrideDisplayIcon below returns true,
// so no need for logic to return a shift display icon, which is already set up
// as the default in the UI.
return m_CapsLockDisplayIcon;
}
/// <inheritdoc />
public override bool OverrideDisplayIcon(XRKeyboard keyboardContext, XRKeyboardKey key)
{
return keyboardContext != null && keyboardContext.capsLocked;
}
/// <inheritdoc />
public override void ProcessKey(XRKeyboard keyboardContext, XRKeyboardKey key)
{
if (keyboardContext == null)
return;
var keyCode = KeyCode.LeftShift;
// Check the caps lock state of the keyboard. If they key is shifted, check if there is a double click.
if (keyboardContext.capsLocked ||(keyboardContext.shifted && key.timeSinceLastClick < keyboardContext.doubleClickInterval))
keyCode = KeyCode.CapsLock;
keyboardContext.ProcessKeyCode(keyCode);
}
/// <inheritdoc />
public override void PostprocessKey(XRKeyboard keyboardContext, XRKeyboardKey key)
{
base.PostprocessKey(keyboardContext, key);
RefreshKeyHighlight(keyboardContext, key);
}
/// <inheritdoc />
public override void ProcessRefreshDisplay(XRKeyboard keyboardContext, XRKeyboardKey key)
{
base.ProcessRefreshDisplay(keyboardContext, key);
RefreshKeyHighlight(keyboardContext, key);
}
protected void RefreshKeyHighlight(XRKeyboard keyboardContext, XRKeyboardKey key)
{
if (keyboardContext == null)
return;
var highlight = keyboardContext.capsLocked || keyboardContext.shifted;
key.EnableHighlight(highlight);
}
}
}