private void InitListeners()
    {
        SteamVR_ControllerEvents[] controllers = GameObject.FindObjectsOfType <SteamVR_ControllerEvents>();
        if (controllers.Length == 0)
        {
            if (listenerInitTries > 0)
            {
                listenerInitTries--;
                Invoke("InitListeners", 0.25f);
            }
            else
            {
                Debug.LogError("A GameObject must exist with a SteamVR_ControllerEvents script attached to it");
                return;
            }
        }

        foreach (SteamVR_ControllerEvents controller in controllers)
        {
            controller.TouchpadAxisChanged += new ControllerClickedEventHandler(DoTouchpadAxisChanged);
            controller.TouchpadUntouched   += new ControllerClickedEventHandler(DoTouchpadUntouched);

            if (ignoreGrabbedCollisions && controller.GetComponent <SteamVR_InteractGrab>())
            {
                SteamVR_InteractGrab grabbingController = controller.GetComponent <SteamVR_InteractGrab>();
                grabbingController.ControllerGrabInteractableObject   += new ObjectInteractEventHandler(OnGrabObject);
                grabbingController.ControllerUngrabInteractableObject += new ObjectInteractEventHandler(OnUngrabObject);
            }
        }

        if (headset.GetComponent <SteamVR_HeadsetCollisionFade>())
        {
            headset.GetComponent <SteamVR_HeadsetCollisionFade>().HeadsetCollisionDetect += new HeadsetCollisionEventHandler(OnHeadsetCollision);
        }
    }
Beispiel #2
0
    private void OnTriggerStay(Collider collider)
    {
        SteamVR_InteractGrab grabbingController = collider.gameObject.GetComponent <SteamVR_InteractGrab>();

        if (CanGrab(grabbingController) && NoArrowNotched(grabbingController.gameObject) && spawnDelayTimer <= 0f)
        {
            GameObject newArrow = Instantiate(arrowPrefab);
            newArrow.name = "ArrowClone";
            grabbingController.gameObject.GetComponent <SteamVR_InteractTouch>().ForceTouch(newArrow);
            grabbingController.AttemptGrab();
            spawnDelayTimer = spawnDelay;
        }

        if (spawnDelayTimer > 0)
        {
            spawnDelayTimer -= Time.deltaTime;
        }
    }
    private void InitControllerListeners()
    {
        SteamVR_ControllerEvents[] controllers = GameObject.FindObjectsOfType <SteamVR_ControllerEvents>();
        if (controllers.Length != connectedControllers.Count)
        {
            if (listenerInitTries > 0)
            {
                listenerInitTries--;
            }
            else
            {
                retryListenersDelay = retryListenersDelay * retryListenerMultiplier;
                listenerInitTries   = listenerInitMax;
                Debug.LogWarning("Waiting for controllers to initialise, retrying in " + retryListenersDelay);
            }
            Invoke("InitControllerListeners", retryListenersDelay);
        }
        else
        {
            foreach (SteamVR_ControllerEvents controller in controllers)
            {
                int controllerEventControllerIndex = (int)controller.GetControllerIndex();
                if (!foundControllerEvents.Contains(controllerEventControllerIndex))
                {
                    controller.TouchpadAxisChanged += new ControllerClickedEventHandler(DoTouchpadAxisChanged);
                    controller.TouchpadUntouched   += new ControllerClickedEventHandler(DoTouchpadUntouched);

                    if (ignoreGrabbedCollisions && controller.GetComponent <SteamVR_InteractGrab>())
                    {
                        SteamVR_InteractGrab grabbingController = controller.GetComponent <SteamVR_InteractGrab>();
                        grabbingController.ControllerGrabInteractableObject   += new ObjectInteractEventHandler(OnGrabObject);
                        grabbingController.ControllerUngrabInteractableObject += new ObjectInteractEventHandler(OnUngrabObject);
                    }
                    foundControllerEvents.Add(controllerEventControllerIndex);
                }
            }
        }
    }
Beispiel #4
0
 private bool CanGrab(SteamVR_InteractGrab grabbingController)
 {
     return(grabbingController && grabbingController.GetGrabbedObject() == null && grabbingController.gameObject.GetComponent <SteamVR_ControllerEvents>().grabPressed);
 }