1
0
mirror of https://github.com/xiaopeng12138/MaiDXR.git synced 2025-01-31 12:23:45 +01:00

Made it possible to switch hand during hold

maybe not stable but
This commit is contained in:
wang_w571 2022-03-15 23:35:12 +08:00
parent 981e2c38d2
commit f8a39dd34b

View File

@ -10,14 +10,30 @@ public class ButtonToKey : MonoBehaviour
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo); static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);
public VirtualKeyCode keyToPress; public VirtualKeyCode keyToPress;
private int _insideColliderCount = 0;
private void Update()
{
if (_insideColliderCount == 0)
{
keybd_event(System.Convert.ToByte(keyToPress), (byte)MapVirtualKey((uint)keyToPress, 0), 2, UIntPtr.Zero);
}
else
{
keybd_event(System.Convert.ToByte(keyToPress), (byte)MapVirtualKey((uint)keyToPress, 0), 0, UIntPtr.Zero);
}
}
private void OnTriggerEnter(Collider other) private void OnTriggerEnter(Collider other)
{ {
keybd_event(System.Convert.ToByte(keyToPress), (byte)MapVirtualKey((uint)keyToPress, 0), 0, UIntPtr.Zero); _insideColliderCount += 1;
} }
private void OnTriggerExit(Collider other) private void OnTriggerExit(Collider other)
{ {
keybd_event(System.Convert.ToByte(keyToPress), (byte)MapVirtualKey((uint)keyToPress, 0), 2, UIntPtr.Zero); _insideColliderCount -= 1;
_insideColliderCount = Mathf.Max(0, _insideColliderCount);
} }
} }