Problème d'instance de classe

amlil-cs Messages postés 7 Date d'inscription jeudi 16 janvier 2014 Statut Membre Dernière intervention 7 avril 2014 - 7 avril 2014 à 11:23
yann_lo_san Messages postés 1137 Date d'inscription lundi 17 novembre 2003 Statut Membre Dernière intervention 23 janvier 2016 - 7 avril 2014 à 21:15
Bonjour,
je travaille actuellement sur un projet qui fait l'interfaçage entre un joystick et unity3d. Pour cela, j'utilise les bibliothèques SharptDX. à chaque fois que je lance mon problème il m'envoie la même erreur que je n'arrive pas à résoudre. mon programme tourne normalement sous visual studio mais il refuse de tourner sous unity. voilà l'erreur que j'obtiens à chaque fois.

SharpDXException: HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: Paramètre incorrect.

voilà le rapport de l'erreur

SharpDX.Result.CheckError ()

SharpDX.DirectInput.Device.SetDataFormat (SharpDX.DirectInput.DataFormat arg0)

SharpDX.DirectInput.CustomDevice'3[SharpDX.DirectInput.JoystickState,SharpDX.DirectInput.RawJoystickState,SharpDX.DirectInput.JoystickUpdate]..ctor (SharpDX.DirectInput.DirectInput directInput, Guid deviceGuid)

SharpDX.DirectInput.Joystick..ctor (SharpDX.DirectInput.DirectInput directInput, Guid deviceGuid)

Movement.Start () (at Assets/Movement.cs:41)



voiçi mon petit programme
using UnityEngine;
using System;
using System.Linq;
using System.Text;
using System.Collections;
using SharpDX.DirectInput;
using SharpDX;

public class Movement : MonoBehaviour {
public Movement ()
{
// initialize DirectInput
var directInput = new DirectInput();

// find Joystick Guid
var joystickGuid = Guid.Empty;


foreach (var deviceInstance in directInput.GetDevices(SharpDX.DirectInput.DeviceType.Joystick, DeviceEnumerationFlags.AllDevices))
joystickGuid = deviceInstance.InstanceGuid;

Debug.Log("Found Joystick/Gamepad with GUID: {0}"+ joystickGuid);
Joystick joystick = new Joystick (directInput, joystickGuid);


}
void Start ()
{

}
void Update ()
{

}
}

l'origine de l'erreur est la ligne: Joystick joystick = new Joystick (directInput, joystickGuid);

il n'arrive pas à instancier la classe Joystick.


quelqu'un veut bien m'aider SVP?

1 réponse

yann_lo_san Messages postés 1137 Date d'inscription lundi 17 novembre 2003 Statut Membre Dernière intervention 23 janvier 2016 26
7 avril 2014 à 21:15
Salut,

En managed DirectX 1.1 sans libs additionnelles


// en utilisant DirectInput "directement"
using Microsoft.DirectX.DirectInput;

// Acquérir le joystick "actuellement connecté"
Device joystick = null;

DeviceList gameControllerList = Manager.GetDevices(DeviceClass.GameControl,
    EnumDevicesFlags.AttachedOnly /*ICI*/);
if (gameControllerList.Count > 0)
{
    gameControllerList.MoveNext();
    DeviceInstance deviceInstance = (DeviceInstance)
        gameControllerList.Current;
    joystick = new Device(deviceInstance.InstanceGuid);
    joystick.SetCooperativeLevel(this,
        CooperativeLevelFlags.Background |
        CooperativeLevelFlags.NonExclusive);
} 
joystick.SetDataFormat(DeviceDataFormat.Joystick); 
joystick.Acquire();



bye...
0
Rejoignez-nous