/// <summary> /// Scans for keyboard input and calls the handler with the result. /// Returns KeyCode.None if timeout is reached. /// </summary> public static void StartKeyScan(KeyScanHandler scanHandler, float timeout, string cancelScanButton, params object[] optional) { _instance._scanTimeout = timeout; _instance._cancelScanButton = cancelScanButton; _instance._optionalParameters = optional; _instance._scanType = ScanType.Key; _instance._keyScanHandler = scanHandler; }
private void StopScan() { if (_scanType == ScanType.Key) { _keyScanHandler(KeyCode.None, _optionalParameters); } else if (_scanType == ScanType.MouseAxis || _scanType == ScanType.JoystickAxis) { _axisScanHandler(-1, _optionalParameters); } _scanType = ScanType.None; _axisScanHandler = null; _keyScanHandler = null; }
/// <summary> /// Scans for keyboard input and calls the handler with the result. /// Returns KeyCode.None if timeout is reached or the scan is canceled. /// </summary> public static void StartKeyScan(KeyScanHandler scanHandler, float timeout, string cancelScanButton, params object[] userData) { if (_instance._scanFlags != ScanFlags.None) { _instance.StopInputScan(); } _instance._scanTimeout = timeout; _instance._scanFlags = ScanFlags.Key | ScanFlags.JoystickButton; _instance._scanStartTime = _instance.ignoreTimescale ? Time.realtimeSinceStartup : Time.time; _instance._cancelScanButton = cancelScanButton; _instance._scanUserData = userData; _instance._scanHandler = (result) => { return(scanHandler(result.key, (object[])result.userData)); }; }
private void ScanKey() { if (!string.IsNullOrEmpty(_cancelScanButton) && GetButtonDown(_cancelScanButton) || _scanTimeout <= 0.0f) { StopScan(); } else { foreach (KeyValuePair <string, KeyCode> entry in _stringToKeyTable) { if (Input.GetKeyDown(entry.Value)) { if (_keyScanHandler(entry.Value, _optionalParameters)) { _keyScanHandler = null; _scanType = ScanType.None; break; } } } } }
/// <summary> /// Scans for keyboard input and calls the handler with the result. /// Returns KeyCode.None if timeout is reached or the scan is canceled. /// </summary> public static void StartKeyScan(KeyScanHandler scanHandler, float timeout, string cancelScanButton, params object[] userData) { if (_instance._scanFlags != ScanFlags.None) _instance.StopInputScan (); _instance._scanTimeout = timeout; _instance._scanFlags = ScanFlags.Key | ScanFlags.JoystickButton; _instance._scanStartTime = _instance.ignoreTimescale ? Time.realtimeSinceStartup : Time.time; _instance._cancelScanButton = cancelScanButton; _instance._scanUserData = userData; _instance._scanHandler = (result) => { return scanHandler (result.key, (object[])result.userData); }; }