// Utility public static void GetState(ref NpadState pOutValue, NpadId npadId, NpadStyle npadStyle) { NpadButton preButtons = pOutValue.buttons; switch (npadStyle) { case NpadStyle.FullKey: NpadFullKey.GetState(ref pOutValue, npadId); break; case NpadStyle.Handheld: NpadHandheld.GetState(ref pOutValue, npadId); break; case NpadStyle.JoyDual: NpadJoyDual.GetState(ref pOutValue, npadId); break; case NpadStyle.JoyLeft: NpadJoyLeft.GetState(ref pOutValue, npadId); break; case NpadStyle.JoyRight: NpadJoyRight.GetState(ref pOutValue, npadId); break; } pOutValue.preButtons = preButtons; }
/// <summary> /// 振動の実装部 /// </summary> /// <param name="_Index">コントローラーの番号</param> /// <param name="_LowPow">低周波の振動の強さ</param> /// <param name="_HighPow">高周波の振動の強さ</param> static void VibrationImpl(int _Index, float _LowPow, float _HighPow) { //未接続なら何もしない if (!SwitchManager.GetInstance().IsConnect(_Index)) { return; } //IDの取得 NpadId npadId = SwitchManager.GetInstance().GetNpadId(_Index); //スタイルの取得 NpadStyle npadStyle = Npad.GetStyleSet(npadId); //デバイスの数を取得(0か1のみ取得する) int deviceCount = Vibration.GetDeviceHandles( m_VibrationDeviceHandles, 1, npadId, npadStyle); //デバイスの数が1じゃない場合は何もしない if (deviceCount != 1) { return; } //パワーをセット m_VibrationValue.amplitudeLow = _LowPow; m_VibrationValue.amplitudeHigh = _HighPow; //デバイスの初期化 Vibration.InitializeDevice(m_VibrationDeviceHandles[0]); //振動の値をセット Vibration.SendValue(m_VibrationDeviceHandles[0], m_VibrationValue); }
private bool UpdatePadState() { NpadStyle handheldStyle = Npad.GetStyleSet(NpadId.Handheld); NpadState handheldState = new NpadState(); if (handheldStyle != NpadStyle.None) { Npad.GetState(ref handheldState, NpadId.Handheld, handheldStyle); if (handheldState.buttons != NpadButton.None) { if ((npadId != NpadId.Handheld) || (npadStyle != handheldStyle)) { this.GetSixAxisSensor(NpadId.Handheld, handheldStyle); } npadId = NpadId.Handheld; npadStyle = handheldStyle; npadState = handheldState; return(true); } } NpadStyle no1Style = Npad.GetStyleSet(NpadId.No1); NpadState no1State = new NpadState(); if (no1Style != NpadStyle.None) { Npad.GetState(ref no1State, NpadId.No1, no1Style); if (no1State.buttons != NpadButton.None) { if ((npadId != NpadId.No1) || (npadStyle != no1Style)) { this.GetSixAxisSensor(NpadId.No1, no1Style); } npadId = NpadId.No1; npadStyle = no1Style; npadState = no1State; return(true); } } if ((npadId == NpadId.Handheld) && (handheldStyle != NpadStyle.None)) { npadId = NpadId.Handheld; npadStyle = handheldStyle; npadState = handheldState; } else if ((npadId == NpadId.No1) && (no1Style != NpadStyle.None)) { npadId = NpadId.No1; npadStyle = no1Style; npadState = no1State; } else { npadId = NpadId.Invalid; npadStyle = NpadStyle.Invalid; npadState.Clear(); return(false); } return(true); }
/// <summary> /// 振動の実装部 /// </summary> /// <param name="index">コントローラーの番号</param> /// <param name="lowPow">低周波の振動の強さ</param> /// <param name="highPow">高周波の振動の強さ</param> static void VibrationImpl(int index, float lowPow, float highPow) { #if UNITY_SWITCH && !(UNITY_EDITOR) //未接続なら何もしない if (!SwitchManager.GetInstance().IsConnect(index)) { return; } //IDの取得 NpadId npadId = SwitchManager.GetInstance().GetNpadId(index); //スタイルの取得 NpadStyle npadStyle = Npad.GetStyleSet(npadId); //デバイスの数を取得(0か1のみ取得する) int deviceCount = Vibration.GetDeviceHandles( vibrationDeviceHandles, 1, npadId, npadStyle); //デバイスの数が1じゃない場合は何もしない if (deviceCount != 1) { return; } //パワーをセット vibrationValue.amplitudeLow = lowPow; vibrationValue.amplitudeHigh = highPow; //デバイスの初期化 Vibration.InitializeDevice(vibrationDeviceHandles[0]); //振動の値をセット Vibration.SendValue(vibrationDeviceHandles[0], vibrationValue); #endif }
/// <summary> /// Gets the settings for a specific Npad id. /// </summary> /// <param name="npadId">The Npad id.</param> /// <returns>Npad settings.</returns> public Rewired.Platforms.Switch.Config.INpadSettings GetNpadSettings(NpadId npadId) { NpadSettings_Internal settings; if (!_userData.npadSettings.TryGetValue(npadId, out settings)) { return(null); } return(new NpadSettings(npadId, settings)); }
private void NowStyle() { NpadId npadId = NpadId.Handheld; NpadStyle npadStyle = NpadStyle.None; npadStyle = Npad.GetStyleSet(npadId); if (npadStyle != NpadStyle.Handheld) { npadStyle = Npad.GetStyleSet(npadId); } }
private void GetSixAxisSensor(NpadId id, NpadStyle style) { for (int i = 0; i < handleCount; i++) { SixAxisSensor.Stop(handle[i]); } handleCount = SixAxisSensor.GetHandles(handle, 2, id, style); for (int i = 0; i < handleCount; i++) { SixAxisSensor.Start(handle[i]); } }
protected override void RefreshConfiguration() { base.RefreshConfiguration(); var command = NPadStatusReport.Create(); if (ExecuteCommand(ref command) > 0) { m_NpadId = command.npadId; m_Orientation = command.orientation; m_StyleMask = command.styleMask; ReadNNColorIntoJoyConColor(ref m_LeftControllerColor, command.colorLeftMain, command.colorLeftSub); ReadNNColorIntoJoyConColor(ref m_RightControllerColor, command.colorRightMain, command.colorRightSub); } }
/// <summary> /// 加速度の更新 /// </summary> static public void AccelerationUpdate(int index, NpadId npadId) { //未接続 if (!SwitchManager.GetInstance().IsConnect(index)) { return; } //スタイルの取得 npadStyle = Npad.GetStyleSet(npadId); SixAxisSensor.GetHandles(handles, 1, npadId, npadStyle); //ジャイロスタート SixAxisSensor.Start(handles[0]); SixAxisSensor.GetState(ref sixAxisSensorState, handles[0]); var switchAcceleration = sixAxisSensorState.acceleration; Acceleration[index].Set(switchAcceleration.x, switchAcceleration.y, switchAcceleration.z); }
/// <summary> /// 入力の更新 /// </summary> /// <param name="_Index">コントローラーの番号</param> /// <param name="_NpadId">パッドのID</param> static public void InputUpdate(int _Index, NpadId _NpadId) { #if UNITY_EDITOR for (int i = 0; i < (int)XboxInput.None; ++i) { m_XboxPrevButtons[_Index, i] = m_XboxCurrentButtons[_Index, i]; m_XboxCurrentButtons[_Index, i] = InputXboxButton(_Index, (XboxInput)i); } #endif m_PrevButtons[_Index] = m_CurrentButtons[_Index]; //未接続 if (!SwitchManager.GetInstance().IsConnect(_Index)) { return; } //スタイルを取得 NpadStyle npadStyle = Npad.GetStyleSet(_NpadId); //スタイルが合うかどうか if ((npadStyle & SwitchManager.GetInstance().GetNpadStyle()) == 0) { return; } //入力情報を取得 Npad.GetState(ref m_NpadState, _NpadId, npadStyle); m_CurrentButtons[_Index] = (long)m_NpadState.buttons; //スティックの更新 if (npadStyle == NpadStyle.JoyRight) { m_StickInfos[_Index].m_Horizontal = m_NpadState.analogStickR.fy; m_StickInfos[_Index].m_Vertical = -m_NpadState.analogStickR.fx; } else if (npadStyle == NpadStyle.JoyLeft) { m_StickInfos[_Index].m_Horizontal = -m_NpadState.analogStickL.fy; m_StickInfos[_Index].m_Vertical = m_NpadState.analogStickL.fx; } else { Debug.LogError("JoyRight,JoyLeft以外のStyleを取得"); } }
public static int GetStates( [Out] NpadStateArrayItem[] pOutValues, int count, NpadId npadId, NpadStyle npadStyle) { switch (npadStyle) { case NpadStyle.FullKey: return(NpadFullKey.GetStates(pOutValues, count, npadId)); case NpadStyle.Handheld: return(NpadHandheld.GetStates(pOutValues, count, npadId)); case NpadStyle.JoyDual: return(NpadJoyDual.GetStates(pOutValues, count, npadId)); case NpadStyle.JoyLeft: return(NpadJoyLeft.GetStates(pOutValues, count, npadId)); case NpadStyle.JoyRight: return(NpadJoyRight.GetStates(pOutValues, count, npadId)); } return(0); }
/// <summary> /// ジャイロの取得 /// </summary> /// <param name="_Index">コントローラーの番号</param> /// <returns>ジャイロの回転(使用するx軸のみ)</returns> static public float GetGyroX(int _Index) { //未接続なら0.0f if (!SwitchManager.GetInstance().IsConnect(_Index)) { return(0.0f); } //キーがない場合は追加しておく if (!m_BaseGyro.ContainsKey(_Index)) { m_BaseGyro.Add(_Index, 0.0f); } //IDの取得 NpadId npadId = SwitchManager.GetInstance().GetNpadId(_Index); //スタイルの取得 NpadStyle npadStyle = Npad.GetStyleSet(npadId); //ハンドラを取得 int handleCount = SixAxisSensor.GetHandles(m_GyroHandles, 1, npadId, npadStyle); //ハンドラの数が1じゃない場合は0.0f if (handleCount != 1) { return(0.0f); } //ジャイロスタート SixAxisSensor.Start(m_GyroHandles[0]); //状態の取得 SixAxisSensor.GetState(ref m_GyroState, m_GyroHandles[0]); //右か左で返す値を変換する if (npadStyle == NpadStyle.JoyRight) { return(m_GyroState.angle.x % 1 * 360 - 90 - m_BaseGyro[_Index]); } else { return(m_GyroState.angle.x % 1 * -360 + 90 - m_BaseGyro[_Index]); } }
/// <summary> /// ジャイロの取得の実装部 /// </summary> /// <param name="index">コントローラーの番号</param> /// <returns>ジャイロの回転</returns> static Quaternion GetGyroImpl(int index) { #if UNITY_SWITCH && !(UNITY_EDITOR) //IDの取得 NpadId npadId = SwitchManager.GetInstance().GetNpadId(index); //スタイルの取得 NpadStyle npadStyle = Npad.GetStyleSet(npadId); //ハンドラを取得 int handleCount = SixAxisSensor.GetHandles(gyroHandles, 1, npadId, npadStyle); //ハンドラの数が1じゃない場合はQuaternion.identity if (handleCount != 1) { return(Quaternion.identity); } //ジャイロスタート SixAxisSensor.Start(gyroHandles[0]); //状態の取得 SixAxisSensor.GetState(ref gyroState, gyroHandles[0]); gyroState.GetQuaternion(ref refQuaternion); quat.Set(refQuaternion.x, refQuaternion.z, refQuaternion.y, -refQuaternion.w); #endif return(quat); }
public NintendoSwitchInputDevice(NpadId nPadId) { NPadId = nPadId; NPadStyle = Npad.GetStyleSet(NPadId); NPadHoldType = NpadJoy.GetHoldType(); EnableSixAxisSensors = NintendoSwitchInputDeviceManager.EnableSixAxisSensors; SixAxisSensorHandles = new SixAxisSensorHandle[2]; SixAxisSensorStates = new SixAxisSensorState[2]; SixAxisSensorCount = 0; VibrationDeviceHandles = new VibrationDeviceHandle[2]; VibrationDeviceInfos = new VibrationDeviceInfo[2]; VibrationDeviceCount = 0; SortOrder = (int)NPadId; DeviceClass = InputDeviceClass.Controller; DeviceStyle = InputDeviceStyle.NintendoSwitch; IsPresent = false; Initialize(); }
public static extern void DestroyStyleSetUpdateEvent(NpadId npadId); // 0x00A1A2C0-0x00A1A2D0 public static extern NpadStyle GetStyleSet(NpadId npadId); // 0x00A1A2D0-0x00A1A2E0
public static extern bool IsStyleSetUpdated(NpadId npadId); // 0x00A1A2A0-0x00A1A2C0 public static extern void DestroyStyleSetUpdateEvent(NpadId npadId); // 0x00A1A2C0-0x00A1A2D0
public static extern void BindStyleSetUpdateEvent(NpadId npadId); // 0x00A1A290-0x00A1A2A0 public static extern bool IsStyleSetUpdated(NpadId npadId); // 0x00A1A2A0-0x00A1A2C0
} // 0x00A1A270-0x00A1A290 public static extern void BindStyleSetUpdateEvent(NpadId npadId); // 0x00A1A290-0x00A1A2A0
public NintendoSwitchInputDeviceManager() { DebugPad.Initialize(); CreateDebugDevice(); Npad.Initialize(); // NpadJoy.SetHoldType only affects how controllers behave when using a system applet. // NpadJoyHoldType.Vertical is the default setting, but most games would want to use // NpadJoyHoldType.Horizontal as it can support all controller styles. // // If you do use NpadJoyHoldType.Vertical, Npad.SetSupportedStyleSet must only list // controller types supported by NpadJoyHoldType.Vertical. If you don't, the controller // applet will fail to load. // // Supported types for NpadJoyHoldType.Vertical are: // NpadStyle.FullKey, NpadStyle.JoyLeft and NpadStyle.JoyRight NpadJoy.SetHoldType(NpadJoyHoldType.Horizontal); // Handheld = Joy-Con docked with the console. // FullKey = Pro Controller. // JoyDual = Two Joy-Con used together as one controller. // JoyLeft = Left Joy-Con used by itself. // JoyRight = Left Joy-Con used by itself. Npad.SetSupportedStyleSet(NpadStyle.Handheld | NpadStyle.FullKey | NpadStyle.JoyDual | NpadStyle.JoyLeft | NpadStyle.JoyRight); // Both controllers must be docked for handheld mode. NpadJoy.SetHandheldActivationMode(NpadHandheldActivationMode.Dual); // You must call Npad.SetSupportedIdType for all supported controllers. // Not calling this may lead to crashes in some circumstances. var nPadIds = new NpadId[] { NpadId.Handheld, NpadId.No1, NpadId.No2, NpadId.No3, NpadId.No4, NpadId.No5, NpadId.No6, NpadId.No7, NpadId.No8 }; Npad.SetSupportedIdType(nPadIds); // Create InControl devices for all NpadIds regardless of how many we request from NintendoSDK. CreateDevice(NpadId.Handheld); CreateDevice(NpadId.No1); CreateDevice(NpadId.No2); CreateDevice(NpadId.No3); CreateDevice(NpadId.No4); CreateDevice(NpadId.No5); CreateDevice(NpadId.No6); CreateDevice(NpadId.No7); CreateDevice(NpadId.No8); UpdateInternal(0, 0); ShowControllerSupportForSinglePlayer(false); InputManager.OnDeviceAttached += inputDevice => { if (!Gunhouse.AppEntry.HasAppStarted()) { UnityEngine.Debug.Log("<color=red>we're not in it yet. don't pop the controller applet</color>"); return; } else { UnityEngine.Debug.Log("<color=blue>it's ok to pop the applet.</color>"); } UnityEngine.Debug.Log("Attached: " + inputDevice.Name); ShowControllerSupportForSinglePlayer(false); }; /*InputManager.OnDeviceDetached += inputDevice => * { * UnityEngine.Debug.Log("Detached: " + inputDevice.Name); * ShowControllerSupportForSinglePlayer(false); * }; * InputManager.OnActiveDeviceChanged += inputDevice => * { * UnityEngine.Debug.Log("Switched: " + inputDevice.Name); * ShowControllerSupportForSinglePlayer(false); * };*/ }
void CreateDevice(NpadId nPadId) { devices.Add(new NintendoSwitchInputDevice(nPadId)); }
public static extern int GetStates([Out] NpadStateArrayItem[] pOutValues, int count, NpadId npadId);
public static extern Result GetControllerColor(ref NpadControllerColor pOutLeftColor, ref NpadControllerColor pOutRightColor, NpadId npadId); // 0x00A1A320-0x00A1A340 public static void GetState(ref NpadState pOutValue, NpadId npadId, NpadStyle npadStyle) { } // 0x00A1A340-0x00A1A3F0
public static extern byte GetPlayerLedPattern(NpadId npadId); // 0x00A1A2F0-0x00A1A300 public static extern Result GetControllerColor(ref NpadControllerColor pOutValue, NpadId npadId); // 0x00A1A300-0x00A1A320
public static extern NpadStyle GetStyleSet(NpadId npadId); // 0x00A1A2D0-0x00A1A2E0 public static extern void Disconnect(NpadId npadId); // 0x00A1A2E0-0x00A1A2F0
public static extern void Disconnect(NpadId npadId); // 0x00A1A2E0-0x00A1A2F0 public static extern byte GetPlayerLedPattern(NpadId npadId); // 0x00A1A2F0-0x00A1A300
public static extern int GetHandles(SixAxisSensorHandle[] pOutValues, int count, NpadId npadId, NpadStyle npadStyle);
public static extern Result GetControllerColor(ref NpadControllerColor pOutValue, NpadId npadId); // 0x00A1A300-0x00A1A320 public static extern Result GetControllerColor(ref NpadControllerColor pOutLeftColor, ref NpadControllerColor pOutRightColor, NpadId npadId); // 0x00A1A320-0x00A1A340
public static extern void GetState(ref NpadState pOutValue, NpadId npadId);
} // 0x00A1A340-0x00A1A3F0 public static int GetStates(out NpadStateArrayItem[] pOutValues, int count, NpadId npadId, NpadStyle npadStyle) { pOutValues = default; return(default);
public static extern int GetStates([Out] NpadJoyDualState[] pOutValues, int count, NpadId npadId);