public JoystickDevice(IntPtr sdlHandle) { this.sdlHandle = sdlHandle; joystickType = (JoystickType)SDL.SDL_JoystickGetType(sdlHandle); deviceId = SDL.SDL_JoystickName(sdlHandle); deviceName = string.Format("{0} ({1})", deviceId, joystickType.ToString()); totalButtons = SDL.SDL_JoystickNumButtons(sdlHandle); totalAxis = SDL.SDL_JoystickNumAxes(sdlHandle); totalBalls = SDL.SDL_JoystickNumBalls(sdlHandle); totalHats = SDL.SDL_JoystickNumHats(sdlHandle); for (int i = 0; i < statesDoubleBuffer.Length; ++i) { statesDoubleBuffer[i] = new JoystickState() { buttonsDown = new bool[totalButtons], axisValues = new float[totalAxis], ballValues = new Vector2[totalBalls], hatPositions = new HatPosition[totalHats], }; } }
//====================================================== public void Initialize() { string[] joystickNames = Input.GetJoystickNames(); string joystickName = ""; if (joystickNames.Length > 0) { joystickName = joystickNames[0]; } if (!string.IsNullOrEmpty(joystickName)) { joystickType = (joystickName == "Wireless Controller") ? JoystickType.PS4 : JoystickType.XBOX; Log.Debug("Joystick name: '" + joystickName + "' ...name: " + joystickName + " ..type: " + joystickType.ToString()); } else { Log.Debug("Joystick not found."); } }