//* -----------------------------------------------------------------------* /// <summary> /// 管理している入力クラスが対象の値と同じ場合、管理放棄します。 /// </summary> /// /// <typeparam name="_T">適用する入力制御・管理クラスの型。</typeparam> /// <param name="device"> /// <typeparamref name="_T"/>に対応する入力デバイス。 /// </param> /// <param name="input"> /// 管理しているマンマシンI/F入力制御・管理クラスの格納先。 /// </param> /// <param name="expr">比較対象のマンマシンI/F入力制御・管理クラス。</param> private void castOffAtEquals <_T>( EInputDevice device, ref _T input, CInput expr) where _T : CInput { if (input != null && expr != null && expr == input) { m_inputDevice &= ~device; input = null; } }
//* -----------------------------------------------------------------------* /// <summary>管理している子入力クラスを全て解放します。</summary> /// /// <exception cref="System.NotSupportedException"> /// 読み取り専用状態でこのメソッドを実行した場合。 /// </exception> public override void Clear() { m_inputDevice = EInputDevice.None; m_inputKeyboard = null; m_inputMouse = null; m_inputXbox360 = null; m_inputXbox360Chatpad = null; m_inputLegacy = null; base.Clear(); }
//* -----------------------------------------------------------------------* /// <summary> /// <c>inputDevice</c>プロパティで設定された、入力デバイスの設定を適用します。 /// </summary> /// /// <typeparam name="_T">適用する入力制御・管理クラスの型。</typeparam> /// <param name="device"> /// <typeparamref name="_T"/>に対応する入力デバイス。 /// </param> /// <param name="input"> /// 作成または解放されたマンマシンI/F入力制御・管理クラスの格納先。 /// </param> /// <param name="instanceCreator"> /// <typeparamref name="_T"/>に対応するマンマシン /// I/F入力制御・管理クラスを生成するためのデリゲート。 /// </param> private void applyInputDevice <_T>( EInputDevice device, ref _T input, Func <_T> instanceCreator) where _T : CInput { device = (m_inputDevice & device); if (device != EInputDevice.None && input == null) { input = instanceCreator(); Add(input); } else if (device == EInputDevice.None && input != null) { Remove(input); input = null; } }
public static InputDevice GetInputDevice(this EInputDevice inputDevice) { switch (inputDevice) { case EInputDevice.KeyboardAndMouse: return(Keyboard.current); case EInputDevice.Gamepad: return(Gamepad.current); case EInputDevice.Touch: return(Touchscreen.current); default: throw new ArgumentException($"No enum value defined for InputDevice {inputDevice}"); } }
//* -----------------------------------------------------------------------* /// <summary>キーの割り当てをします。</summary> /// /// <param name="device">入力デバイス</param> /// <param name="uType">ボタン番号</param> /// <returns>割り当てに成功した場合、true</returns> /// <exception cref="System.ArgumentOutOfRangeException"> /// 登録されている数以上のボタン番号を指定した場合。 /// または、対応していない入力デバイスを引数に設定した場合。 /// </exception> /// <exception cref="Microsoft.DirectX.DirectInput.DeviceNotRegisteredException"> /// レガシ ゲームパッドが初期化されていない状態で割り当てをしようとした場合。 /// </exception> public bool assign(EInputDevice device, ushort uType) { bool bAssign = false; switch (device) { case EInputDevice.Keyboard: if (uType >= assignKeyboard.Length) { throw new ArgumentOutOfRangeException("uType"); } else { Keys[] keys = Keyboard.GetState().GetPressedKeys(); if (keys.Length > 0 && !isReserved(keys[0])) { bAssign = true; assignKeyboard[uType] = keys[0]; } } break; #if WINDOWS case EInputDevice.LegacyPad: if (legacy == null) { throw new Microsoft.DirectX.DirectInput.DeviceNotRegisteredException(); } else if (uType >= assignLegacy.Length) { throw new ArgumentOutOfRangeException("uType"); } else { byte[] buttons = legacy.state.GetButtons(); int nBtnID = 0; while (nBtnID < buttons.Length) { if (buttons[nBtnID] != 0) { bAssign = true; assignLegacy[uType] = nBtnID; break; } else { nBtnID++; } } } break; #endif case EInputDevice.XBOX360: if (uType >= assignXBOX360.Length) { throw new ArgumentOutOfRangeException("uType"); } bAssign = __assignXBOX360(ref assignXBOX360[uType]); break; default: throw new ArgumentOutOfRangeException("device"); } return(bAssign); }