Unity 中的 SharpDX.Direct 输入

Posted

技术标签:

【中文标题】Unity 中的 SharpDX.Direct 输入【英文标题】:SharpDX.Direct Input in Unity 【发布时间】:2014-10-31 16:22:09 【问题描述】:

我一直在尝试使用 SharpDX.DirectInput dll 将 DirectInput 实现为统一,但是当我创建操纵杆时,它给了我一个错误:

SharpDXException: HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: The parameter is incorrect.

这是我的代码:

using System;
using UnityEngine;
using SharpDX.DirectInput;


namespace KurdifyEngine.Input

static class Direct

    public static DirectInput directInput;
    public static Guid directGuid;
    public static Joystick directGamepad ;
    internal static void Initialize()
    
        // Initialize DirectInput
        directInput = new DirectInput();
        directGuid = Guid.Empty;
        DirectUpdate();


    
    internal static void DirectUpdate()
    
        // search for Gamepad
        foreach (var deviceInstance in directInput.GetDevices(SharpDX.DirectInput.DeviceType.Gamepad, DeviceEnumerationFlags.AttachedOnly))
            directGuid = deviceInstance.InstanceGuid;
        
        if (directGuid != Guid.Empty)
        
            directGamepad = new Joystick(directInput, directGuid);
        
    

创建操纵杆时发生错误:

directGamepad = new Joystick(directInput, directGuid);

【问题讨论】:

我怀疑您能否将 SharpDX(一个渲染框架/游戏引擎)与 Unity(一个渲染框架/游戏引擎)混合使用。为什么还要打扰? Unity 内置了对操纵杆/游戏手柄的支持,如果这还不够,您可以在资源商店中找到更好的支持。 它适用于其他人,并且内置支持缺乏很多功能,我已经支持 XInput,运行时键绑定,我只是想知道如何自己实现它,我不想依赖资产商店资产。 【参考方案1】:

我们一直在为 Unity 产品开发奇异的控制器支持,并在完全相同的行上遇到了相同的问题(SharpDXException:HRESULT:[0x80070057])。

我们尝试通过修复它来重新编译 SharpDX,就像在这篇 github 帖子中解释的那样:https://github.com/sharpdx/SharpDX/issues/406 但遇到了 DirectX(2010 年 6 月)SDK 的其他问题。

我们刚刚找到了一种使用该项目中包含的库(这是 Kerbal Space Program 中的外来控制器支持的附加组件)编译 Unity 项目的方法:https://github.com/pbatard/AltInput 只需在 Libraries/ 下选择 .dll,用这些替换旧的 .dll 就可以了!

【讨论】:

以上是关于Unity 中的 SharpDX.Direct 输入的主要内容,如果未能解决你的问题,请参考以下文章

Unity for Android 中的 Azure AD 身份验证出错

unity接入quick sdk报错总结(ios版)

unity接入quick sdk报错总结(ios第一版)

升级到Unity 5.3

解决Qt Tcp通信传输中文字符乱码问题

Unity2d自动寻路(AI插件)