Example #1
0
    private void UpdateButtonState(InputDevice device, InputFeatureUsage <bool> button,
                                   AButtonEvent aButtonPressEvent)
    {
        bool tempState;
        bool invalidDeviceFound = false;
        bool buttonState        = false;

        tempState = device.isValid && // the device is still valid
                    device.TryGetFeatureValue(button, out buttonState) && // did get a value
                    buttonState;    // the value we got

        if (!device.isValid)
        {
            invalidDeviceFound = true;
        }

        if (tempState != aButtonPressEvent.Value) // Button state changed since last frame
        {
            aButtonPressEvent.Invoke(tempState);
            aButtonPressEvent.Value = tempState;
        }

        if (invalidDeviceFound) // refresh device lists
        {
            SetDevices();
        }
    }
 private void InitializeButtons()
 {
     (gripEvent = new AButtonEvent()).Initialize(isGripPressed, OnGripButtonEvent);
     (triggerEvent = new AButtonEvent()).Initialize(isTriggerPressed, OnTriggerButtonEvent);
     (primaryButtonEvent = new AButtonEvent()).Initialize(isPrimaryButtonPressed, OnPrimaryButtonEvent);
     (secondaryButtonEvent = new AButtonEvent()).Initialize(isSecondaryButtonPressed, OnSecondaryButtonEvent);
     (primaryAxisEvent = new AButtonEvent()).Initialize(isPrimaryAxisPressed, OnAxisClickButtonEvent);
 }