void Update() { bool tempState = false; bool invalidDeviceFound = false; foreach (var device in devicesWithPrimaryButton) { bool buttonState = false; tempState = device.isValid && // the device is still valid device.TryGetFeatureValue(CommonUsages.primaryButton, out buttonState) && // did get a value buttonState || // the value we got tempState; // cumulative result from other controllers if (!device.isValid) { invalidDeviceFound = true; } } if (tempState != lastButtonState) // Button state changed since last frame { primaryButtonPress.Invoke(tempState); lastButtonState = tempState; } if (invalidDeviceFound || devicesWithPrimaryButton.Count == 0) // refresh device lists { UpdateInputDevices(); } }
// Update is called once per frame void Update() { //FindDevices(); bool tempStatePrimary = false; bool tempStateTrigger = false; bool invalidDeviceFound = false; foreach (var device in devicesWithPrimary) { bool primaryButtonState = false; tempStatePrimary = device.isValid && // the device is still valid device.TryGetFeatureValue(CommonUsages.primary2DAxisClick, out primaryButtonState) && // did get a value primaryButtonState || // the value we got tempStatePrimary; // cumulative result from other controllers if (!device.isValid) { invalidDeviceFound = true; } } foreach (var device in devicesWithTrigger) { bool triggerButtonState = false; tempStateTrigger = device.isValid && // the device is still valid device.TryGetFeatureValue(CommonUsages.triggerButton, out triggerButtonState) && // did get a value triggerButtonState || // the value we got tempStateTrigger; // cumulative result from other controllers if (!device.isValid) { invalidDeviceFound = true; } } if (tempStatePrimary != lastButtonStatePrimary) // Button state changed since last frame { primaryButtonEvent.Invoke(tempStatePrimary); lastButtonStatePrimary = tempStatePrimary; } if (tempStateTrigger != lastButtonStateTrigger) // Button state changed since last frame { triggerButtonEvent.Invoke(tempStateTrigger); lastButtonStateTrigger = tempStateTrigger; } if (invalidDeviceFound || devicesWithPrimary.Count == 0 || devicesWithTrigger.Count == 0) // refresh device lists { UpdateInputDevices(); } }
void Update() { bool tempState = false; foreach (var device in devicesWithPrimaryButton) { bool primaryButtonState = false; tempState = device.TryGetFeatureValue(CommonUsages.primaryButton, out primaryButtonState) && // did get a value primaryButtonState || // the value we got tempState; // cumulative result from other controllers } if (tempState != lastButtonState) // Button state changed since last frame { primaryButtonPress.Invoke(tempState); lastButtonState = tempState; } }