public DirectInputGamePad(DirectInput directInput, GamePadKey key) : base(key) { this.key = key; this.directInput = directInput; this.instance = new Joystick(directInput, key.Guid); joystickState = new JoystickState(); }
public GamePad(DirectInput directInput, DeviceInstance deviceInstance) { this.directInput = directInput; this.device = new Joystick(directInput, deviceInstance.InstanceGuid); this.device.Acquire(); UpdateState(); }
//Disable all dinput devices for xinput controllers public void Lock_DX_Devices() { var directInput = new DirectInput(); try { IList<DeviceInstance> devicelist = directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AttachedOnly); foreach (DeviceInstance cdevice in devicelist) { if (cdevice.InstanceName.Trim('\0') == XINPUT_NAME) { var joystick = new Joystick(directInput, cdevice.InstanceGuid); joystick.Acquire(); Guid deviceGUID = joystick.Properties.ClassGuid; string devicePath = joystick.Properties.InterfacePath; joystick.Unacquire(); string[] dpstlit = devicePath.Split('#'); devicePath = @"HID\" + dpstlit[1].ToUpper() + @"\" + dpstlit[2].ToUpper(); lockedDevices.Add(new DeviceID(deviceGUID, devicePath)); DeviceHelper.SetDeviceEnabled(deviceGUID, devicePath, false); } } } finally { directInput.Dispose(); } }
private void ConfigEditDialog_Load(object sender, EventArgs e) { directInput = new DirectInput(); var list = directInput.GetDevices(DeviceClass.GameControl, DeviceEnumerationFlags.AttachedOnly); if (list.Count > 0) { inputDevice = new Joystick(directInput, list.First().InstanceGuid); tableLayoutPanel1.RowCount = actionNames.Length; for (int i = 0; i < actionNames.Length; i++) { tableLayoutPanel1.Controls.Add(new Label() { AutoSize = true, Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Top, Text = actionNames[i], TextAlign = ContentAlignment.MiddleLeft }, 0, i); ButtonControl buttonControl = new ButtonControl() { Enabled = false }; tableLayoutPanel1.Controls.Add(buttonControl, 1, i); buttonControls.Add(buttonControl); buttonControl.SetButtonClicked += buttonControl_SetButtonClicked; buttonControl.ClearButtonClicked += buttonControl_ClearButtonClicked; if (i == tableLayoutPanel1.RowStyles.Count) tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.AutoSize)); } } else tabControl1.TabPages.Remove(tabPage_Controller); // Load the config INI upon window load LoadConfigIni(); }
/// <summary> /// 番号指定でデバイス生成。番号のデバイスが存在しなければ例外を投げる。 /// </summary> /// <param name="window"></param> /// <param name="padNumber">0始まり</param> public GamePadDevice(int padNumber, DirectInput directInput) { var devices = GetDevices(directInput); if (devices.Count <= padNumber) { throw new Exception("指定された数のパッドがつながれていない"); } try { Stick = new Joystick(directInput, devices[padNumber].InstanceGuid); //Stick.SetCooperativeLevel(window, CooperativeLevel.Exclusive | CooperativeLevel.Foreground); } catch (Exception e) { throw new Exception("パッドの初期化に失敗", e); } ///スティックの範囲設定 foreach (var item in Stick.GetObjects()) { //if ((item.ObjectType & .Axis) != 0) //{ // Stick.GetObjectPropertiesById((int)item.ObjectType).SetRange(-1000, 1000); //} } Stick.Acquire(); }
public static void Initialize() { if (dinput == null) dinput = new DirectInput(); Devices = new List<GamePad>(); foreach (DeviceInstance device in dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly)) { Console.WriteLine("joydevice: {0} `{1}`", device.InstanceGuid, device.ProductName); if (device.ProductName.Contains("XBOX 360")) continue; // Don't input XBOX 360 controllers into here; we'll process them via XInput (there are limitations in some trigger axes when xbox pads go over xinput) var joystick = new Joystick(dinput, device.InstanceGuid); joystick.SetCooperativeLevel(GlobalWin.MainForm.Handle, CooperativeLevel.Background | CooperativeLevel.Nonexclusive); foreach (DeviceObjectInstance deviceObject in joystick.GetObjects()) { if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0) joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-1000, 1000); } joystick.Acquire(); GamePad p = new GamePad(device.InstanceName, device.InstanceGuid, joystick); Devices.Add(p); } }
private Joystick GetJoystick() { var directInput = new DirectInput(); var form = new Form(); foreach (var device in directInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly)) { var controller = new Joystick(directInput, device.InstanceGuid); controller.SetCooperativeLevel(form.Handle, CooperativeLevel.Exclusive | CooperativeLevel.Background); var retries = 0; while (controller.Acquire().IsFailure) { retries++; if (retries > 500) throw new Exception("Couldnt acquire SlimDX stick"); } if (controller.Information.InstanceName.Contains("PPJoy")) { foreach (DeviceObjectInstance deviceObject in controller.GetObjects()) { if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0) controller.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-1000, 1000); } return controller; } } return null; }
public override void JoystickReleased(Joystick sender, Joystick.JoystickState state) { //ConsoleDisplayN18.Write("Selected " + _menu.CursorLine); //Thread.Sleep(1000); //_menu.Draw(); SelectState(_menu.CursorLine); }
public bool SetJoystickByName(string name) { WriteLog("Searching joystick!"); // Find joystick foreach (DeviceInstance deviceInstance in GetJoysticks()) { if (deviceInstance.InstanceName.StartsWith(name, StringComparison.CurrentCulture)) { joystickGuid = deviceInstance.InstanceGuid; } } // Joystick not found! if (joystickGuid == Guid.Empty) { WriteLog("Joystick not found!"); return false; } WriteLog("Joystick found!"); // Create & acquire the joystick joystick = new Joystick(directInput, joystickGuid); joystick.Properties.BufferSize = 128; joystick.Acquire(); WriteLog("Joystick '" + joystick.Properties.InstanceName + "' found!"); return true; }
public void InitializeController(Guid initGuid) { controllerGuid = Guid.Empty; var deviceInst = input.GetDevices(DeviceClass.GameControl, DeviceEnumerationFlags.AttachedOnly); if (deviceInst.Count == 0) { deviceInst = input.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AttachedOnly); } if (deviceInst.Count > 0) { foreach (var device in deviceInst) { if (device.InstanceGuid == initGuid) { controllerGuid = initGuid; } } if (controllerGuid == Guid.Empty) { controllerGuid = deviceInst[0].InstanceGuid; } controller = new Joystick(input, controllerGuid); controller.Acquire(); defaultControllerState = controller.GetCurrentState(); } }
public GamepadReader() { Buttons = _buttons; Analogs = _analogs; _dinput = new DirectInput(); var devices = _dinput.GetDevices (DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly); if (devices.Count < 1) { throw new IOException ("GamepadReader could not find a connected gamepad."); } _joystick = new Joystick (_dinput, devices[0].InstanceGuid); foreach (var obj in _joystick.GetObjects()) { if ((obj.ObjectType & ObjectDeviceType.Axis) != 0) { _joystick.GetObjectPropertiesById ((int)obj.ObjectType).SetRange (-RANGE, RANGE); } } if (_joystick.Acquire().IsFailure) { throw new IOException ("Connected gamepad could not be acquired."); } _timer = new DispatcherTimer (); _timer.Interval = TimeSpan.FromMilliseconds (TIMER_MS); _timer.Tick += tick; _timer.Start (); }
public MainController() { var directInput = new DirectInput(); LogicState = new LogicState(); foreach (var deviceInstance in directInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly)) { try { gamepad = new Joystick(directInput, deviceInstance.InstanceGuid); gamepad.SetCooperativeLevel(Parent, CooperativeLevel.Exclusive | CooperativeLevel.Foreground); break; } catch (DirectInputException) { } } if (gamepad == null) return; foreach (var deviceObject in gamepad.GetObjects()) { if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0) gamepad.GetObjectPropertiesById((int) deviceObject.ObjectType).SetRange(-1000, 1000); } gamepad.Acquire(); }
public override IEnumerator startObjective() { player = GameObject.FindWithTag("Player").GetComponent<Player>(); //Moves the player closer to the gap joyStickScript = joystick.GetComponent<Joystick>(); while (player.transform.position.x < 18) { joyStickScript.UpdateVirtualAxes(new Vector3(joyStickScript.m_StartPos.x + 20, joyStickScript.m_StartPos.y)); yield return new WaitForSeconds((float)0.01); } joyStickScript.OnPointerUp(null); Text stageText = stageTextObject.GetComponent<Text>(); stageText.text = "Drop down the gap to respawn above"; //Enables the buttons joystick.GetComponent<Image>().enabled = true; while (!isCompleted()) { yield return new WaitForSeconds((float)0.1); } //Disables the buttons joystick.GetComponent<Image>().enabled = false; stageText.text = "Remember! Enemies get a speed boost when they drop into a gap"; yield return new WaitForSeconds(3); }
public void UpdateFrom(Joystick device, out JoystickState state) { if (!AppHelper.IsSameDevice(device, deviceInstanceGuid)) { ShowDeviceInfo(device); deviceInstanceGuid = Guid.Empty; if (device != null) { deviceInstanceGuid = device.Information.InstanceGuid; isWheel = device.Information.Type == SharpDX.DirectInput.DeviceType.Driving; } } state = null; if (device != null) { try { device.Acquire(); state = device.GetCurrentState(); } catch (Exception ex) { var error = ex; } } ShowDirectInputState(state); }
public GhiJoystickInputProvider(Joystick joystick) { if (joystick == null) throw new ArgumentNullException("joystick"); _joystick = joystick; _joystick.JoystickPressed += joystick_JoystickPressed; _joystick.JoystickReleased += joystick_JoystickReleased; }
public static DeviceObjectItem[] GetDeviceObjects(Joystick device) { var og = typeof(SharpDX.DirectInput.ObjectGuid); var guidFileds = og.GetFields().Where(x => x.FieldType == typeof(Guid)); List<Guid> guids = guidFileds.Select(x => (Guid)x.GetValue(og)).ToList(); List<string> names = guidFileds.Select(x => x.Name).ToList(); var objects = device.GetObjects(DeviceObjectTypeFlags.All).OrderBy(x => x.Offset).ToArray(); var items = new List<DeviceObjectItem>(); foreach (var o in objects) { var item = new DeviceObjectItem() { Name = o.Name, Offset = o.Offset, Instance = o.ObjectId.InstanceNumber, Usage = o.Usage, Aspect = o.Aspect, Flags = o.ObjectId.Flags, GuidValue = o.ObjectType, GuidName = guids.Contains(o.ObjectType) ? names[guids.IndexOf(o.ObjectType)] : o.ObjectType.ToString(), }; items.Add(item); } return items.ToArray(); }
protected override void ResolveDependencies() { base.ResolveDependencies(); this.leftJoystick = this.EntityManager.Find<Joystick>("leftJoystick"); this.fireButton = this.EntityManager.Find<FireButton>("fireButton"); }
public override void Reconnect() { // search for devices foreach (DeviceInstance device in _DInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly)) { // create the device try { _Joy = new Joystick(_DInput, device.InstanceGuid); _Joy.SetCooperativeLevel(wnd_int, CooperativeLevel.Nonexclusive | CooperativeLevel.Background); break; } catch (DirectInputException) { } } if (_Joy == null) { IsConnected = false; Name = ""; Type = ""; return; } _Joy.Acquire(); IsConnected = true; Name = _Joy.Information.ProductName; Type = "DirectInput"; }
public DirectInputManager() { var directInput = new DirectInput(); // Prefer a Driving device but make do with fallback to a Joystick if we have to var deviceInstance = FindAttachedDevice(directInput, DeviceType.Driving); if (null == deviceInstance) deviceInstance = FindAttachedDevice(directInput, DeviceType.Joystick); if (null == deviceInstance) throw new Exception("No Driving or Joystick devices attached."); joystickType = (DeviceType.Driving == deviceInstance.Type ? JoystickTypes.Driving : JoystickTypes.Joystick); // A little debug spew is often good for you Log.Spew("First Suitable Device Selected \"" + deviceInstance.InstanceName + "\":"); Log.Spew("\tProductName: " + deviceInstance.ProductName); Log.Spew("\tType: " + deviceInstance.Type); Log.Spew("\tSubType: " + deviceInstance.Subtype); // Data for both Driving and Joystick device types is received via Joystick joystick = new Joystick(directInput, deviceInstance.InstanceGuid); IntPtr consoleWindowHandle = GetConsoleWindow(); if (IntPtr.Zero != consoleWindowHandle) { CooperativeLevel cooperativeLevel = CooperativeLevel.Background | CooperativeLevel.Nonexclusive; Log.Spew("Console window cooperative level: " + cooperativeLevel); if (!joystick.SetCooperativeLevel(consoleWindowHandle, cooperativeLevel).IsSuccess) throw new Exception("Failed to set cooperative level for DirectInput device in console window."); } var result = joystick.Acquire(); if (!result.IsSuccess) throw new Exception("Failed to acquire DirectInput device."); Log.Spew("Joystick acquired."); }
public NesVSUnisystemDIPJoystickConnection(IntPtr handle, string guid, IInputSettingsVSUnisystemDIP settings) { DirectInput di = new DirectInput(); joystick = new Joystick(di, Guid.Parse(guid)); joystick.SetCooperativeLevel(handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Foreground); if (settings.CreditServiceButton != "") CreditServiceButton = ParseKey(settings.CreditServiceButton); if (settings.DIPSwitch1 != "") DIPSwitch1 = ParseKey(settings.DIPSwitch1); if (settings.DIPSwitch2 != "") DIPSwitch2 = ParseKey(settings.DIPSwitch2); if (settings.DIPSwitch3 != "") DIPSwitch3 = ParseKey(settings.DIPSwitch3); if (settings.DIPSwitch4 != "") DIPSwitch4 = ParseKey(settings.DIPSwitch4); if (settings.DIPSwitch5 != "") DIPSwitch5 = ParseKey(settings.DIPSwitch5); if (settings.DIPSwitch6 != "") DIPSwitch6 = ParseKey(settings.DIPSwitch6); if (settings.DIPSwitch7 != "") DIPSwitch7 = ParseKey(settings.DIPSwitch7); if (settings.DIPSwitch8 != "") DIPSwitch8 = ParseKey(settings.DIPSwitch8); if (settings.CreditLeftCoinSlot != "") CreditLeftCoinSlot = ParseKey(settings.CreditLeftCoinSlot); if (settings.CreditRightCoinSlot != "") CreditRightCoinSlot = ParseKey(settings.CreditRightCoinSlot); NesEmu.EMUShutdown += NesEmu_EMUShutdown; }
/// /// Construct, attach the joystick /// public SimpleJoystick() { DirectInput dinput = new DirectInput(); // Search for device foreach (DeviceInstance device in dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly)) { // Create device try { Joystick = new Joystick(dinput, device.InstanceGuid); break; } catch (DirectInputException) { } } if (Joystick == null) throw new Exception("No joystick found"); foreach (DeviceObjectInstance deviceObject in Joystick.GetObjects()) { if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0) Joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-100, 100); } // Acquire sdevice Joystick.Acquire(); }
protected void InitJoystick() { #if UNITY_IPHONE || UNITY_ANDROID || UNITY_WP8 || UNITY_BLACKBERRY if (joystickPrefab) { // Create left joystick GameObject joystickLeftGO = Instantiate (joystickPrefab) as GameObject; joystickLeftGO.name = "Joystick Left"; joystickLeft = joystickLeftGO.GetComponent<Joystick> (); GUITexture guiTex = joystickLeftGO.GetComponent<GUITexture> (); joystickLeftRect = new Rect(0, 0,//Screen.height - guiTex.pixelInset.y - guiTex.pixelInset.height, guiTex.pixelInset.x + guiTex.pixelInset.width, guiTex.pixelInset.y + guiTex.pixelInset.height); // Create right joystick joystickRightGO = Instantiate (joystickPrefab) as GameObject; joystickRightGO.name = "Joystick Right"; joystickRight = joystickRightGO.GetComponent<Joystick> (); joystickRight.touchPad = true; GUITexture guiTexRight = joystickRightGO.GetComponent<GUITexture> (); string texture = "Common/Joystick/ShootButton";//"Textures/ThumbStickPad"; Texture2D inputTexture = Resources.Load(texture, typeof(Texture2D)) as Texture2D; guiTexRight.texture = inputTexture; } #endif }
public NesJoypadPcJoystickConnection(IntPtr handle, string guid, IInputSettingsJoypad settings) { DirectInput di = new DirectInput(); joystick = new Joystick(di, Guid.Parse(guid)); joystick.SetCooperativeLevel(handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Foreground); if (settings.ButtonUp != "") KeyUp = ParseKey(settings.ButtonUp); if (settings.ButtonDown != "") KeyDown = ParseKey(settings.ButtonDown); if (settings.ButtonLeft != "") KeyLeft = ParseKey(settings.ButtonLeft); if (settings.ButtonRight != "") KeyRight = ParseKey(settings.ButtonRight); if (settings.ButtonStart != "") KeyStart = ParseKey(settings.ButtonStart); if (settings.ButtonSelect != "") KeySelect = ParseKey(settings.ButtonSelect); if (settings.ButtonA != "") KeyA = ParseKey(settings.ButtonA); if (settings.ButtonB != "") KeyB = ParseKey(settings.ButtonB); if (settings.ButtonTurboA != "") KeyTurboA = ParseKey(settings.ButtonTurboA); if (settings.ButtonTurboB != "") KeyTurboB = ParseKey(settings.ButtonTurboB); }
public JoystickAxesVM(Joystick joystickInterface, string joystickName) { _joystickInterface = joystickInterface; JoystickName = joystickName; }
private void Joystick_Load(object sender, EventArgs e) { try { DeviceList joysticklist = Joystick.getDevices(); foreach (DeviceInstance device in joysticklist) { CMB_joysticks.Items.Add(device.ProductName); } } catch { CustomMessageBox.Show("Error geting joystick list: do you have the directx redist installed?"); this.Close(); return; } if (CMB_joysticks.Items.Count > 0 && CMB_joysticks.SelectedIndex == -1) CMB_joysticks.SelectedIndex = 0; try { if (MainV2.config.ContainsKey("joystick_name") && MainV2.config["joystick_name"].ToString() != "") CMB_joysticks.Text = MainV2.config["joystick_name"].ToString(); } catch { } CMB_CH1.DataSource = (Enum.GetValues(typeof(Joystick.joystickaxis))); CMB_CH2.DataSource = (Enum.GetValues(typeof(Joystick.joystickaxis))); CMB_CH3.DataSource = (Enum.GetValues(typeof(Joystick.joystickaxis))); CMB_CH4.DataSource = (Enum.GetValues(typeof(Joystick.joystickaxis))); CMB_CH5.DataSource = (Enum.GetValues(typeof(Joystick.joystickaxis))); CMB_CH6.DataSource = (Enum.GetValues(typeof(Joystick.joystickaxis))); CMB_CH7.DataSource = (Enum.GetValues(typeof(Joystick.joystickaxis))); CMB_CH8.DataSource = (Enum.GetValues(typeof(Joystick.joystickaxis))); try { CHK_elevons.Checked = bool.Parse(MainV2.config["joy_elevons"].ToString()); } catch { } // IF 1 DOESNT EXIST NONE WILL var tempjoystick = new Joystick(); label14.Text += " " + MainV2.comPort.MAV.cs.firmware.ToString(); for (int a = 1; a <= 8; a++) { var config = tempjoystick.getChannel(a); findandsetcontrol("CMB_CH" + a, config.axis.ToString()); findandsetcontrol("revCH" + a, config.reverse.ToString()); findandsetcontrol("expo_ch" + a, config.expo.ToString()); } if (MainV2.joystick != null && MainV2.joystick.enabled) { timer1.Start(); BUT_enable.Text = "Disable"; } startup = false; }
/// <summary>Maps the axes of the joystick</summary> /// <param name="joystick">Joystick for which axes are mapped</param> private void mapAxes(Joystick joystick) { IList<DeviceObjectInstance> axes = joystick.GetObjects( ObjectDeviceType.AbsoluteAxis ); var unmappedReaders = new Queue<IAxisReader>(); for (int index = 0; index < axes.Count; ++index) { if (axes[index].ObjectTypeGuid != ObjectGuid.Slider) { Axes axis = identifyAxis( axes[index].Aspect, axes[index].ObjectTypeGuid ); // If this axis could not be identified but we're still missing one of // the standard axes (X, Y, Rx, Ry), remember it so we can later map it // to the next unassigned standard axes in case some are left unassigned. if (axis == 0) { if (unmappedReaders.Count < 4) { unmappedReaders.Enqueue(createAxisReader(joystick, axis, axes[index])); } } else { // Axis identified, build reader and store it this.availableAxes |= axis; this.axisReaders[indexFromAxis(axis)] = createAxisReader( joystick, axis, axes[index] ); } } // if } // for // If the four standard axes are still not completely provided, use // the unidentified axis we remembered earlier as a fallback solution. if ((this.axisReaders[0] == null) && (unmappedReaders.Count > 0)) { this.availableAxes |= Axes.X; this.axisReaders[0] = unmappedReaders.Dequeue(); } if ((this.axisReaders[1] == null) && (unmappedReaders.Count > 0)) { this.availableAxes |= Axes.Y; this.axisReaders[1] = unmappedReaders.Dequeue(); } if ((this.axisReaders[12] == null) && (unmappedReaders.Count > 0)) { this.availableAxes |= Axes.RotationX; this.axisReaders[12] = unmappedReaders.Dequeue(); } if ((this.axisReaders[13] == null) && (unmappedReaders.Count > 0)) { this.availableAxes |= Axes.RotationY; this.axisReaders[13] = unmappedReaders.Dequeue(); } }
public override void Dispose() { if (instance != null) { instance.Dispose(); instance = null; } }
public ControllerEngine() { this._joystick = new Joystick(); this._gamepad = new Gamepad(); this.ActiveDevice = 0; //oldgstate = OpenTK.Input.GamePad.GetState(this.ActiveDevice); createNewTimer(); }
GamePad(string name, Guid guid, Joystick joystick) { this.name = name; this.guid = guid; this.joystick = joystick; Update(); InitializeCallbacks(); }
internal static extern int glfwJoystickPresent(Joystick joy);
internal static extern float *glfwGetJoystickAxes(Joystick joy, out int numaxes);
internal static extern byte *glfwGetJoystickButtons(Joystick joy, out int numbuttons);
internal static extern sbyte *glfwGetJoystickName(Joystick joy);
void Awake() { if (!automatic) { joystickGo = Instantiate(joystick) as GameObject; joystickGo.transform.localPosition = RockerOriginalPos; joystickLeft = joystickGo.GetComponent <Joystick>(); // joystick_left = GameObject.Find ("joystick_left").GetComponent<JoyStick>(); btnFire = GameObject.Find("joystick_right").GetComponent <AttackButton>(); SubscribeEvents(); StartCoroutine(DropWeaponAfterDuration(2f)); Time.timeScale = 1.2f; GameData.Instance.goldAdditionValue = 0; ///pet System.Array petArray = System.Enum.GetValues(typeof(PetType)); int i = 0; foreach (var p in petArray) { int level = PetDB.Instance.GetPetLvById((int)p); int onBattle = PetDB.Instance.GetPetOnBattleById((int)p); if (onBattle == 1) { float xoffset = 0; float zoffset = 0; switch ((PetType)p) { case PetType.songshu: speed = speed * (1f + IOHelper.GetPetInfoByIdAndLevel((int)p, level).value); GameObject petSongshu = (GameObject)Instantiate(Resources.Load("prefabs/pet/pet_songshu")); xoffset = Random.Range(-3f, 3f); zoffset = Random.Range(-3f, 3f); petSongshu.transform.position = transform.position + new Vector3(xoffset, 0, zoffset); break; case PetType.tuzi: GameObject petTuzi = (GameObject)Instantiate(Resources.Load("prefabs/pet/tuzi")); xoffset = Random.Range(-5f, 5f); zoffset = Random.Range(-5f, 5f); petTuzi.transform.position = transform.position + new Vector3(xoffset, 0, zoffset); break; case PetType.pet3: hpAddtional = IOHelper.GetPetInfoByIdAndLevel((int)p, level).value; GameObject pet03 = (GameObject)Instantiate(Resources.Load("prefabs/pet/pet03")); xoffset = Random.Range(-5f, 5f); zoffset = Random.Range(-5f, 5f); pet03.transform.position = transform.position + new Vector3(xoffset, 0, zoffset); break; case PetType.pet4: isRecovered = true; recoveredPercent = IOHelper.GetPetInfoByIdAndLevel((int)p, level).value; GameObject pet04 = (GameObject)Instantiate(Resources.Load("prefabs/pet/pet04")); xoffset = Random.Range(-5f, 5f); zoffset = Random.Range(-5f, 5f); pet04.transform.position = transform.position + new Vector3(xoffset, 0, zoffset); break; case PetType.pet5: isSpeedUp = true; speedUpPercent = IOHelper.GetPetInfoByIdAndLevel((int)p, level).value; GameObject pet05 = (GameObject)Instantiate(Resources.Load("prefabs/pet/pet05")); xoffset = Random.Range(-5f, 5f); zoffset = Random.Range(-5f, 5f); pet05.transform.position = transform.position + new Vector3(xoffset, 0, zoffset); break; case PetType.pet6: capacityUpPercent = IOHelper.GetPetInfoByIdAndLevel((int)p, level).value; GameObject pet06 = (GameObject)Instantiate(Resources.Load("prefabs/pet/pet06")); xoffset = Random.Range(-5f, 5f); zoffset = Random.Range(-5f, 5f); pet06.transform.position = transform.position + new Vector3(xoffset, 0, zoffset); break; case PetType.pet7: attackAddtional = IOHelper.GetPetInfoByIdAndLevel((int)p, level).value; GameObject pet07 = (GameObject)Instantiate(Resources.Load("prefabs/pet/pet07")); xoffset = Random.Range(-5f, 5f); zoffset = Random.Range(-5f, 5f); pet07.transform.position = transform.position + new Vector3(xoffset, 0, zoffset); break; } } } } }
void pollController() { Joystick TheMat; string text = ""; var directInput = new DirectInput(); var joystickGuid = Guid.Empty; //Find Gamepad foreach (var deviceInstance in directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices)) { joystickGuid = deviceInstance.InstanceGuid; } // If Gamepad not found, look for a Joystick if (joystickGuid == Guid.Empty) { foreach (var deviceInstance in directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices)) { joystickGuid = deviceInstance.InstanceGuid; } } // If Joystick not found, throws an error if (joystickGuid == Guid.Empty) { text = "No joystick/Gamepad found.\n"; OutputArea.Text = OutputArea.Text + text + "\n"; return; } // Instantiate the joystick TheMat = new Joystick(directInput, joystickGuid); text = "Found Joystick/Gamepad with GUID: " + joystickGuid + "\n"; // Query all suported ForceFeedback effects var allEffects = TheMat.GetEffects(); if (allEffects.Count == 0) { text = text + "No effects available for this controller.\n"; } foreach (var effectInfo in allEffects) { text = text + "Effect available: " + effectInfo.Name + "\n"; } //Capabilities text = text + "Axe Count: " + TheMat.Capabilities.AxeCount.ToString() + "\n"; text = text + "Button Count: " + TheMat.Capabilities.ButtonCount.ToString() + "\n"; text = text + "Driver Version: " + TheMat.Capabilities.DriverVersion.ToString() + "\n"; text = text + "Firmware Revision: " + TheMat.Capabilities.FirmwareRevision.ToString() + "\n"; text = text + "Force Feedback Minimum Time Resolution: " + TheMat.Capabilities.ForceFeedbackMinimumTimeResolution.ToString() + "\n"; text = text + "Force Feedback Sample Period: " + TheMat.Capabilities.ForceFeedbackSamplePeriod.ToString() + "\n"; text = text + "Hardware Revision: " + TheMat.Capabilities.HardwareRevision.ToString() + "\n"; text = text + "Pov Count: " + TheMat.Capabilities.PovCount.ToString() + "\n"; text = text + "Is Human Interface Device: " + TheMat.Capabilities.IsHumanInterfaceDevice.ToString() + "\n"; text = text + "Sub-Type: " + TheMat.Capabilities.Subtype.ToString() + "\n"; //Properies text = text + "Axis Mode: " + TheMat.Properties.AxisMode.ToString() + "\n"; text = text + "Buffer Size: " + TheMat.Properties.BufferSize.ToString() + "\n"; text = text + "Class GUID: " + TheMat.Properties.ClassGuid.ToString() + "\n"; text = text + "Force Feedback Gain: " + TheMat.Properties.ForceFeedbackGain.ToString() + "\n"; text = text + "Interface Path: " + TheMat.Properties.InterfacePath.ToString() + "\n"; text = text + "Product name: " + TheMat.Properties.ProductName.ToString() + "\n"; text = text + "Joystick ID: " + TheMat.Properties.JoystickId.ToString() + "\n"; text = text + "Product ID: " + TheMat.Properties.ProductId.ToString() + "\n"; text = text + "Vendor ID: " + TheMat.Properties.VendorId.ToString() + "\n"; text = text + "Created Effects Count: " + TheMat.CreatedEffects.Count.ToString() + "\n"; text = text + "Usage: " + TheMat.Information.Usage.ToString() + "\n"; OutputArea.Text = OutputArea.Text + text + "\n"; // Set BufferSize in order to use buffered data. TheMat.Properties.BufferSize = 128; //TheMat.SetDataFormat(DeviceDataFormat.Joystick); // Acquire the joystick TheMat.Acquire(); //TheMat.SetCooperativeLevel(Handle, CooperativeLevel.Background | CooperativeLevel.NonExclusive); while (1 == 1) { try { TheMat.Poll(); var stateData = TheMat.GetCurrentState(); bool[] ButtonState = stateData.Buttons; for (int i = 0; i <= ButtonState.Length - 1; i++) { if (ButtonState[i] == true) { OutputArea2.Text = OutputArea2.Text + "Button " + i + " pressed\n"; } } //var bufferedData = TheMat.GetBufferedData(); //This is totally useless, lol. //OutputArea2.Text = OutputArea2.Text + bData.ToString() + "\n"; /* * This gets the raw buffered data. I do not want to mess around sorting through the string data returned, just the change in state will be fine thanks. * foreach (var rawbuffereddata in bufferedData) * { * OutputArea2.Text = OutputArea2.Text + rawbuffereddata.ToString() + "\n"; * } */ } catch { OutputArea2.Text = OutputArea2.Text + "Disconnected. Attempting graceful controller exit.\n"; TheMat.Dispose(); OutputArea2.Text = OutputArea2.Text + "Disposed controller successfully, graceful disconnect achieved!\n"; break; } } }
private void Start() { joystick = spellStickContainer.GetComponent <Joystick>(); spellCaster = GetComponent <SpellCaster>(); }
public void tポーリング(bool bWindowがアクティブ中) { #region [ bButtonフラグ初期化 ] for (int i = 0; i < 256; i++) { this.bButtonPushDown[i] = false; this.bButtonPullUp[i] = false; } #endregion if (bWindowがアクティブ中) { this.list入力イベント.Clear(); // #xxxxx 2012.6.11 yyagi; To optimize, I removed new(); #region [ 入力 ] //----------------------------- JoystickState ButtonState = Joystick.GetState(ID); if (ButtonState.IsConnected) { #region [ X軸- ] //----------------------------- if (ButtonState.GetAxis(0) < -0.5) { if (this.bButtonState[0] == false) { STInputEvent ev = new STInputEvent() { nKey = 0, b押された = true, nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms, // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。 }; this.list入力イベント.Add(ev); this.bButtonState[0] = true; this.bButtonPushDown[0] = true; } } else { if (this.bButtonState[0] == true) { STInputEvent ev = new STInputEvent() { nKey = 0, b押された = false, nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms, // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。 }; this.list入力イベント.Add(ev); this.bButtonState[0] = false; this.bButtonPullUp[0] = true; } } //----------------------------- #endregion #region [ X軸+ ] //----------------------------- if (ButtonState.GetAxis(0) > 0.5) { if (this.bButtonState[1] == false) { STInputEvent ev = new STInputEvent() { nKey = 1, b押された = true, nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms, // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。 }; this.list入力イベント.Add(ev); this.bButtonState[1] = true; this.bButtonPushDown[1] = true; } } else { if (this.bButtonState[1] == true) { STInputEvent event7 = new STInputEvent() { nKey = 1, b押された = false, nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms, // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。 }; this.list入力イベント.Add(event7); this.bButtonState[1] = false; this.bButtonPullUp[1] = true; } } //----------------------------- #endregion #region [ Y軸- ] //----------------------------- if (ButtonState.GetAxis(1) < -0.5) { if (this.bButtonState[2] == false) { STInputEvent ev = new STInputEvent() { nKey = 2, b押された = true, nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms, // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。 }; this.list入力イベント.Add(ev); this.bButtonState[2] = true; this.bButtonPushDown[2] = true; } } else { if (this.bButtonState[2] == true) { STInputEvent ev = new STInputEvent() { nKey = 2, b押された = false, nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms, // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。 }; this.list入力イベント.Add(ev); this.bButtonState[2] = false; this.bButtonPullUp[2] = true; } } //----------------------------- #endregion #region [ Y軸+ ] //----------------------------- if (ButtonState.GetAxis(1) > 0.5) { if (this.bButtonState[3] == false) { STInputEvent ev = new STInputEvent() { nKey = 3, b押された = true, nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms, // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。 }; this.list入力イベント.Add(ev); this.bButtonState[3] = true; this.bButtonPushDown[3] = true; } } else { if (this.bButtonState[3] == true) { STInputEvent ev = new STInputEvent() { nKey = 3, b押された = false, nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms, // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。 }; this.list入力イベント.Add(ev); this.bButtonState[3] = false; this.bButtonPullUp[3] = true; } } //----------------------------- #endregion #region [ Z軸- ] //----------------------------- if (ButtonState.GetAxis(2) < -0.5) { if (this.bButtonState[4] == false) { STInputEvent ev = new STInputEvent() { nKey = 4, b押された = true, nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms, // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。 }; this.list入力イベント.Add(ev); this.bButtonState[4] = true; this.bButtonPushDown[4] = true; } } else { if (this.bButtonState[4] == true) { STInputEvent ev = new STInputEvent() { nKey = 4, b押された = false, nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms, // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。 }; this.list入力イベント.Add(ev); this.bButtonState[4] = false; this.bButtonPullUp[4] = true; } } //----------------------------- #endregion #region [ Z軸+ ] //----------------------------- if (ButtonState.GetAxis(2) > 0.5) { if (this.bButtonState[5] == false) { STInputEvent ev = new STInputEvent() { nKey = 5, b押された = true, nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms, // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。 }; this.list入力イベント.Add(ev); this.bButtonState[5] = true; this.bButtonPushDown[5] = true; } } else { if (this.bButtonState[5] == true) { STInputEvent event15 = new STInputEvent() { nKey = 5, b押された = false, nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms, // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。 }; this.list入力イベント.Add(event15); this.bButtonState[5] = false; this.bButtonPullUp[5] = true; } } //----------------------------- #endregion #region [ Z軸回転- ] //----------------------------- if (ButtonState.GetAxis(3) < -0.5) { if (this.bButtonState[6] == false) { STInputEvent ev = new STInputEvent() { nKey = 6, b押された = true, nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms, // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。 }; this.list入力イベント.Add(ev); this.bButtonState[6] = true; this.bButtonPushDown[6] = true; } } else { if (this.bButtonState[4] == true) { STInputEvent ev = new STInputEvent() { nKey = 6, b押された = false, nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms, // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。 }; this.list入力イベント.Add(ev); this.bButtonState[6] = false; this.bButtonPullUp[6] = true; } } //----------------------------- #endregion #region [ Z軸回転+ ] //----------------------------- if (ButtonState.GetAxis(3) > 0.5) { if (this.bButtonState[7] == false) { STInputEvent ev = new STInputEvent() { nKey = 7, b押された = true, nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms, // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。 }; this.list入力イベント.Add(ev); this.bButtonState[7] = true; this.bButtonPushDown[7] = true; } } else { if (this.bButtonState[7] == true) { STInputEvent event15 = new STInputEvent() { nKey = 7, b押された = false, nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms, // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。 }; this.list入力イベント.Add(event15); this.bButtonState[7] = false; this.bButtonPullUp[7] = true; } } //----------------------------- #endregion #region [ Button ] //----------------------------- bool bIsButtonPressedReleased = false; for (int j = 0; j < 128; j++) { if (this.bButtonState[8 + j] == false && ButtonState.IsButtonDown(j)) { STInputEvent item = new STInputEvent() { nKey = 8 + j, b押された = true, nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms, // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。 }; this.list入力イベント.Add(item); this.bButtonState[8 + j] = true; this.bButtonPushDown[8 + j] = true; bIsButtonPressedReleased = true; } else if (this.bButtonState[8 + j] == true && !ButtonState.IsButtonDown(j)) { STInputEvent item = new STInputEvent() { nKey = 8 + j, b押された = false, nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms, // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。 }; this.list入力イベント.Add(item); this.bButtonState[8 + j] = false; this.bButtonPullUp[8 + j] = true; bIsButtonPressedReleased = true; } } //----------------------------- #endregion // #24341 2011.3.12 yyagi: POV support #region [ POV HAT 4/8way (only single POV switch is supported)] JoystickHatState hatState = ButtonState.GetHat(JoystickHat.Hat0); for (int nWay = 0; nWay < 8; nWay++) { if (hatState.Position == (OpenTK.Input.HatPosition)nWay + 1) { if (this.bButtonState[8 + 128 + nWay] == false) { STInputEvent stevent = new STInputEvent() { nKey = 8 + 128 + nWay, b押された = true, nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms, // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。 }; this.list入力イベント.Add(stevent); this.bButtonState[stevent.nKey] = true; this.bButtonPushDown[stevent.nKey] = true; } bIsButtonPressedReleased = true; } } if (bIsButtonPressedReleased == false) // #xxxxx 2011.12.3 yyagi 他のボタンが何も押され/離されてない=POVが離された { int nWay = 0; for (int i = 8 + 0x80; i < 8 + 0x80 + 8; i++) { // 離されたボタンを調べるために、元々押されていたボタンを探す。 if (this.bButtonState[i] == true) // DirectInputを直接いじるならこんなことしなくて良いのに、あぁ面倒。 { // この処理が必要なために、POVを1個しかサポートできない。無念。 nWay = i; break; } } if (nWay != 0) { STInputEvent stevent = new STInputEvent() { nKey = nWay, b押された = false, nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms, // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。 }; this.list入力イベント.Add(stevent); this.bButtonState[nWay] = false; this.bButtonPullUp[nWay] = true; } } #endregion //----------------------------- #endregion } } }
public static float GetAxisRaw(SPInputId axis, Joystick joystick = Joystick.All) { return(UnityEngine.Input.GetAxisRaw(GetInputName(axis, joystick))); }
public static bool TryPollButton(out SPInputId button, ButtonState state = ButtonState.Down, Joystick joystick = Joystick.All) { if (joystick != Joystick.None) { for (int i = ID_BUTTONLOW; i <= ID_BUTTONHIGH; i++) { switch (state) { case ButtonState.None: if (!UnityEngine.Input.GetButton(GetInputName((SPInputId)i, joystick))) { button = (SPInputId)i; return(true); } break; case ButtonState.Down: if (UnityEngine.Input.GetButtonDown(GetInputName((SPInputId)i, joystick))) { button = (SPInputId)i; return(true); } break; case ButtonState.Held: if (UnityEngine.Input.GetButton(GetInputName((SPInputId)i, joystick))) { button = (SPInputId)i; return(true); } break; case ButtonState.Released: if (UnityEngine.Input.GetButtonUp(GetInputName((SPInputId)i, joystick))) { button = (SPInputId)i; return(true); } break; } } } button = SPInputId.Unknown; return(false); }
public void update() { Joystick.Update(); for (uint index = 0; index < numSupportedPads; index++) { if (!Joystick.IsConnected(index)) { if (padInputs.ContainsKey(index)) { unregisterPad(index); } } else { if (!padInputs.ContainsKey(index)) { registerPad(index); } Input input = padInputs[index]; for (uint i = 0; i < (uint)GamePadButton.BUTTONNUM; i++) { input.oldButton[i] = input.currentButton[i]; input.currentButton[i] = Joystick.IsButtonPressed(index, i); } input.rightStick = 0.01F * new Vector2(Joystick.GetAxisPosition(index, Joystick.Axis.U), -Joystick.GetAxisPosition(index, Joystick.Axis.R)); input.rightStick = adjustDeadZone(input.rightStick); input.leftStick = 0.01F * new Vector2(Joystick.GetAxisPosition(index, Joystick.Axis.X), -Joystick.GetAxisPosition(index, Joystick.Axis.Y)); input.leftStick = adjustDeadZone(input.leftStick); input.LTRT = Joystick.GetAxisPosition(index, Joystick.Axis.Z); padInputs[index] = input; } } }
public static bool GetButton(SPInputId button, Joystick joystick = Joystick.All) { return(UnityEngine.Input.GetButton(GetInputName(button, joystick))); }
void Start() { audioSource = GetComponent <AudioSource>(); playerMove = transform.parent.GetComponent <PlayerJoyStickMovement>().moveStick; }
public static string GetInputName(SPInputId id, Joystick joystick = Joystick.All) { if (id == SPInputId.Unknown) { return(null); } if (_inputIdToName == null) { _inputIdToName = new Dictionary <int, string>(); } int hash = (int)joystick | ((int)id << 4); string sname; if (_inputIdToName.TryGetValue(hash, out sname)) { return(sname); } if (joystick == Joystick.All) { if (id.IsJoyAxis()) { sname = string.Format("JoyAll-Axis{0:00}", (int)id); } else if (id.IsMouseAxis()) { sname = string.Format("MouseAxis{0:0}", (int)id - (int)SPInputId.MouseAxis1 + 1); } else if (id.IsJoyButton()) { sname = string.Format("JoyAll-Button{0:00}", (int)id - (int)SPInputId.Button0); } else if (id.IsMouseButton()) { sname = string.Format("MouseButton{0:0}", (int)id - (int)SPInputId.MouseButton0); } } else { if (id.IsJoyAxis()) { sname = string.Format("Joy{0:0}-Axis{1:00}", (int)joystick, (int)id); } else if (id.IsMouseAxis()) { sname = string.Format("MouseAxis{0:0}", (int)id - (int)SPInputId.MouseAxis1 + 1); } else if (id.IsJoyButton()) { sname = string.Format("Joy{0:0}-Button{1:00}", (int)joystick, (int)id - (int)SPInputId.Button0); } else if (id.IsMouseButton()) { sname = string.Format("MouseButton{0:0}", (int)id - (int)SPInputId.MouseButton0); } } _inputIdToName[hash] = sname; return(sname); }
public void SetJoystick(int playerId, Joystick joystick) { if (!initialized) { return; } this.playerId = playerId; this.joystick = joystick; if (joystick == null) { Debug.LogError("Rewired Control Mapper: Joystick cannot be null!"); return; } // Create axis list float buttonHeight = 0.0f; for (int i = 0; i < joystick.axisCount; i++) { int index = i; GameObject instance = UITools.InstantiateGUIObject <Button>(axisButtonPrefab, axisScrollAreaContent, "Axis" + i); Button button = instance.GetComponent <Button>(); button.onClick.AddListener(() => { OnAxisSelected(index, button); }); Text text = UnityTools.GetComponentInSelfOrChildren <Text>(instance); if (text != null) { text.text = ControlMapper.GetLanguage().GetElementIdentifierName(joystick, joystick.AxisElementIdentifiers[i].id, AxisRange.Full); } if (buttonHeight == 0.0f) { buttonHeight = UnityTools.GetComponentInSelfOrChildren <LayoutElement>(instance).minHeight; } axisButtons.Add(button); } // set axis list height float vSpacing = axisScrollAreaContent.GetComponent <VerticalLayoutGroup>().spacing; axisScrollAreaContent.sizeDelta = new Vector2(axisScrollAreaContent.sizeDelta.x, Mathf.Max((joystick.axisCount * (buttonHeight + vSpacing) - vSpacing), axisScrollAreaContent.sizeDelta.y)); // Store the original calibration data so we can revert origCalibrationData = joystick.calibrationMap.ToXmlString(); // Record info displayAreaWidth = rightContentContainer.sizeDelta.x; // Try to get the UI control axis deadzone from the RewiredStandaloneInputModule if it exists in the hierarchy // This is used to prevent users from rendering menu navigation axes unusable by changing the axis sensitivity rewiredStandaloneInputModule = gameObject.transform.root.GetComponentInChildren <RewiredStandaloneInputModule>(); if (rewiredStandaloneInputModule != null) { menuHorizActionId = ReInput.mapping.GetActionId(rewiredStandaloneInputModule.horizontalAxis); menuVertActionId = ReInput.mapping.GetActionId(rewiredStandaloneInputModule.verticalAxis); } // Select first axis if (joystick.axisCount > 0) { SelectAxis(0); } // Set default UI element defaultUIElement = doneButton.gameObject; // Draw window RefreshControls(); Redraw(); }
public void Update() { state = Joystick.GetState(_stickIdx); }
private JoystickTrigger SpotTrigger(Joystick joystick, JoystickState oldState, JoystickState newState) { /////////////////////// // Check the buttons bool[] oldButtons = oldState.GetButtons(); bool[] newButtons = newState.GetButtons(); for (int button = 0; button < joystick.Capabilities.ButtonCount; button++) { // it may be pressed, but it only counts if it's newly pressed. if (newButtons[button] && !oldButtons[button]) { var newTrigger = new JoystickTrigger(); newTrigger.DeviceInstance = joystick.Information.InstanceGuid.ToString(); newTrigger.Type = JoystickTriggerType.Button; newTrigger.ButtonNumber = button; return(newTrigger); } } /////////////////////// // Check each axis var axi = (JoystickTriggerAxis[])Enum.GetValues(typeof(JoystickTriggerAxis)); foreach (JoystickTriggerAxis axis in axi) { int oldAxisValue = JoyInput.GetAxisValue(oldState, axis); int newAxisValue = JoyInput.GetAxisValue(newState, axis); if (oldAxisValue != newAxisValue) { bool positive; if (newAxisValue < 16384) { positive = false; } else if (newAxisValue > 49152) { positive = true; } else { continue; // the axis isn't far enough. Screw em! } var newTrigger = new JoystickTrigger(); newTrigger.DeviceInstance = joystick.Information.InstanceGuid.ToString(); newTrigger.Type = JoystickTriggerType.Axis; newTrigger.Axis = axis; newTrigger.AxisPositive = positive; return(newTrigger); } } /////////////////////// // Check each Point-Of-View (POV) thingie. int[] oldPovs = oldState.GetPointOfViewControllers(); int[] newPovs = newState.GetPointOfViewControllers(); for (int pov = 0; pov < joystick.Capabilities.PovCount; pov++) { int newPov = newPovs[pov]; if ((newPov != -1) && (newPov != oldPovs[pov])) { JoystickTriggerPovDirection direction; if (newPov == 0) { direction = JoystickTriggerPovDirection.Up; } else if (newPov == 9000) { direction = JoystickTriggerPovDirection.Right; } else if (newPov == 18000) { direction = JoystickTriggerPovDirection.Down; } else if (newPov == 27000) { direction = JoystickTriggerPovDirection.Left; } else { continue; // we don't accept diagnols here. } var newTrigger = new JoystickTrigger(); newTrigger.DeviceInstance = joystick.Information.InstanceGuid.ToString(); newTrigger.Type = JoystickTriggerType.Pov; newTrigger.PovNumber = pov; newTrigger.PovDirection = direction; return(newTrigger); } } // We checked everything. There's no new trigger to be found. return(null); }
private void Start() { joystick = FindObjectOfType <Joystick>(); joyButton = FindObjectOfType <JoyButton>(); }
// Start is called before the first frame update void Awake() { _joystick = FindObjectOfType <Joystick>(); }
// private ButtonControler bcontrl; // Start is called before the first frame update // void OnBecameVisible() // { // // enabled = true; // print(true) // } void Start() { ch_controller = GetComponent <CharacterController>(); joystick = FindObjectOfType <Joystick>(); // joystick = GameObject.Find("Jump"); }
//CTOR public ManuelPilotViewModel(IMainWinModel m, Joystick j) { model = m; joystick = j; }
public static SPInputId[] PollAllButtons(ButtonState state = ButtonState.Down, Joystick joystick = Joystick.All) { if (joystick != Joystick.None) { using (var lst = com.spacepuppy.Collections.TempCollection.GetList <SPInputId>()) { for (int i = ID_BUTTONLOW; i <= ID_BUTTONHIGH; i++) { switch (state) { case ButtonState.None: if (!UnityEngine.Input.GetButton(GetInputName((SPInputId)i, joystick))) { lst.Add((SPInputId)i); } break; case ButtonState.Down: if (UnityEngine.Input.GetButtonDown(GetInputName((SPInputId)i, joystick))) { lst.Add((SPInputId)i); } break; case ButtonState.Held: if (UnityEngine.Input.GetButton(GetInputName((SPInputId)i, joystick))) { lst.Add((SPInputId)i); } break; case ButtonState.Released: if (UnityEngine.Input.GetButtonUp(GetInputName((SPInputId)i, joystick))) { lst.Add((SPInputId)i); } break; } } return(lst.Count > 0 ? lst.ToArray() : com.spacepuppy.Utils.ArrayUtil.Empty <SPInputId>()); } } return(com.spacepuppy.Utils.ArrayUtil.Empty <SPInputId>()); }
// Use this for initialization void Start() { joystick = FindObjectOfType <Joystick>(); }
/// <summary> /// Updates the joystick class. Joysticks do not work if this is not done regularly. /// </summary> public void ControllerUpdate() { Joystick.Update(); }
public static Vector3 GetPlayerJoystickMove(Joystick joystick) { return(new Vector3(joystick.Horizontal, 0, joystick.Vertical)); }
/// <summary> /// Loads the form, setting the controls to the initial style. /// </summary> private void DirectInputAxisPropertiesForm_Load(object sender, EventArgs e) { this.txtText.Text = this.initialDefinition.Text; this.txtShiftText.Text = this.initialDefinition.ShiftText; this.txtTextPosition.X = this.initialDefinition.TextPosition.X; this.txtTextPosition.Y = this.initialDefinition.TextPosition.Y; this.lstBoundaries.Items.AddRange(this.initialDefinition.Boundaries.Cast <object>().ToArray()); this.chkChangeOnCaps.Checked = this.initialDefinition.ChangeOnCaps; this.txtDeviceId.Text = this.initialDefinition.DeviceId.ToString(); // Retrieves all of the currently available joysticks and lists them here this.devices = HookManager.GetCurrentlyActiveJoysticks(); var data = new List <JoystickComboBoxItem>(); data.Add(new JoystickComboBoxItem(Guid.Empty.ToString(), "No Device Selected")); foreach (var device in this.devices) { data.Add(new JoystickComboBoxItem(device.Information.ProductGuid.ToString(), device.Information.ProductName)); } // Sets the other Joystick(s) values this.txtStickWidth.Text = this.initialDefinition.StickWidth.ToString(); this.txtStickHeight.Text = this.initialDefinition.StickHeight.ToString(); this.txtAxisOneMax.Text = this.initialDefinition.AxisOneMax.ToString(); this.txtAxisTwoMax.Text = this.initialDefinition.AxisTwoMax.ToString(); this.chkInvertAxisOne.Checked = this.initialDefinition.InvertAxisOne == 1; this.chkInvertAxisTwo.Checked = this.initialDefinition.InvertAxisTwo == 1; // Sets the Joystick Combobox DataSource this.comboBoxDevicesList.ValueMember = "ID"; this.comboBoxDevicesList.DisplayMember = "Text"; this.comboBoxDevicesList.DataSource = data; // If one of the currently available joysticks matches the ID of the currentDefinition, we take it as the currently selected one foreach (var joystick in this.devices) { if (joystick.Information.ProductGuid == this.currentDefinition.DeviceId) { this.selectedJoystick = joystick; this.comboBoxDevicesList.SelectedValue = joystick.Information.ProductGuid.ToString(); break; } } // Refreshes the Buttons dropdown RefreshFormOnJoystickChange(); // Only add the event handlers after the initial properties have been set. this.lstBoundaries.SelectedIndexChanged += this.lstBoundaries_SelectedIndexChanged; this.txtText.TextChanged += this.txtText_TextChanged; this.txtTextPosition.ValueChanged += this.txtTextPosition_ValueChanged; this.txtShiftText.TextChanged += this.txtShiftText_TextChanged; this.chkChangeOnCaps.CheckedChanged += this.chkChangeOnCaps_CheckedChanged; this.txtDeviceId.TextChanged += this.txtDeviceId_TextChanged; this.comboBoxDevicesList.SelectedIndexChanged += this.comboBoxDevicesList_SelectedIndexChanged; this.cmbAxisOne.SelectedIndexChanged += this.cmbAxisOne_SelectedIndexChanged; this.cmbAxisTwo.SelectedIndexChanged += this.cmbAxisTwo_SelectedIndexChanged; this.txtAxisOneMax.TextChanged += this.txtAxisOneMax_TextChanged; this.txtAxisTwoMax.TextChanged += this.txtAxisTwoMax_TextChanged; this.txtStickWidth.TextChanged += this.txtStickWidth_TextChanged; this.txtStickHeight.TextChanged += this.txtStickHeight_TextChanged; this.chkInvertAxisOne.CheckedChanged += this.chkInvertAxisOne_CheckedChanged; this.chkInvertAxisTwo.CheckedChanged += this.chkInvertAxisTwo_CheckedChanged; }
/// <summary> /// Parse string argument and try to create <see cref="JoystickInput"/> instance. /// </summary> /// <returns>Parsed JoystickInput.</returns> /// <param name="value">String representation of JoystickInput.</param> public static JoystickInput FromString(string value) { if (value == null) { return(null); } KeyModifier modifiers = ModifiersFromString(ref value); if (!value.StartsWith("Joystick ")) { return(null); } value = value.Substring(9); if (value.Length == 0) { return(null); } Joystick target; if (value[0] >= '0' && value[0] <= '9') { int index = value.IndexOf(" "); if (index < 0) { return(null); } try { int targetNumber = Convert.ToInt32(value.Substring(0, index)); if ( targetNumber < 1 || targetNumber >= (int)Joystick.None ) { return(null); } target = (Joystick)targetNumber; } catch (Exception) { return(null); } value = value.Substring(index + 1); } else { target = Joystick.AllJoysticks; } if (value.StartsWith("Axis ")) { value = value.Substring(5); bool positive; if (value.EndsWith(" (-)")) { positive = false; } else if (value.EndsWith(" (+)")) { positive = true; } else { return(null); } value = value.Remove(value.Length - 4); try { int axisNumber = (Convert.ToInt32(value) - 1) * 2; if (!positive) { ++axisNumber; } if ( axisNumber < 0 || axisNumber >= (int)JoystickAxis.None ) { return(null); } return(new JoystickInput((JoystickAxis)axisNumber, target, modifiers)); } catch (Exception) { return(null); } } if (!value.StartsWith("Button ")) { return(null); } value = value.Substring(7); try { int button = Convert.ToInt32(value) - 1; if ( button < 0 || button >= (int)JoystickButton.None ) { return(null); } return(new JoystickInput((JoystickButton)button, target, modifiers)); } catch (Exception) { return(null); } }
private void PollJoystick() { _pollingTask = Task.Factory.StartNew(() => { var lastSate = new List <JoystickUpdate>(); var joystick = new Joystick(_directInput, _deviceGuid) { Properties = { BufferSize = 0, AxisMode = DeviceAxisMode.Absolute, Range = new InputRange(0, 1000) } }; joystick.SetCooperativeLevel(IntPtr.Zero, CooperativeLevel.Background | CooperativeLevel.NonExclusive); joystick.Acquire(); while (!_quitPolling) { try { joystick.Poll(); var data = new JoystickState(); joystick.GetCurrentState(ref data); var args = new JoystickUpdateEventArgs(data.X, data.Y, data.Z, data.RotationX, data.RotationY, data.RotationZ, data.Sliders[0], data.Sliders[1]); JoystickUpdate?.Invoke(this, args); GlobalEventAggregator.Instance.SendMessage(args); //Debug.WriteLine("X: {0}, Y: {1}, Z: {2}", data.X, data.Y, data.Z); //var data1 = joystick.GetBufferedData(); //foreach (var state in data1) //{ // var lastUpdate = lastSate.FirstOrDefault(f => f.Offset == state.Offset); // if (lastUpdate.Timestamp == 0) // { // lastSate.Add(state); // } // if (state.Offset == JoystickOffset.X && state.Value != lastUpdate.Value) // { // ////PostAxisValue(iDevice, HID_USAGE_X, state.lX); // Debug.WriteLine("{0}: {1}", state.Offset, state.Value); // } // lastUpdate = state; //} //Task.Delay(10); } catch (SharpDX.SharpDXException e) { StopCapture(); } } joystick.Dispose(); }); }
public Input(TgcD3dInput _keyboard, Joystick _joystick) { this.keyboard = _keyboard; this.joystick = _joystick; }
void Start() { joystick = GameObject.Find("Floating Joystick").GetComponent <Joystick>(); animator = transform.Find("ybot").GetComponent <Animator>(); }
public void CaptureJoysticks() { // Initialize DirectInput var directInput = new DirectInput(); // Find all joysticks connected to the system IList<DeviceInstance> connectedJoysticks = new List<DeviceInstance>(); // - look for gamepads foreach (var deviceInstance in directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices)) { connectedJoysticks.Add(deviceInstance); } // - look for joysticks foreach (var deviceInstance in directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices)) { connectedJoysticks.Add(deviceInstance); } // Use the two first joysticks found if (connectedJoysticks.Count >= 1) { joystick1 = new Joystick(directInput, connectedJoysticks[0].InstanceGuid); Joystick1DeviceName = connectedJoysticks[0].InstanceName; joystick1.Acquire(); } if (connectedJoysticks.Count >= 2) { joystick2 = new Joystick(directInput, connectedJoysticks[1].InstanceGuid); Joystick2DeviceName = connectedJoysticks[1].InstanceName; joystick2.Acquire(); } }