Beispiel #1
0
        protected virtual void ToggleControllerListeners(GameObject controller, bool toggle, ref bool subscribed)
        {
            VRTK_ControllerEvents controllerEvent = controller.GetComponent <VRTK_ControllerEvents>();

            if (controllerEvent != null)
            {
                //If engage button has changed, then unsubscribe the previous engage button from the events
                if (engageButton != previousEngageButton && subscribed)
                {
                    controllerEvent.UnsubscribeToButtonAliasEvent(previousEngageButton, true, EngageButtonPressed);
                    controllerEvent.UnsubscribeToButtonAliasEvent(previousEngageButton, false, EngageButtonReleased);
                    subscribed = false;
                }

                if (toggle && !subscribed)
                {
                    controllerEvent.SubscribeToButtonAliasEvent(engageButton, true, EngageButtonPressed);
                    controllerEvent.SubscribeToButtonAliasEvent(engageButton, false, EngageButtonReleased);
                    subscribed = true;
                }
                else if (!toggle && subscribed)
                {
                    controllerEvent.UnsubscribeToButtonAliasEvent(engageButton, true, EngageButtonPressed);
                    controllerEvent.UnsubscribeToButtonAliasEvent(engageButton, false, EngageButtonReleased);
                    subscribed = false;
                }
            }
        }
Beispiel #2
0
        // Token: 0x060017F3 RID: 6131 RVA: 0x0007FDAC File Offset: 0x0007DFAC
        protected virtual void ToggleControllerListeners(GameObject controller, bool toggle, ref bool subscribed)
        {
            VRTK_ControllerEvents component = controller.GetComponent <VRTK_ControllerEvents>();

            if (component != null)
            {
                if (this.engageButton != this.previousEngageButton & subscribed)
                {
                    component.UnsubscribeToButtonAliasEvent(this.previousEngageButton, true, new ControllerInteractionEventHandler(this.EngageButtonPressed));
                    component.UnsubscribeToButtonAliasEvent(this.previousEngageButton, false, new ControllerInteractionEventHandler(this.EngageButtonReleased));
                    subscribed = false;
                }
                if (toggle && !subscribed)
                {
                    component.SubscribeToButtonAliasEvent(this.engageButton, true, new ControllerInteractionEventHandler(this.EngageButtonPressed));
                    component.SubscribeToButtonAliasEvent(this.engageButton, false, new ControllerInteractionEventHandler(this.EngageButtonReleased));
                    subscribed = true;
                    return;
                }
                if (!toggle & subscribed)
                {
                    component.UnsubscribeToButtonAliasEvent(this.engageButton, true, new ControllerInteractionEventHandler(this.EngageButtonPressed));
                    component.UnsubscribeToButtonAliasEvent(this.engageButton, false, new ControllerInteractionEventHandler(this.EngageButtonReleased));
                    subscribed = false;
                }
            }
        }
Beispiel #3
0
        protected void InitControllerListener(bool state, GameObject controller, ref VRTK_ControllerEvents events, ref VRTK_InteractGrab grab,
                                              ControllerInteractionEventHandler triggerPressed, ControllerInteractionEventHandler triggerReleased)
        {
            if (controller != null)
            {
                events = controller.GetComponentInChildren <VRTK_ControllerEvents>();
                grab   = controller.GetComponentInChildren <VRTK_InteractGrab>();

                if (events != null)
                {
                    if (state == true)
                    {
                        events.SubscribeToButtonAliasEvent(activationButton, true, triggerPressed);
                        events.SubscribeToButtonAliasEvent(activationButton, false, triggerReleased);

                        if (cancelButton != VRTK_ControllerEvents.ButtonAlias.Undefined)
                        {
                            events.SubscribeToButtonAliasEvent(cancelButton, true, CancelButtonPressed);
                        }
                    }
                    else
                    {
                        events.UnsubscribeToButtonAliasEvent(activationButton, true, triggerPressed);
                        events.UnsubscribeToButtonAliasEvent(activationButton, false, triggerReleased);

                        if (cancelButton != VRTK_ControllerEvents.ButtonAlias.Undefined)
                        {
                            events.UnsubscribeToButtonAliasEvent(cancelButton, true, CancelButtonPressed);
                        }
                    }
                }
            }
        }
 protected virtual void UnsubscribeButtonEvent(VRTK_ControllerEvents.ButtonAlias buttonType, ControllerInteractionEventHandler eventHandler)
 {
     if (buttonType != VRTK_ControllerEvents.ButtonAlias.Undefined)
     {
         controllerEvents.UnsubscribeToButtonAliasEvent(buttonType, true, eventHandler);
         controllerEvents.UnsubscribeToButtonAliasEvent(buttonType, false, eventHandler);
     }
 }
 protected virtual void UnsubscribeActivationButton()
 {
     if (controllerEvents != null && subscribedActivationButton != VRTK_ControllerEvents.ButtonAlias.Undefined)
     {
         controllerEvents.UnsubscribeToButtonAliasEvent(subscribedActivationButton, true, DoActivationButtonPressed);
         controllerEvents.UnsubscribeToButtonAliasEvent(subscribedActivationButton, false, DoActivationButtonReleased);
         subscribedActivationButton = VRTK_ControllerEvents.ButtonAlias.Undefined;
     }
 }
Beispiel #6
0
        protected virtual void OnDisable()
        {
            if (cachedVRInputModule && cachedVRInputModule.pointers.Contains(this))
            {
                cachedVRInputModule.pointers.Remove(this);
            }

            if (controllerEvents != null)
            {
                controllerEvents.UnsubscribeToButtonAliasEvent(activationButton, true, DoActivationButtonPressed);
                controllerEvents.UnsubscribeToButtonAliasEvent(activationButton, false, DoActivationButtonReleased);
                controllerEvents.UnsubscribeToButtonAliasEvent(selectionButton, true, DoSelectionButtonPressed);
                controllerEvents.UnsubscribeToButtonAliasEvent(selectionButton, false, DoSelectionButtonReleased);
            }
        }
Beispiel #7
0
        protected virtual void ManageGrabListener(bool state)
        {
            if (controllerEvents != null && subscribedGrabButton != VRTK_ControllerEvents.ButtonAlias.Undefined && (!state || !grabButton.Equals(subscribedGrabButton)))
            {
                controllerEvents.UnsubscribeToButtonAliasEvent(subscribedGrabButton, true, DoGrabObject);
                controllerEvents.UnsubscribeToButtonAliasEvent(subscribedGrabButton, false, DoReleaseObject);
                subscribedGrabButton = VRTK_ControllerEvents.ButtonAlias.Undefined;
            }

            if (controllerEvents != null && state && grabButton != VRTK_ControllerEvents.ButtonAlias.Undefined && !grabButton.Equals(subscribedGrabButton))
            {
                controllerEvents.SubscribeToButtonAliasEvent(grabButton, true, DoGrabObject);
                controllerEvents.SubscribeToButtonAliasEvent(grabButton, false, DoReleaseObject);
                subscribedGrabButton = grabButton;
            }
        }
Beispiel #8
0
        protected virtual void ManageUseListener(bool state)
        {
            if (controllerEvents != null && subscribedUseButton != VRTK_ControllerEvents.ButtonAlias.Undefined && (!state || useButton != subscribedUseButton))
            {
                controllerEvents.UnsubscribeToButtonAliasEvent(subscribedUseButton, true, DoStartUseObject);
                controllerEvents.UnsubscribeToButtonAliasEvent(subscribedUseButton, false, DoStopUseObject);
                subscribedUseButton = VRTK_ControllerEvents.ButtonAlias.Undefined;
            }

            if (controllerEvents != null && state && useButton != VRTK_ControllerEvents.ButtonAlias.Undefined && useButton != subscribedUseButton)
            {
                controllerEvents.SubscribeToButtonAliasEvent(useButton, true, DoStartUseObject);
                controllerEvents.SubscribeToButtonAliasEvent(useButton, false, DoStopUseObject);
                subscribedUseButton = useButton;
            }
        }
Beispiel #9
0
        protected virtual void ManageActivationListener(bool state, ref VRTK_ControllerEvents.ButtonAlias activationButton, ref VRTK_ControllerEvents.ButtonAlias subscribedActivationButton, ControllerInteractionEventHandler buttonPressedCallback, ControllerInteractionEventHandler buttonReleasedCallback)
        {
            if (subscribedActivationButton == VRTK_ControllerEvents.ButtonAlias.Undefined && (!state || activationButton != subscribedActivationButton))
            {
                if (leftControllerEvents != null)
                {
                    leftControllerEvents.UnsubscribeToButtonAliasEvent(subscribedActivationButton, true, buttonPressedCallback);
                    leftControllerEvents.UnsubscribeToButtonAliasEvent(subscribedActivationButton, false, buttonReleasedCallback);
                    leftControllerEvents.ControllerModelAvailable -= ControllerModelAvailable;
                }
                if (rightControllerEvents != null)
                {
                    rightControllerEvents.UnsubscribeToButtonAliasEvent(subscribedActivationButton, true, buttonPressedCallback);
                    rightControllerEvents.UnsubscribeToButtonAliasEvent(subscribedActivationButton, false, buttonReleasedCallback);
                    rightControllerEvents.ControllerModelAvailable -= ControllerModelAvailable;
                }
                subscribedActivationButton = VRTK_ControllerEvents.ButtonAlias.Undefined;
            }

            if (state && subscribedActivationButton == VRTK_ControllerEvents.ButtonAlias.Undefined && activationButton != VRTK_ControllerEvents.ButtonAlias.Undefined)
            {
                bool subscribed = false;
                if (leftControllerEvents != null)
                {
                    leftControllerEvents.SubscribeToButtonAliasEvent(activationButton, true, buttonPressedCallback);
                    leftControllerEvents.SubscribeToButtonAliasEvent(activationButton, false, buttonReleasedCallback);
                    leftControllerEvents.ControllerModelAvailable += ControllerModelAvailable;
                    subscribed = true;
                }

                if (rightControllerEvents != null)
                {
                    rightControllerEvents.SubscribeToButtonAliasEvent(activationButton, true, buttonPressedCallback);
                    rightControllerEvents.SubscribeToButtonAliasEvent(activationButton, false, buttonReleasedCallback);
                    rightControllerEvents.ControllerModelAvailable += ControllerModelAvailable;
                    subscribed = true;
                }

                if (subscribed)
                {
                    subscribedActivationButton = activationButton;
                }
            }
        }
        protected virtual void ManageActivationListeners(bool state)
        {
            if (controllerEvents != null)
            {
                if (subscribedActivationButton != VRTK_ControllerEvents.ButtonAlias.Undefined && (!state || activationButton != subscribedActivationButton))
                {
                    controllerEvents.UnsubscribeToButtonAliasEvent(subscribedActivationButton, true, DoActivationPress);
                    controllerEvents.UnsubscribeToButtonAliasEvent(subscribedActivationButton, false, DoActivationRelease);
                    subscribedActivationButton = VRTK_ControllerEvents.ButtonAlias.Undefined;
                }

                if (state && activationButton != VRTK_ControllerEvents.ButtonAlias.Undefined)
                {
                    controllerEvents.SubscribeToButtonAliasEvent(activationButton, true, DoActivationPress);
                    controllerEvents.SubscribeToButtonAliasEvent(activationButton, false, DoActivationRelease);
                    subscribedActivationButton = activationButton;
                }
            }
        }
        protected virtual void ManageButtonSubscription()
        {
            controllerEvents = (controllerEvents != null ? controllerEvents : GetComponentInParent <VRTK_ControllerEvents>());

            if (controllerEvents != null && buttonSubscribed && subscribedActivationButton != VRTK_ControllerEvents.ButtonAlias.Undefined && activationButton != subscribedActivationButton)
            {
                buttonSubscribed = false;
                controllerEvents.UnsubscribeToButtonAliasEvent(subscribedActivationButton, true, ActivationButtonPressed);
                controllerEvents.UnsubscribeToButtonAliasEvent(subscribedActivationButton, false, ActivationButtonReleased);
                subscribedActivationButton = VRTK_ControllerEvents.ButtonAlias.Undefined;
            }

            if (controllerEvents != null && !buttonSubscribed && activationButton != VRTK_ControllerEvents.ButtonAlias.Undefined)
            {
                controllerEvents.SubscribeToButtonAliasEvent(activationButton, true, ActivationButtonPressed);
                controllerEvents.SubscribeToButtonAliasEvent(activationButton, false, ActivationButtonReleased);
                buttonSubscribed           = true;
                subscribedActivationButton = activationButton;
            }
        }