아마도 Unity3D는 구성 런타임을 변경할 수없는 끔찍한 빌트인 입력 시스템을 가지고 있기 때문에 SharpDX를 기반으로 자체 입력 시스템을 작성하기로 결심했습니다 DirectInput. 내가 잘 알고 directInput 공식 recomendet 아니지만 모든 종류의 장치 (내 트러스트 스틱 게임 패드 GTX 28처럼. 원래 PSX 에뮬레이션에 구입)와 함께 작동하는 능력을 좋아. 내가 클래스를 사용하여Unity3D의 SharpDx - 편집기의 다른 창을 클릭하면 더 이상 작동하지 않는 버튼
당신은 대체 통일의 클래스 중 하나와 동일한 클래스의 이름을 지정하는 경우 아래의 (내 자신과 Input.GetKeyDown 버튼 객체
public class InputButton
{
public JoystickOffset button;
public Key key;
public int pressValue;
public int relaseValue;
public bool isJoystick;
public InputButton(JoystickOffset button, int pressValue, int relaseValue)
{
this.button = button;
this.pressValue = pressValue;
this.relaseValue = relaseValue;
isJoystick = true;
}
public InputButton(Key key, int pressValue, int relaseValue)
{
this.key = key;
this.pressValue = pressValue;
this.relaseValue = relaseValue;
isJoystick = false;
}
}
그리고 내가 유니티의 (그런데 꽤 끔찍한 방법) 교체를 representate하기 가. 나는 누군가가 여기에 정적의 사용을 싫어한다 알고 있지만 나는) 매우 benefical 볼
public static bool GetKeyDown(InputButton button)
{
bool pressed = false;
keyboard.Poll();
keyboardData = keyboard.GetBufferedData();
if (button.isJoystick == false)
{
foreach (var state in keyboardData)
{
if (state.Key == button.key && state.Value == button.pressValue)
{
pressed = true;
}
}
}
return pressed;
}
하지만 Input.Initialize를 호출 할 모든 것을하기 전에 (깨어있는 동안 (다른 클래스에서)()). 다음과 같이 보입니다.
public static void Initialize()
{
directInput = new DirectInput();
var joystickGuid = Guid.Empty;
foreach (var deviceInstance in directInput.GetDevices(SharpDX.DirectInput.DeviceType.Joystick, DeviceEnumerationFlags.AttachedOnly))
{
joystickGuid = deviceInstance.InstanceGuid;
}
if (joystickGuid == Guid.Empty)
{
foreach (var deviceInstance in directInput.GetDevices(SharpDX.DirectInput.DeviceType.Gamepad, DeviceEnumerationFlags.AttachedOnly))
{
joystickGuid = deviceInstance.InstanceGuid;
}
}
if (joystickGuid != Guid.Empty)
{
joystick = new Joystick(directInput, joystickGuid);
joystick.Properties.BufferSize = 128;
joystick.Acquire();
}
keyboard = new Keyboard(directInput);
keyboard.Properties.BufferSize = 128;
keyboard.Acquire();
}
이제 문제가 생겼습니다. 에디터에서 게임 창의 외부를 클릭하면 키가 더 이상 반응하지 않습니다. 나는 모든 것을 검사했고 directInput과 keyboard는 여전히 변수에 있습니다. 이 문제는 게임 윈도우가 포커스를 잃는 순간 곧바로 연결이 끊어 지거나 (윈도우가 활성 윈도우가 아니거나 활성 윈도우가 활성 상태가 아니라 " 집중된 ").
누군가가이 문제가 발생하는 이유와 해결 방법을 알고 있습니까?
편집 :이 문제는 어떻게 든 창에 연결되어있는 것처럼 보입니다. 설정이 있고 전체 화면 런타임을 전환 할 수 있습니다. 내가 fullscreen에있는 한 그것은 잘 작동하지만 내가 창으로 전환하면 작동을 멈 춥니 다.
감사합니다. -Garrom