Exemple #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;
                }
            }
        }
Exemple #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;
                }
            }
        }
Exemple #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);
                        }
                    }
                }
            }
        }
Exemple #4
0
    void Awake()
    {
        MakeSingleton();

        CurrentGameMode = GameMode.BUILD;

        /* Setup Controller Events */
        RightControllerEvents.SubscribeToButtonAliasEvent(VRTK.VRTK_ControllerEvents.ButtonAlias.TriggerPress, true, RightControllerEvents_TriggerDown);
        RightControllerEvents.SubscribeToButtonAliasEvent(VRTK.VRTK_ControllerEvents.ButtonAlias.TriggerPress, false, RightControllerEvents_TriggerUp);
        RightControllerEvents.SubscribeToButtonAliasEvent(VRTK.VRTK_ControllerEvents.ButtonAlias.GripPress, true, RightControllerEvents_GripDown);
        RightControllerEvents.SubscribeToButtonAliasEvent(VRTK.VRTK_ControllerEvents.ButtonAlias.GripPress, false, RightControllerEvents_GripUp);
        RightControllerEvents.SubscribeToButtonAliasEvent(VRTK.VRTK_ControllerEvents.ButtonAlias.TouchpadPress, false, RightControllerEvents_TouchpadUp);

        LeftControllerEvents.SubscribeToButtonAliasEvent(VRTK.VRTK_ControllerEvents.ButtonAlias.TriggerPress, true, LeftControllerEvents_TriggerDown);
        LeftControllerEvents.SubscribeToButtonAliasEvent(VRTK.VRTK_ControllerEvents.ButtonAlias.TriggerPress, false, LeftControllerEvents_TriggerUp);
        LeftControllerEvents.SubscribeToButtonAliasEvent(VRTK.VRTK_ControllerEvents.ButtonAlias.GripPress, false, LeftControllerEvents_GripUp);

        /* Setup Controller VRTK scripts */
        VRTK.VRTK_InteractGrab rightInteractGrab = RightControllerEvents.GetComponent <VRTK.VRTK_InteractGrab>();
        rightInteractGrab.grabButton = VRTK.VRTK_ControllerEvents.ButtonAlias.TriggerPress;

        RightInteractNearTouch = RightControllerEvents.GetComponent <VRTK.VRTK_InteractNearTouch>();
        RightInteractTouch     = RightControllerEvents.GetComponent <VRTK.VRTK_InteractTouch>();
        RightInteractGrab      = RightControllerEvents.GetComponent <VRTK.VRTK_InteractGrab>();

        RightAnimator = RightControllerEvents.gameObject.GetComponentInChildren <HandAnimator>();
        LeftAnimator  = LeftControllerEvents.gameObject.GetComponentInChildren <HandAnimator>();
    }
 protected virtual void SubscribeButtonEvent(VRTK_ControllerEvents.ButtonAlias buttonType, ref VRTK_ControllerEvents.ButtonAlias saveType, ControllerInteractionEventHandler eventHandler)
 {
     if (buttonType != VRTK_ControllerEvents.ButtonAlias.Undefined)
     {
         saveType = buttonType;
         controllerEvents.SubscribeToButtonAliasEvent(buttonType, true, eventHandler);
         controllerEvents.SubscribeToButtonAliasEvent(buttonType, false, eventHandler);
     }
 }
        protected virtual void SubscribeActivationButton()
        {
            if (subscribedActivationButton != VRTK_ControllerEvents.ButtonAlias.Undefined)
            {
                UnsubscribeActivationButton();
            }

            if (controllerEvents != null)
            {
                controllerEvents.SubscribeToButtonAliasEvent(activationButton, true, DoActivationButtonPressed);
                controllerEvents.SubscribeToButtonAliasEvent(activationButton, false, DoActivationButtonReleased);
                subscribedActivationButton = activationButton;
            }
        }
Exemple #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;
            }
        }
Exemple #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;
            }
        }
Exemple #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;
                }
            }
        }
Exemple #11
0
        protected virtual void OnEnable()
        {
            pointerOriginTransform = (originalPointerOriginTransform == null ? VRTK_SDK_Bridge.GenerateControllerPointerOrigin(gameObject) : originalPointerOriginTransform);

            controller = (controller != null ? controller : GetComponent <VRTK_ControllerEvents>());
            ConfigureEventSystem();
            pointerClicked        = false;
            lastPointerPressState = false;
            lastPointerClickState = false;
            beamEnabledState      = false;

            if (controller != null)
            {
                controller.SubscribeToButtonAliasEvent(activationButton, true, DoActivationButtonPressed);
                controller.SubscribeToButtonAliasEvent(activationButton, false, DoActivationButtonReleased);
                controller.SubscribeToButtonAliasEvent(selectionButton, true, DoSelectionButtonPressed);
                controller.SubscribeToButtonAliasEvent(selectionButton, false, DoSelectionButtonReleased);
            }
        }
        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;
            }
        }
        protected virtual void OnEnable()
        {
#pragma warning disable 0618
            controllerEvents = (controller != null && controllerEvents == null ? controller : controllerEvents);
            customOrigin     = (pointerOriginTransform != null && customOrigin == null ? pointerOriginTransform : customOrigin);
#pragma warning restore 0618
            attachedTo       = (attachedTo == null ? gameObject : attachedTo);
            controllerEvents = (controllerEvents != null ? controllerEvents : GetComponentInParent <VRTK_ControllerEvents>());
            ConfigureEventSystem();
            pointerClicked        = false;
            lastPointerPressState = false;
            lastPointerClickState = false;
            beamEnabledState      = false;

            if (controllerEvents != null)
            {
                controllerEvents.SubscribeToButtonAliasEvent(activationButton, true, DoActivationButtonPressed);
                controllerEvents.SubscribeToButtonAliasEvent(activationButton, false, DoActivationButtonReleased);
                controllerEvents.SubscribeToButtonAliasEvent(selectionButton, true, DoSelectionButtonPressed);
                controllerEvents.SubscribeToButtonAliasEvent(selectionButton, false, DoSelectionButtonReleased);
            }
        }