예제 #1
0
    /// <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);
    }
예제 #2
0
    /// <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
    }
예제 #3
0
    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);
    }
예제 #4
0
    /// <summary>
    /// 接続状態の更新
    /// </summary>
    /// <param name="index">コントローラーの番号</param>
    /// <returns></returns>
    void ConnectUpdate(int index)
    {
        //スタイルがNoneならfalse
#if UNITY_SWITCH && !(UNITY_EDITOR)
        isConnect[index] = (Npad.GetStyleSet(npadIds[index]) != NpadStyle.None);
#else
        isConnect[index] = UnityEngine.Input.GetJoystickNames().Length >= index + 1;
#endif
    }
예제 #5
0
    private void NowStyle()
    {
        NpadId    npadId    = NpadId.Handheld;
        NpadStyle npadStyle = NpadStyle.None;

        npadStyle = Npad.GetStyleSet(npadId);

        if (npadStyle != NpadStyle.Handheld)
        {
            npadStyle = Npad.GetStyleSet(npadId);
        }
    }
예제 #6
0
    /// <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);
    }
예제 #7
0
    /// <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を取得");
        }
    }
예제 #8
0
        public void UpdateInternalState()
        {
            var oldNPadStyle    = NPadStyle;
            var oldNPadHoldType = NPadHoldType;

            NPadStyle = Npad.GetStyleSet(NPadId);
            if (HasNPadStyle)
            {
                NPadHoldType = NpadJoy.GetHoldType();
                Npad.GetState(ref state, NPadId, NPadStyle);
                IsPresent = (state.attributes & NpadAttribute.IsConnected) != 0;
            }
            else
            {
                IsPresent = false;
            }

            if (oldNPadStyle != NPadStyle || oldNPadHoldType != NPadHoldType)
            {
                Initialize();
            }
        }
예제 #9
0
파일: SwitchGyro.cs 프로젝트: SAKI-toki/U22
    /// <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]);
        }
    }
예제 #10
0
    /// <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);
    }
예제 #11
0
        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();
        }
예제 #12
0
    /// <summary>
    /// 入力の更新
    /// </summary>
    /// <param name="index">コントローラーの番号</param>
    /// <param name="npadId">パッドのID</param>
    static public void InputUpdate(int index, NpadId npadId)
    {
        prevButtons[index] = currentButtons[index];
        //未接続
        if (!SwitchManager.GetInstance().IsConnect(index))
        {
            return;
        }

        //スタイルを取得
        NpadStyle npadStyle = Npad.GetStyleSet(npadId);

        //スタイルが合うかどうか
        if ((npadStyle & SwitchManager.GetInstance().GetNpadStyle()) == 0)
        {
            return;
        }
        //入力情報を取得
        Npad.GetState(ref npadState, npadId, npadStyle);
        npadState.buttons &= ~(NpadButton.StickLUp | NpadButton.StickRUp |
                               NpadButton.StickLDown | NpadButton.StickRDown |
                               NpadButton.StickLRight | NpadButton.StickRRight |
                               NpadButton.StickLLeft | NpadButton.StickRLeft);

        if (npadStyle == NpadStyle.JoyLeft)
        {
            //デッドゾーンを超えているかどうか
            if (Mathf.Abs(npadState.analogStickL.fx) > DeadZone)
            {
                stickInfos[index].y = npadState.analogStickL.fx;
                npadState.buttons  |= (npadState.analogStickL.fx > 0) ? NpadButton.StickLUp : NpadButton.StickLDown;
            }
            else
            {
                stickInfos[index].y = 0.0f;
            }
            //デッドゾーンを超えているかどうか
            if (Mathf.Abs(npadState.analogStickL.fy) > DeadZone)
            {
                stickInfos[index].x = -npadState.analogStickL.fy;
                npadState.buttons  |= (npadState.analogStickL.fy > 0) ? NpadButton.StickLLeft : NpadButton.StickLRight;
            }
            else
            {
                stickInfos[index].x = 0.0f;
            }
        }
        else
        {
            //デッドゾーンを超えているかどうか
            if (Mathf.Abs(npadState.analogStickR.fx) > DeadZone)
            {
                stickInfos[index].y = -npadState.analogStickR.fx;
                npadState.buttons  |= (npadState.analogStickR.fx > 0) ? NpadButton.StickRDown : NpadButton.StickRUp;
            }
            else
            {
                stickInfos[index].y = 0.0f;
            }
            //デッドゾーンを超えているかどうか
            if (Mathf.Abs(npadState.analogStickR.fy) > DeadZone)
            {
                stickInfos[index].x = npadState.analogStickR.fy;
                npadState.buttons  |= (npadState.analogStickR.fy > 0) ? NpadButton.StickRRight : NpadButton.StickRLeft;
            }
            else
            {
                stickInfos[index].x = 0.0f;
            }
        }

        currentButtons[index] = (long)npadState.buttons;
    }
예제 #13
0
 /// <summary>
 /// 接続状態の更新
 /// </summary>
 /// <param name="_Index">コントローラーの番号</param>
 /// <returns></returns>
 void ConnectUpdate(int _Index)
 {
     //スタイルがNoneならfalse
     m_IsConnect[_Index] = (Npad.GetStyleSet(m_NpadIds[_Index]) != NpadStyle.None);
 }
예제 #14
0
    /// <summary>
    /// 入力の更新
    /// </summary>
    /// <param name="index">コントローラーの番号</param>
    /// <param name="npadId">パッドのID</param>
    static public void InputUpdate(int index
#if UNITY_SWITCH && !(UNITY_EDITOR)
                                   , NpadId npadId
#endif
                                   )
    {
#if UNITY_EDITOR || !(UNITY_SWITCH)
        for (int i = 0; i < (int)XboxInput.None; ++i)
        {
            xboxPrevButtons[index, i]    = xboxCurrentButtons[index, i];
            xboxCurrentButtons[index, i] = InputXboxButton(index, (XboxInput)i);
        }
#endif
        prevButtons[index] = currentButtons[index];
        //未接続
        if (!SwitchManager.GetInstance().IsConnect(index))
        {
            return;
        }

#if UNITY_SWITCH && !(UNITY_EDITOR)
        //スタイルを取得
        NpadStyle npadStyle = Npad.GetStyleSet(npadId);
        //スタイルが合うかどうか
        if ((npadStyle & SwitchManager.GetInstance().GetNpadStyle()) == 0)
        {
            return;
        }
        //入力情報を取得
        Npad.GetState(ref npadState, npadId, npadStyle);
        npadState.buttons &= ~(NpadButton.StickLUp | NpadButton.StickRUp |
                               NpadButton.StickLDown | NpadButton.StickRDown |
                               NpadButton.StickLRight | NpadButton.StickRRight |
                               NpadButton.StickLLeft | NpadButton.StickRLeft);
        //スティックの更新
        //右のジョイスティック
        if (npadStyle == NpadStyle.JoyRight)
        {
            //デッドゾーンを超えているかどうか
            if (Mathf.Abs(npadState.analogStickR.fx) > DeadZone)
            {
                stickInfos[index].horizontal = npadState.analogStickR.fx;
                npadState.buttons           |= (npadState.analogStickR.fx > 0) ? NpadButton.StickLRight : NpadButton.StickLLeft;
            }
            else
            {
                stickInfos[index].horizontal = 0.0f;
            }
            //デッドゾーンを超えているかどうか
            if (Mathf.Abs(npadState.analogStickR.fy) > DeadZone)
            {
                stickInfos[index].vertical = npadState.analogStickR.fy;
                npadState.buttons         |= (npadState.analogStickR.fy > 0) ? NpadButton.StickLUp : NpadButton.StickLDown;
            }
            else
            {
                stickInfos[index].vertical = 0.0f;
            }
        }
        //左のジョイスティック
        else
        {
            //デッドゾーンを超えているかどうか
            if (Mathf.Abs(npadState.analogStickL.fx) > DeadZone)
            {
                stickInfos[index].horizontal = npadState.analogStickL.fx;
                npadState.buttons           |= (npadState.analogStickL.fx > 0) ? NpadButton.StickLRight : NpadButton.StickLLeft;
            }
            else
            {
                stickInfos[index].horizontal = 0.0f;
            }
            //デッドゾーンを超えているかどうか
            if (Mathf.Abs(npadState.analogStickL.fy) > DeadZone)
            {
                stickInfos[index].vertical = npadState.analogStickL.fy;
                npadState.buttons         |= (npadState.analogStickL.fy > 0) ? NpadButton.StickLUp : NpadButton.StickLDown;
            }
            else
            {
                stickInfos[index].vertical = 0.0f;
            }
        }
        currentButtons[index] = (long)npadState.buttons;
#endif
    }
예제 #15
0
 /// <summary>
 /// 接続状態の更新
 /// </summary>
 /// <param name="index">コントローラーの番号</param>
 void ConnectUpdate(int index)
 {
     //スタイルがNoneならfalse
     isConnect[index] = (Npad.GetStyleSet(npadIds[index]) != NpadStyle.None);
 }
    private bool UpdatePadState()
    {
        nn.hid.NpadStyle handheldStyle = Npad.GetStyleSet(nn.hid.NpadId.Handheld);
        NpadState        handheldState = new NpadState();

        nn.hid.NpadStyle no1Style = Npad.GetStyleSet(nn.hid.NpadId.No1);
        NpadState        no1State = new NpadState();

        if (playerID == 0)
        {
            if (handheldStyle != nn.hid.NpadStyle.None)
            {
                Npad.GetState(ref handheldState, nn.hid.NpadId.Handheld, handheldStyle);
                if (handheldState.buttons != nn.hid.NpadButton.None)
                {
                    if ((npadId != nn.hid.NpadId.Handheld) || (npadStyle != handheldStyle))
                    {
                        this.GetVibrationDevice(nn.hid.NpadId.Handheld, handheldStyle);
                    }
                    npadId    = nn.hid.NpadId.Handheld;
                    npadStyle = handheldStyle;
                    npadState = handheldState;
                    return(true);
                }
            }

            if (no1Style != nn.hid.NpadStyle.None)
            {
                Npad.GetState(ref no1State, nn.hid.NpadId.No1, no1Style);
                if (no1State.buttons != nn.hid.NpadButton.None)
                {
                    if ((npadId != nn.hid.NpadId.No1) || (npadStyle != no1Style))
                    {
                        this.GetVibrationDevice(nn.hid.NpadId.No1, no1Style);
                    }
                    npadId    = nn.hid.NpadId.No1;
                    npadStyle = no1Style;
                    npadState = no1State;
                    return(true);
                }
            }
        }

        nn.hid.NpadStyle no2Style = Npad.GetStyleSet(nn.hid.NpadId.No2);
        NpadState        no2State = new NpadState();

        if (playerID == 1)
        {
            if (no2Style != nn.hid.NpadStyle.None)
            {
                Npad.GetState(ref no2State, nn.hid.NpadId.No2, no2Style);
                if (no2State.buttons != nn.hid.NpadButton.None)
                {
                    if ((npadId != nn.hid.NpadId.No2) || (npadStyle != no2Style))
                    {
                        this.GetVibrationDevice(nn.hid.NpadId.No2, no2Style);
                    }
                    npadId    = nn.hid.NpadId.No2;
                    npadStyle = no2Style;
                    npadState = no2State;
                    return(true);
                }
            }
        }

        nn.hid.NpadStyle no3Style = Npad.GetStyleSet(nn.hid.NpadId.No3);
        NpadState        no3State = new NpadState();

        if (playerID == 2)
        {
            if (no3Style != nn.hid.NpadStyle.None)
            {
                Npad.GetState(ref no3State, nn.hid.NpadId.No3, no3Style);
                if (no3State.buttons != nn.hid.NpadButton.None)
                {
                    if ((npadId != nn.hid.NpadId.No3) || (npadStyle != no3Style))
                    {
                        this.GetVibrationDevice(nn.hid.NpadId.No3, no3Style);
                    }
                    npadId    = nn.hid.NpadId.No3;
                    npadStyle = no3Style;
                    npadState = no3State;
                    return(true);
                }
            }
        }

        nn.hid.NpadStyle no4Style = Npad.GetStyleSet(nn.hid.NpadId.No4);
        NpadState        no4State = new NpadState();

        if (playerID == 3)
        {
            if (no4Style != nn.hid.NpadStyle.None)
            {
                Npad.GetState(ref no4State, nn.hid.NpadId.No4, no4Style);
                if (no4State.buttons != nn.hid.NpadButton.None)
                {
                    if ((npadId != nn.hid.NpadId.No4) || (npadStyle != no4Style))
                    {
                        this.GetVibrationDevice(nn.hid.NpadId.No4, no4Style);
                    }
                    npadId    = nn.hid.NpadId.No4;
                    npadStyle = no4Style;
                    npadState = no4State;
                    return(true);
                }
            }
        }

        if (playerID == 0 && (npadId == nn.hid.NpadId.Handheld) && (handheldStyle != nn.hid.NpadStyle.None))
        {
            npadId    = nn.hid.NpadId.Handheld;
            npadStyle = handheldStyle;
            npadState = handheldState;
        }
        else if (playerID == 0 && (npadId == nn.hid.NpadId.No1) && (no1Style != nn.hid.NpadStyle.None))
        {
            npadId    = nn.hid.NpadId.No1;
            npadStyle = no1Style;
            npadState = no1State;
        }
        else if (playerID == 1 && (npadId == nn.hid.NpadId.No2) && (no2Style != nn.hid.NpadStyle.None))
        {
            npadId    = nn.hid.NpadId.No2;
            npadStyle = no2Style;
            npadState = no2State;
        }
        else if (playerID == 2 && (npadId == nn.hid.NpadId.No3) && (no3Style != nn.hid.NpadStyle.None))
        {
            npadId    = nn.hid.NpadId.No3;
            npadStyle = no3Style;
            npadState = no3State;
        }
        else if (playerID == 3 && (npadId == nn.hid.NpadId.No4) && (no4Style != nn.hid.NpadStyle.None))
        {
            npadId    = nn.hid.NpadId.No4;
            npadStyle = no4Style;
            npadState = no4State;
        }
        else
        {
            npadId    = nn.hid.NpadId.Invalid;
            npadStyle = nn.hid.NpadStyle.Invalid;
            npadState.Clear();
            return(false);
        }
        return(true);
    }