Net.Like.Xue.Tokyo/Assets/BITKit/Unity/Scripts/InputSystem/InputSystemExtensions.cs

41 lines
1.4 KiB
C#
Raw Normal View History

2024-11-03 16:42:23 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using System;
using System.Linq;
2025-02-27 17:52:42 +08:00
using UnityEngine.InputSystem.Controls;
2024-11-03 16:42:23 +08:00
namespace BITKit
{
public static partial class InputSystemExtensions
{
public static bool JustPressed(this InputAction.CallbackContext self)
{
2025-02-27 17:52:42 +08:00
return self is { started:true, control: ButtonControl { wasPressedThisFrame: true , isPressed:true} };
2024-11-03 16:42:23 +08:00
}
public static InputAction RegisterCallback(this InputAction self, Action<InputAction.CallbackContext> action)
{
self.performed += action;
self.started += action;
self.canceled += action;
return self;
}
public static string GetKeyMap(this InputAction self)
{
return string.Join("|", self.bindings.Select(x=>x.path.Split("/").Last().ToUpper()));
}
public static string GetKeyMap(this InputActionReference self)
{
return string.Join("|", self.action.bindings.Select(x=>x.path.Split("/").Last().ToUpper()));
}
public static InputAction UnRegisterCallback(this InputAction self, Action<InputAction.CallbackContext> action)
{
self.performed -= action;
self.started -= action;
self.canceled -= action;
return self;
}
}
}