コード例 #1
0
        void TeleportInteractables()
        {
            NVRInteractable LHandInteractable = Player.LeftHand.CurrentlyInteracting;
            NVRInteractable RHandInteractable = Player.RightHand.CurrentlyInteracting;

            if (LHandInteractable != null)
            {
                DoNotTeleportObject LTO = LHandInteractable.transform.gameObject.GetComponent <DoNotTeleportObject> ();
                if (LTO == null || LTO.DoTeleport)
                {
                    LHandInteractable.transform.position = Player.LeftHand.transform.position;
                }
            }
            if (RHandInteractable != null)
            {
                DoNotTeleportObject RTO = RHandInteractable.transform.gameObject.GetComponent <DoNotTeleportObject> ();
                if (RTO == null || RTO.DoTeleport)
                {
                    RHandInteractable.transform.position = Player.RightHand.transform.position;
                }
            }
        }
コード例 #2
0
    public override void UseButtonDown()
    {
        base.UseButtonDown();
        NVRPlayer player = AttachedHand.GetComponentInParent <NVRPlayer> ();

        if (!player.LeftHand || !player.RightHand)
        {
            return;
        }
        NVRInteractable left  = player.LeftHand.CurrentlyInteracting;
        NVRInteractable right = player.RightHand.CurrentlyInteracting;

        if (!left || !right)
        {
            return;
        }
        GameObject leftGame  = left.gameObject;
        GameObject rightGame = right.gameObject;

        if (!leftGame || !rightGame)
        {
            return;
        }

        Constructable leftCons  = leftGame.GetComponent <Constructable> ();
        Constructable rightCons = rightGame.GetComponent <Constructable> ();

        if (leftCons && rightCons &&
            player.LeftHand.UseButtonPressed && player.RightHand.UseButtonPressed)
        {
            Debug.Log("MAKING CONNECTION");
            FixedJoint f = left.gameObject.AddComponent <FixedJoint> ();
            f.breakForce    = breakForce;
            f.connectedBody = right.gameObject.GetComponent <Rigidbody> ();
        }
    }
コード例 #3
0
    public IEnumerator delayForReactivate(NVRInteractable item)
    {
        yield return(new WaitForSeconds(.5f));

        item.GetComponent <NVRInteractableItem>().enabled = true;
    }
コード例 #4
0
    public void SendEndInterraction(NVRInteractable item)
    {
        SerializableRigidbody rb = new SerializableRigidbody(item.Rigidbody);

        photonView.RPC("ReceiveEndInteraction", PhotonTargets.Others, SerializationToolkit.ObjectToByteArray(rb), GetObjectID(item));
    }
コード例 #5
0
    public void SendBeginInterraction(NVRInteractable item, NVRHand hand)
    {
        SerializableTransform t = new SerializableTransform(item.transform.position - hand.transform.position, item.transform.rotation);

        photonView.RPC("ReceiveBeginInteraction", PhotonTargets.Others, SerializationToolkit.ObjectToByteArray(t), hand.IsRight, GetObjectID(item), NetworkPlayerManager.Instance.personalID);
    }
コード例 #6
0
    // Update is called once per frame
    void Update()
    {
        if (controller.GetPressDown(triggerButton))
        //IPL.Set_Left_Interacting(true); IPL.Set_Player_Interacting(true);
        {
            IPL.SetLeftTriggerInteracting(true);
            if (anthology)
            {
                if (anthology.active)
                {
                    anthology.activate(true);
                }
            }
        }

        if (controller.GetPressUp(triggerButton))
        //IPL.Set_Left_Interacting(false); IPL.Set_Player_Interacting(false);
        {
            IPL.SetLeftTriggerInteracting(false);
            if (objectHovering)
            {
                objectHovering.GetComponent <Rigidbody>().isKinematic     = false;
                objectHovering.GetComponent <Rigidbody>().velocity        = controller.velocity + new Vector3(controller.velocity.x * -2, 0, controller.velocity.z * -2);
                objectHovering.GetComponent <Rigidbody>().angularVelocity = controller.angularVelocity;
            }
            if (anthology)
            {
                if (anthology.active)
                {
                    anthology.activate(true);
                }
            }
        }
        if (controller.GetPressDown(gripButton))
        //IPL.Set_Left_Interacting(true); IPL.Set_Player_Interacting(true);
        {
            IPL.SetLeftGripped(true);
            aimer.SetActive(true);
        }
        if (controller.GetPressUp(gripButton))
        //IPL.Set_Left_Interacting(false); IPL.Set_Player_Interacting(false);
        {
            aimer.SetActive(false);
            IPL.SetLeftGripped(false);
            if (IPL.leftHand.CurrentlyInteracting)
            {
                NVRInteractable test = IPL.leftHand.CurrentlyInteracting;
                StartCoroutine(delayForReactivate(test));
                test.GetComponent <NVRInteractableItem>().enabled = false;
                IPL.leftHand.EndInteraction(test);
                test.GetComponent <Rigidbody>().AddForce(raycastOrigin.transform.forward * 500);
                StartCoroutine("vibrateLeft", .1f);
                PlaySound(source, sounds[1], true);
            }
            else if (objectHovering && IPL.leftTriggerInteractive)
            {
                NVRInteractableItem test = objectHovering;
                objectHovering = null;
                test.GetComponent <Rigidbody>().isKinematic = false;
                test.GetComponent <Rigidbody>().AddForce(raycastOrigin.transform.forward * 500);
                StartCoroutine("vibrateLeft", .1f);
                PlaySound(source, sounds[1], true);
            }
        }

        if (controller.GetPressDown(aButton) || controller.GetPressDown(bButton) || controller.GetPressDown(joystickPress))
        {
            IPL.SetRightButtonInteracting(true);
            anthology.activate(true);
        }
        if (controller.GetPressUp(aButton) || controller.GetPressUp(bButton) || controller.GetPressUp(joystickPress))
        {
            IPL.SetRightButtonInteracting(false);
            anthology.activate(false);
        }


        if (!IPL.GetLeftTriggerInteracting())
        {
            hovering       = Physics.OverlapBox(raycastOrigin.transform.position + raycastOrigin.transform.forward * IPL.range, IPL.halfExtents, raycastOrigin.transform.rotation);
            objectHovering = IPL.CheckForObject(hovering, raycastOrigin.transform, false);

            //indicator.transform.position = hovering.transform.position;
            if (objectHovering)
            {
                ringDisplay.transform.position = objectHovering.transform.position;
                ringDisplay.transform.LookAt(Camera.main.transform);
            }
            playedWhoosh = false;
        }
        else
        {
            if (objectHovering) //&& !IPL.leftHand.CurrentlyInteracting)
            {
                if (!playedWhoosh)
                {
                    StartCoroutine("vibrateLeft", .1f);
                    PlaySound(source, sounds[0], true);
                    playedWhoosh = true;
                }
                objectHovering.GetComponent <Rigidbody>().isKinematic = true;
                objectHovering.transform.position = Vector3.MoveTowards(objectHovering.transform.position, raycastOrigin.transform.position, IPL.pullSpeed * Time.deltaTime);
            }
        }
        if (objectHovering && IPL.GetLeftTriggerInteracting())
        {
            pullSomething = true;
            if (objectHovering.GetComponent <PotionStack>())
            {
                pullPotion = true;
            }
            else
            {
                pullPotion = false;
            }
        }
        else
        {
            pullSomething = false;
        }
        if (objectHovering && !IPL.GetLeftTriggerInteracting())
        {
            ringDisplay.enabled = true;
        }
        else
        {
            ringDisplay.enabled = false;
        }
    }
コード例 #7
0
    private void LateUpdate()
    {
        Line.enabled = (Hand != null && Hand.Inputs[LaserEnableButton].SingleAxis > 0.01f);

        if (Line.enabled == true)
        {
            Line.material.SetColor("_Color", LineColor);
            NVRHelpers.LineRendererSetColor(Line, LineColor, LineColor);
            NVRHelpers.LineRendererSetWidth(Line, LineWidth, LineWidth);

            RaycastHit hitInfo;
            bool       hit      = Physics.Raycast(this.transform.position, this.transform.forward, out hitInfo, 1000);
            Vector3    endPoint = transform.position;

            if (hit == true)
            {
                // TODO: Display marker at hit location
                endPoint = hitInfo.point;

                bool isInLayer;
                if (RestrictToLayer)
                {
                    isInLayer = ((Layer & 1 << hitInfo.transform.gameObject.layer) ==
                                 1 << hitInfo.transform.gameObject.layer);
                }
                else
                {
                    isInLayer = true;
                }

                if (hitInfo.distance <= MaxTeleportDistance && isInLayer)
                {
                    if (Hand.Inputs[TeleportButton].PressDown == true)
                    {
                        NVRInteractable LHandInteractable = Player.LeftHand.CurrentlyInteracting;
                        NVRInteractable RHandInteractable = Player.RightHand.CurrentlyInteracting;


                        Vector3 offset = Player.Head.transform.position - Player.transform.position;
                        offset.y = 0;

                        Player.transform.position = hitInfo.point - offset;
                        if (LHandInteractable != null)
                        {
                            LHandInteractable.transform.position = Player.LeftHand.transform.position;
                        }

                        if (RHandInteractable != null)
                        {
                            RHandInteractable.transform.position = Player.RightHand.transform.position;
                        }
                    }
                }
            }
            else
            {
                endPoint = this.transform.position + (this.transform.forward * 1000f);
            }

            Line.SetPositions(new Vector3[] { this.transform.position, endPoint });
        }
    }
コード例 #8
0
    private void LateUpdate()
    {
        var controller = GetComponent <SteamVR_TrackedController>();


        Line.enabled = controller.triggerPressed;
        controller.TriggerClicked += teleport;


        if (Line.enabled)
        {
            // Draw Line

            // Check if can teleport, when we can, add teleport to trigger clicked
        }

        if (Line.enabled == true)
        {
            Line.material.SetColor("_Color", LineColor);
            NVRHelpers.LineRendererSetColor(Line, LineColor, LineColor);
            NVRHelpers.LineRendererSetWidth(Line, LineWidth, LineWidth);

            RaycastHit hitInfo;
            bool       hit      = Physics.Raycast(this.transform.position, this.transform.forward, out hitInfo, 1000);
            Vector3    endPoint = transform.position;

            if (hit == true)
            {
                // TODO: Display marker at hit location
                endPoint = hitInfo.point;

                bool isInLayer;
                if (RestrictToLayer)
                {
                    isInLayer = ((Layer & 1 << hitInfo.transform.gameObject.layer) ==
                                 1 << hitInfo.transform.gameObject.layer);
                }
                else
                {
                    isInLayer = true;
                }

                if (hitInfo.distance <= MaxTeleportDistance && isInLayer)
                {
                    if (true)    // Hand.Inputs[TeleportButton].PressDown == true)
                    {
                        NVRInteractable LHandInteractable = Player.LeftHand.CurrentlyInteracting;
                        NVRInteractable RHandInteractable = Player.RightHand.CurrentlyInteracting;


                        Vector3 offset = Player.Head.transform.position - Player.transform.position;
                        offset.y = 0;

                        Player.transform.position = hitInfo.point - offset;
                        if (LHandInteractable != null)
                        {
                            LHandInteractable.transform.position = Player.LeftHand.transform.position;
                        }

                        if (RHandInteractable != null)
                        {
                            RHandInteractable.transform.position = Player.RightHand.transform.position;
                        }
                    }
                }
            }
            else
            {
                endPoint = this.transform.position + (this.transform.forward * 1000f);
            }

            Line.SetPositions(new Vector3[] { this.transform.position, endPoint });
        }
    }