private void UpdateTime(ControllerInformation controller)
    {
        LightInteractionInformation info      = (LightInteractionInformation)controller.GetFunctionalityInfoByType(typeof(LightInteractionInformation));
        WatchInteractionInformation watchInfo = (WatchInteractionInformation)controller.GetFunctionalityInfoByType(typeof(WatchInteractionInformation));
        Vector2 touchpadValue = controllerManager.GetController(controller.trackedObj).GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad);
        int     time          = ((VRWatchInteraction)vrInteraction).getTimeByVector(touchpadValue);

        if (time != 0)
        {
            if (!watchInfo.isWatchOnFront)
            {
                time += 12;
            }
            if (info.isOnTime && Mathf.Floor(time) != Mathf.Floor(interactingLight.StartTime))
            {
                interactingLight.StartTime = time;
                controllerManager.GetController(controller.trackedObj).TriggerHapticPulse(3000);
                UpdateDisplay(controller);
                if (interactingLight.taskCompleted[2] != null)
                {
                    interactingLight.taskCompleted[2].Invoke();
                }
            }
            else if (Mathf.Floor(time) != Mathf.Floor(interactingLight.EndTime))
            {
                interactingLight.EndTime = time;
                controllerManager.GetController(controller.trackedObj).TriggerHapticPulse(3000);
                UpdateDisplay(controller);
                if (interactingLight.taskCompleted[2] != null)
                {
                    interactingLight.taskCompleted[2].Invoke();
                }
            }
        }
    }
    private void GrabObject(ControllerInformation info)
    {
        GrabObjectInformation grabObjInfo = (GrabObjectInformation)info.GetFunctionalityInfoByType(typeof(GrabObjectInformation));

        grabObjInfo.objectInHand    = grabObjInfo.collidingObject;
        grabObjInfo.collidingObject = null;
        //objectInHand.transform.position = Vector3.Lerp(transform.position,objectInHand.transform.position, 0.8f);
        if (!info.trackedObj.GetComponent <FixedJoint>())
        {
            var joint = AddFixedJoint(info);
            joint.connectedBody = grabObjInfo.objectInHand.GetComponent <Rigidbody>();
        }
        if (grabObjInfo.objectInHand.gameObject.name == "Cube")
        {
            Cube = grabObjInfo.objectInHand.GetComponent <ThrowObject>();
            if (Cube)
            {
                if (Cube.taskCompleted[0] != null)
                {
                    {
                        Cube.taskCompleted[0].Invoke();
                    }
                }
            }
        }
    }
    private void ReleaseObject(ControllerInformation info)
    {
        GrabObjectInformation grabObjInfo = (GrabObjectInformation)info.GetFunctionalityInfoByType(typeof(GrabObjectInformation));


        FixedJoint[] joints = info.trackedObj.gameObject.GetComponents <FixedJoint>();
        if (joints != null && joints.Length > 0)
        {
            foreach (var item in joints)
            {
                item.connectedBody = null;
                Destroy(item);
            }
        }
        if (grabObjInfo.objectInHand == null)
        {
            return;
        }
        grabObjInfo.objectInHand.GetComponent <Rigidbody>().velocity        = Quaternion.Euler(0, 180, 0) * controllerManager.GetController(info.trackedObj).velocity;
        grabObjInfo.objectInHand.GetComponent <Rigidbody>().angularVelocity = Quaternion.Euler(0, 180, 0) * controllerManager.GetController(info.trackedObj).angularVelocity;


        if (grabObjInfo.ObjectReleased != null)
        {
            grabObjInfo.ObjectReleased.Invoke(grabObjInfo.objectInHand);
        }

        grabObjInfo.objectInHand = null;
    }
 protected override void ActiveControllerUpdate(ControllerInformation controller)
 {
     if (vrInteraction.interactingWith && vrInteraction.interactingWith == this)
     {
         LightInteractionInformation info      = (LightInteractionInformation)controller.GetFunctionalityInfoByType(typeof(LightInteractionInformation));
         LightInteractionInformation otherInfo = (LightInteractionInformation)controllerManager.getOtherController(controller).GetFunctionalityInfoByType(typeof(LightInteractionInformation));
         if (!interactedThisFrame)
         {
             if (controllerManager.GetController(controller.trackedObj).GetPressUp(vrInteraction.menuButton))
             {
                 vrInteraction.interactingWith = null;
                 ((VRWatchInteraction)vrInteraction).HideWatch(controller);
                 ((VRWatchInteraction)vrInteraction).HideWatch(controllerManager.getOtherController(controller));
                 info.OnOffTimeObject.SetActive(false);
                 otherInfo.OnOffTimeObject.SetActive(false);
                 ActiveController = null;
             }
         }
         else
         {
             interactedThisFrame = !interactedThisFrame;
         }
         //tutorial event..
         if (controllerManager.GetController(controller.trackedObj).GetPressDown(Valve.VR.EVRButtonId.k_EButton_Grip))
         {
             if (interactingLight.taskCompleted[1] != null)
             {
                 interactingLight.taskCompleted[1].Invoke();
             }
         }
         UpdateTime(controller);
     }
 }
Ejemplo n.º 5
0
        private void InteractionManager_OnInteractionSourceLost(InteractionSourceLostEventArgs obj)
        {
            // update controllerDictionary
            if (obj.state.source.kind == InteractionSourceKind.Controller)
            {
                ControllerInformation ci;
                if (controllerDictionary.TryGetValue(obj.state.source.id, out ci))
                {
                    if (graspedHand != null && graspedHand.id == ci.id)
                    {
                        graspedHand = null;
                    }
                    Debug.LogFormat("Lost InteractionSource with controllerId={0}", ci.id);
                    controllerDictionary.Remove(ci.id);
                }

                if (controllerDictionary.Count == 0 &&
                    GamepadInput.Instance &&
                    !GamepadInput.Instance.enabled)
                {
                    // if we lost all (Motion)Controllers, enable the GamePad script
                    Debug.Log("Enabling GamepadInput instance");
                    GamepadInput.Instance.enabled = true;
                    InputRouter.Instance.EnableHoldAndNavigationGestures(true);
                }
            }
        }
Ejemplo n.º 6
0
        private void HandleNavigation(ControllerInformation ci, InteractionSourceUpdatedEventArgs obj)
        {
            float displacementAlongX = obj.state.thumbstickPosition.x;
            float displacementAlongY = obj.state.thumbstickPosition.y;

            if (Mathf.Abs(displacementAlongX) >= 0.1f ||
                Mathf.Abs(displacementAlongY) >= 0.1f ||
                navigatingHand != null)
            {
                if (navigatingHand == null)
                {
                    navigatingHand = ci;

                    //Raise navigation started event.
                    InputRouter.Instance.OnNavigationStartedWorker(InteractionSourceKind.Controller, Vector3.zero, new Ray());
                }

                if (navigatingHand.id == ci.id)
                {
                    Vector3 thumbValues = new Vector3(
                        displacementAlongX,
                        displacementAlongY,
                        0f);

                    InputRouter.Instance.OnNavigationUpdatedWorker(InteractionSourceKind.Controller, thumbValues, new Ray());
                }
            }
        }
    protected void UpdateDisplay(ControllerInformation controller)
    {
        LightInteractionInformation info      = (LightInteractionInformation)controller.GetFunctionalityInfoByType(typeof(LightInteractionInformation));
        WatchInteractionInformation watchInfo = (WatchInteractionInformation)controller.GetFunctionalityInfoByType(typeof(WatchInteractionInformation));

        if (watchInfo.watch.activeSelf && vrInteraction.interactingWith == this)
        {
            GameObject correctPart = null;
            if (info.isOnTime)
            {
                if ((watchInfo.isWatchOnFront && interactingLight.StartTime < 13) || (!watchInfo.isWatchOnFront && interactingLight.StartTime > 12))
                {
                    correctPart = ((VRWatchInteraction)vrInteraction).getCorrectPart(interactingLight.StartTime, controller);
                }
            }
            else
            {
                if ((watchInfo.isWatchOnFront && interactingLight.EndTime < 13) || (!watchInfo.isWatchOnFront && interactingLight.EndTime > 12))
                {
                    correctPart = ((VRWatchInteraction)vrInteraction).getCorrectPart(interactingLight.EndTime, controller);
                }
            }
            foreach (var item in watchInfo.allParts)
            {
                if (item != correctPart)
                {
                    ((VRWatchInteraction)vrInteraction).SetPartToNormal(item, controller);
                }
            }
            if (correctPart != null)
            {
                ((VRWatchInteraction)vrInteraction).SetPartToSelected(correctPart, controller);
            }
        }
    }
 protected override void ActiveControllerUpdate(ControllerInformation controller)
 {
     if (controllerManager.GetController(controller.trackedObj).GetPressDown(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger) && InteractWithHelpScreen.interactingHelpScreen == null)
     {
         controllerManager.GetComponent <ControllerGrabObject>().ForceGrab(Instantiate(spawnerPrefab, controller.trackedObj.transform.position + spawnOffset, Quaternion.identity), controller);
     }
 }
 protected override void NonActiveControllerUpdate(ControllerInformation controller)
 {
     if (vrInteraction.interactingWith && vrInteraction.interactingWith == this)
     {
         UpdateTime(controller);
     }
 }
 protected override void ActiveControllerUpdate(ControllerInformation controller)
 {
     if (vrInteraction.interactingWith && vrInteraction.interactingWith == this)
     {
         if (controllerManager.GetController(controller.trackedObj).GetPressUp(vrInteraction.menuButton))
         {
             if (!interactedThisFrame)
             {
                 vrInteraction.interactingWith = null;
                 HideButton();
                 ActiveController = null;
             }
             else
             {
                 interactedThisFrame = !interactedThisFrame;
             }
         }
         if (controllerManager.GetController(controller.trackedObj).GetPressDown(vrInteraction.gripButton))
         {
             interactingFireExtinguisher.SetActivated(!interactingFireExtinguisher.activated);
             StartCoroutine(SwitchSide());
         }
         OnOffSign.transform.LookAt(head);
     }
 }
 protected override void AnyControllerUpdate(ControllerInformation controller)
 {
     if (ActiveController == null)
     {
         ActiveController = controller;
     }
 }
Ejemplo n.º 12
0
    //Code duplication
    private void AddControllerInformation(string inputString)
    {
        string controllerOrder = InputToolMethod.ReturnJoyStickOrder(inputString);

        //check controllers thats already been added to see if this is a duplicate.
        for (int i = 0; i < connectedControllers.Count; i++)
        {
            //Controllers should be unique and not added through one controller
            //and controller order isnt any of the previous
            bool controlleOrderRepeated = false;
            for (int j = 0; j < connectedControllers.Count; j++)
            {
                if (controllerOrder == connectedControllers[j].controllerOrder)
                {
                    controlleOrderRepeated = true;
                }
            }
            if (connectedControllers[i].controller == ControllerInformation.ControllerType.None && !controlleOrderRepeated)
            {
                connectedControllers[i] = new ControllerInformation();
                connectedControllers[i].controllerOrder = controllerOrder;
                connectedControllers[i].controller      = ControllerInformation.ControllerType.Controller;
                initializePanelAdapter.RefreshPanel();
                break;
            }
        }
    }
    protected override void ActiveControllerUpdate(ControllerInformation controller)
    {
        HideLaser();
        //if (interactingHelpScreen != null)
        //{
        Ray        ray = new Ray(controller.trackedObj.transform.position, controller.trackedObj.transform.forward);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, 10f, layer))
        {
            ShowLaser(hit, controller);
            if (hit.collider.gameObject.name == "UpperTopicBorder")     //not the nicest way to solve..
            {
                hit.collider.GetComponentInParent <TutorialScreen>().Scroll(-1);
            }
            else if (hit.collider.gameObject.name == "LowerTopicBorder")     //not the nicest way to solve..
            {
                hit.collider.GetComponentInParent <TutorialScreen>().Scroll(1);
            }
        }

        if (controllerManager.GetController(controller.trackedObj).GetPressDown(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger))
        {
            Click(controller);
        }
        //}
    }
    public void Click(ControllerInformation controller)
    {
        Ray ray = new Ray(controller.trackedObj.transform.position, controller.trackedObj.transform.forward);

        Debug.DrawRay(transform.position, transform.forward * 100f);
        RaycastHit[] hits = Physics.RaycastAll(ray, 100f, layer);
        if (hits.Length > 0)
        {
            foreach (var hit in hits)
            {
                UITracked tracker = hit.collider.GetComponent <UITracked>();

                if (tracker != null)
                {
                    VRTopic        topic  = tracker.trackedUIObject.GetComponent <VRTopic>();
                    TutorialScreen screen = topic.GetComponentInParent <TutorialScreen>();
                    if (tracker.transform.position.y > screen.getLowerBorder().position.y - toleranceForOutsideRecognition && tracker.transform.position.y < screen.getUpperBorder().position.y + toleranceForOutsideRecognition)
                    {
                        screen.selectedTopic = topic;
                    }
                    break;
                }
            }
        }
    }
    protected override void OnInteract(GameObject go, ControllerInformation controller)
    {
        LightInteractionInformation info      = (LightInteractionInformation)controller.GetFunctionalityInfoByType(typeof(LightInteractionInformation));
        LightInteractionInformation otherInfo = (LightInteractionInformation)controllerManager.getOtherController(controller).GetFunctionalityInfoByType(typeof(LightInteractionInformation));

        interactingLight = go.GetComponent <VRLight>();
        if (interactingLight)
        {
            ((VRWatchInteraction)vrInteraction).ShowWatch(controller);
            ((VRWatchInteraction)vrInteraction).ShowWatch(controllerManager.getOtherController(controller));
            vrInteraction.interactingWith = this;
            interactedThisFrame           = true;
            info.OnOffTimeObject.SetActive(true);
            otherInfo.OnOffTimeObject.SetActive(true);
            ActiveController = controller;


            if (interactingLight.taskCompleted[0] != null)
            {
                interactingLight.taskCompleted[0].Invoke();
            }
        }
        else
        {
            controllerManager.GetController(controller.trackedObj).TriggerHapticPulse(3000);
        }
    }
    private FixedJoint AddFixedJoint(ControllerInformation info)
    {
        FixedJoint fx = info.trackedObj.gameObject.AddComponent <FixedJoint>();

        fx.breakForce  = 20000;
        fx.breakTorque = 20000;
        return(fx);
    }
 private void ShowLaser(RaycastHit hit, ControllerInformation controller)
 {
     laser.SetActive(true);                                                                            //Show the laser
     laserTransform.position = Vector3.Lerp(controller.trackedObj.transform.position, hit.point, .5f); // Move laser to the middle between the controller and the position the raycast hit
     laserTransform.LookAt(hit.point);                                                                 // Rotate laser facing the hit point
     laserTransform.localScale = new Vector3(laserTransform.localScale.x, laserTransform.localScale.y,
                                             hit.distance * 1.333f);                                   // Scale laser so it fits exactly between the controller & the hit point
 }
    public void ForceGrab(GameObject go, ControllerInformation info)
    {
        GrabObjectInformation grabObjInfo = (GrabObjectInformation)info.GetFunctionalityInfoByType(typeof(GrabObjectInformation));

        ReleaseObject(info);
        grabObjInfo.collidingObject = go;
        GrabObject(info);
    }
    public void SetPartToSelected(GameObject part, ControllerInformation controllerInfo)
    {
        int index = Array.IndexOf(GetOrderedParts(controllerInfo), part);

        if (allCoroutines[index] != null)
        {
            StopCoroutine(allCoroutines[index]);
        }
        allCoroutines[index] = StartCoroutine(_SetPartToSelected(part));
    }
 protected override void AnyControllerUpdate(ControllerInformation controller)
 {
     if (ActiveController == null)
     {
         if (controllerManager.GetController(controller.trackedObj).GetPress(SteamVR_Controller.ButtonMask.Touchpad))
         {
             ActiveController = controller;
         }
     }
 }
    public void ShowWatch(ControllerInformation controller)
    {
        WatchInteractionInformation info = (WatchInteractionInformation)controller.GetFunctionalityInfoByType(typeof(WatchInteractionInformation));

        info.watch.SetActive(true);
        updateDisplay(controller);
        //foreach (var item in controllerManager.controllerInfos)
        //{
        //    Debug.Log(item.functionalityInformations.Count);
        //}
    }
    private GameObject[] GetOrderedParts(ControllerInformation controller)
    {
        WatchInteractionInformation info = (WatchInteractionInformation)controller.GetFunctionalityInfoByType(typeof(WatchInteractionInformation));

        GameObject[] parts = new GameObject[12];
        for (int i = 0; i < parts.Length; i++)
        {
            parts[i] = info.watch.transform.GetChild(0).Find("Part" + (i + 1)).gameObject;
        }
        return(parts);
    }
 public ControllerInformation getOtherController(ControllerInformation controller)
 {
     foreach (var item in controllerInfos)
     {
         if (item != controller)
         {
             return(item);
         }
     }
     return(null);
 }
 protected override void AnyControllerUpdate(ControllerInformation controller)
 {
     if (ActiveController == null)
     {
         SteamVR_Controller.Device Controller = controllerManager.GetController(controller.trackedObj);
         if (Controller.GetPressDown(menuButton))
         {
             ActiveController = controller;
         }
     }
 }
Ejemplo n.º 25
0
        private void InteractionManager_OnInteractionSourceUpdated(InteractionSourceUpdatedEventArgs obj)
        {
            if (obj.state.source.kind != InteractionSourceKind.Controller)
            {
                return;
            }

            ControllerInformation ci = null;

            if (!controllerDictionary.TryGetValue(obj.state.source.id, out ci))
            {
                ci = AddNewControllerToDictionary(obj.state);
                if (ci == null)
                {
                    return;
                }
            }

            // Update the grasp state for the current controller and the tracked
            // grasped hand if we didn't already have one.
            ValidateGraspStateTracking(ci, obj);

            // Update position and forward
            if (obj.state.sourcePose.TryGetPosition(out ci.position, InteractionSourceNode.Pointer))
            {
                // convert local position into world position
                ci.position = CameraCache.Main.transform.parent.TransformPoint(ci.position);
            }
            if (obj.state.sourcePose.TryGetForward(out ci.forward, InteractionSourceNode.Pointer))
            {
                // convert local rotation into world rotation
                ci.forward = CameraCache.Main.transform.parent.TransformDirection(ci.forward);
            }


            HandleNavigation(ci, obj);

            // Update the x/y accumulators for the grasped controler
            if (graspedHand != null &&
                graspedHand.handedness == ci.handedness)
            {
                float x = obj.state.thumbstickPosition.x;
                float y = obj.state.thumbstickPosition.y;
                if (Mathf.Abs(x) >= 0.1f)
                {
                    ci.accumulatedX += x;
                }
                if (Mathf.Abs(y) >= 0.1f)
                {
                    ci.accumulatedY += y;
                }
            }
        }
    private void TriggerExit(Collider other, VRSensor sensor)
    {
        ControllerInformation info        = controllerManager.GetControllerInfo(sensor.GetComponent <SteamVR_TrackedObject>());
        GrabObjectInformation grabObjInfo = (GrabObjectInformation)info.GetFunctionalityInfoByType(typeof(GrabObjectInformation));

        if (!grabObjInfo.collidingObject)
        {
            return;
        }

        grabObjInfo.collidingObject = null;
    }
    /// <summary>
    /// In here we check if the collision that jsut occured is relevant
    /// </summary>
    private void SetCollidingObject(Collider col, ControllerInformation info)
    {
        GrabObjectInformation grabObjInfo = (GrabObjectInformation)info.GetFunctionalityInfoByType(typeof(GrabObjectInformation));

        if (grabObjInfo.collidingObject || !col.GetComponent <Rigidbody>() || col.GetComponent <SteamVR_TrackedObject>())
        {
            return;
        }
        grabObjInfo.collidingObject = col.gameObject;

        //Debug.Log("Collided with -> " +info.trackedObj + " - " + grabObjInfo.collidingObject.name);
    }
Ejemplo n.º 28
0
    protected override void AnyControllerUpdate(ControllerInformation controller)
    {
        ButtonInteractInformation grabObjInfo = (ButtonInteractInformation)controller.GetFunctionalityInfoByType(typeof(ButtonInteractInformation));

        if (controllerManager.GetController(controller.trackedObj).GetHairTriggerDown())
        {
            if (grabObjInfo.buttonInRange != null)
            {
                grabObjInfo.buttonInRange.Interact();
            }
        }
    }
    private void TriggerExit(Collider other, VRSensor sensor)
    {
        var trackedObj = other.GetComponent <SteamVR_TrackedObject>();

        if (trackedObj)
        {
            ControllerInformation grabber = controllerManager.GetControllerInfo(trackedObj);
            if (ActiveController == grabber)
            {
                ActiveController = null;
            }
        }
    }
Ejemplo n.º 30
0
        private void ValidateGraspStateTracking(ControllerInformation ci, InteractionSourceUpdatedEventArgs args)
        {
            Debug.Assert(ci != null);
            ci.grasped = args.state.grasped;

            if (ci.grasped && graspedHand == null)
            {
                graspedHand = ci;
            }
            else if (!ci.grasped && graspedHand != null && ci.id == graspedHand.id)
            {
                graspedHand = null;
            }
        }