コード例 #1
0
 private void Update()
 {
     for (int i = 0; i < hands.Length; i++)
     {
         float distance = Vector3.Distance(transform.position, hands[i].transform.position);
         if (distance < InteractRadious)
         {
             if (SteamVR_Input.GetStateUp("Shoot", hands[i].handType))
             {
                 if (hands[i].currentAttachedObject)
                 {
                     if (hands[i].currentAttachedObject.GetComponent <GrabbableObject>().grabTypes == MyGrabTypes.Hold)
                     {
                         StartInteraction(hands[i]);
                     }
                 }
             }
             else if (SteamVR_Input.GetStateDown("Shoot", hands[i].handType))
             {
                 StartInteraction(hands[i]);
             }
             else if (Input.GetKeyDown(KeyCode.N))
             {
                 StartInteraction(hands[i]);
             }
         }
     }
 }
コード例 #2
0
ファイル: PlayerInput.cs プロジェクト: makled/UnityCorn
        // Update is called once per frame
        void Update()
        {
            if (gun == null)
            {
                gun = FindObjectOfType <GunManager>();
            }
            isShoot = SteamVR_Input.GetStateUp("ShootGun", SteamVR_Input_Sources.LeftHand);
            if (isShoot)
            {
                gun.ShootGun();
            }

            locomotionVector = SteamVR_Input.GetVector2("Locomotion", SteamVR_Input_Sources.LeftHand);
            locomotion.supplyLocomotionVector(locomotionVector);
        }
コード例 #3
0
    // Update is called once per frame
    void Update()
    {
        if (SteamVR_Input.GetStateDown("default", "Teleport", SteamVR_Input_Sources.Any, true))
        {
            Debug.Log("Teleport button pressed");
        }
        if (SteamVR_Input.GetStateUp("default", "GrabPinch", SteamVR_Input_Sources.Any, true))
        {
            Debug.Log("Pinch button pressed");
        }
        float triggerValue = squeezeAction.GetAxis(SteamVR_Input_Sources.Any);

        if (triggerValue > 0.0f)
        {
            Debug.Log(triggerValue);
            testRenderer.gameObject.transform.localScale = Vector3.one * Random.Range(0.2f, 1f);
        }
    }
コード例 #4
0
    /// <summary>
    /// Update is called every frame, if the MonoBehaviour is enabled.
    /// </summary>
    void Update()
    {
        // Check if having your index finger streched is a requirement for touch detection.
        if (requiresOpenIndexFinger)
        {
            if (SteamVR_Input.GetStateDown("TouchIndex", SteamVR_Input_Sources.LeftHand) && hand.name == "LeftHand")
            {
                GetComponent <SphereCollider>().enabled = false;
            }
            else if (SteamVR_Input.GetStateUp("TouchIndex", SteamVR_Input_Sources.LeftHand) && hand.name == "LeftHand")
            {
                GetComponent <SphereCollider>().enabled = true;
            }

            if (SteamVR_Input.GetStateDown("TouchIndex", SteamVR_Input_Sources.RightHand) && hand.name == "RightHand")
            {
                GetComponent <SphereCollider>().enabled = false;
            }
            else if (SteamVR_Input.GetStateUp("TouchIndex", SteamVR_Input_Sources.RightHand) && hand.name == "RightHand")
            {
                GetComponent <SphereCollider>().enabled = true;
            }
        }

        // Check if the last button pressed is still highlighted after resting index finger on the controller (bug fix)
        if (!GetComponent <SphereCollider>().enabled)
        {
            if (lastButtonPressed)
            {
                if (lastButtonPressed.GetComponent <Image>().color != lastButtonPressed.colors.normalColor)
                {
                    // FIXME: Needs to be commented for multiple choice for Dialogue Tool plugin, but needs to be commented for other UI.
                    //lastButtonPressed.GetComponent<Image>().color = lastButtonPressed.colors.normalColor;
                }
            }
        }
    }
コード例 #5
0
 //-------------------------------------------------
 // Called every Update() while a Hand is hovering over this object
 //-------------------------------------------------
 private void HandHoverUpdate(Hand hand)
 {
     /*
      * if (isAvailable)
      * {
      *
      *  GrabTypes startingGrabType = hand.GetGrabStarting();
      *  bool isGrabEnding = hand.IsGrabEnding(this.gameObject);
      *
      *  if (interactable.attachedToHand == null && startingGrabType != GrabTypes.None)
      *  {
      *      if (activeSocket)
      *      {
      *          activeSocket.InteractSlot(hand);
      *          return;
      *      }
      *
      *      HandsAttached = 1;
      *      grabbingHand = hand;
      *      hand.HoverLock(interactable);
      *
      *      // Attach this object to the hand
      *      hand.AttachObject(gameObject, startingGrabType, attachmentFlags, grabposition);
      *  }
      *  else if (isGrabEnding)
      *  {
      *      // Detach this object from the hand
      *      hand.DetachObject(gameObject, restoreParent);
      *
      *      // Call this to undo HoverLock
      *      hand.HoverUnlock(interactable);
      *
      *
      *  }
      */
     if (isAvailable)
     {
         if (grabTypes == MyGrabTypes.Press)
         {
             if (SteamVR_Input.GetStateDown("Shoot", hand.handType))
             {
                 if (activeSocket)
                 {
                     activeSocket.InteractSlot(hand);
                     return;
                 }
                 if (hand.ObjectIsAttached(this.gameObject))
                 {
                     // Detach this object from the hand
                     hand.DetachObject(gameObject, restoreParent);
                     // Call this to undo HoverLock
                     hand.HoverUnlock(interactable);
                 }
                 else
                 {
                     HandsAttached = 1;
                     grabbingHand  = hand;
                     hand.HoverLock(interactable);
                     // Attach this object to the hand
                     hand.AttachObject(gameObject, GrabTypes.Scripted, attachmentFlags, grabposition);
                 }
             }
         }
         else if (grabTypes == MyGrabTypes.Hold)
         {
             if (SteamVR_Input.GetStateUp("Shoot", hand.handType))
             {
                 if (hand.ObjectIsAttached(this.gameObject))
                 {
                     // Detach this object from the hand
                     hand.DetachObject(gameObject, restoreParent);
                     // Call this to undo HoverLock
                     hand.HoverUnlock(interactable);
                 }
             }
             else if (SteamVR_Input.GetStateDown("Shoot", hand.handType))
             {
                 if (!hand.ObjectIsAttached(this.gameObject))
                 {
                     HandsAttached = 1;
                     grabbingHand  = hand;
                     hand.HoverLock(interactable);
                     // Attach this object to the hand
                     hand.AttachObject(gameObject, GrabTypes.Scripted, attachmentFlags, grabposition);
                 }
             }
         }
         else
         {
             if (SteamVR_Input.GetStateDown("Shoot", hand.handType))
             {
                 if (!hand.ObjectIsAttached(this.gameObject))
                 {
                     HandsAttached = 1;
                     grabbingHand  = hand;
                     hand.HoverLock(interactable);
                     // Attach this object to the hand
                     hand.AttachObject(gameObject, GrabTypes.Scripted, attachmentFlags, grabposition);
                 }
             }
         }
     }
 }