//* ────________________________________* //* methods ───────────────────────────────-* //* -----------------------------------------------------------------------* /// <summary> /// <typeparamref name="_T"/>型の入力制御・管理クラスが登録されていたら取得します。 /// </summary> /// <remarks>自動認識状態のコレクションから取得する時に便利です。</remarks> /// /// <typeparam name="_T">取得したい入力制御・管理クラスの型。</typeparam> /// <param name="collection">入力制御・管理コレクション</param> /// <returns> /// <typeparamref name="_T"/>型の入力制御・管理クラス。存在しない場合、<c>null</c>。 /// </returns> public static _T getInstance <_T>(this CInputCollection collection) where _T : CInput { _T input = null; if (collection != null) { int nTotal = collection.Count; if (nTotal > 0) { Type typeExpect = typeof(_T); if (nTotal == 1) { CInput _input = collection.childList[0]; Type typeGot = _input.GetType(); if (typeExpect == typeGot || typeExpect.IsSubclassOf(typeGot)) { input = (_T)_input; } } else { input = (_T)collection.FirstOrDefault(_input => _input.GetType() == typeExpect || typeExpect.IsSubclassOf(_input.GetType())); } } } return(input); }
//* -----------------------------------------------------------------------* /// <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> /// /// <param name="item">子入力クラス。</param> /// <returns>解放できた場合、<c>true</c>。</returns> /// <exception cref="System.NotSupportedException"> /// 読み取り専用状態でこのメソッドを実行した場合。 /// </exception> public override bool Remove(CInput item) { bool bResult = base.Remove(item); castOffAtEquals <CInputKeyboard>(EInputDevice.Keyboard, ref m_inputKeyboard, item); castOffAtEquals <CInputMouse>(EInputDevice.Mouse, ref m_inputMouse, item); castOffAtEquals <CInputCollection>(EInputDevice.XBOX360, ref m_inputXbox360, item); castOffAtEquals <CInputCollection>(EInputDevice.XBOX360, ref m_inputXbox360, item); return(bResult); }