コード例 #1
0
        //-------------------------------------------------
        private void HandHoverUpdate(Hand hand)
        {
            if (takeBackItem && requireReleaseActionToReturn)
            {
                if (hand.isActive)
                {
                    ItemPackage currentAttachedItemPackage = GetAttachedItemPackage(hand);
                    if (currentAttachedItemPackage == itemPackage && hand.IsGrabEnding(currentAttachedItemPackage.gameObject))
                    {
                        TakeBackItem(hand);
                        return;                         // So that we don't pick up an ItemPackage the same frame that we return it
                    }
                }
            }

            if (requireGrabActionToTake)
            {
                GrabTypes startingGrab = hand.GetGrabStarting();

                if (startingGrab != GrabTypes.None)
                {
                    SpawnAndAttachObject(hand, GrabTypes.Scripted);
                }
            }
        }
コード例 #2
0
        //-------------------------------------------------
        private void HandHoverUpdate(Hand hand)
        {
            GrabTypes startingGrabType = hand.GetGrabStarting();
            bool      isGrabEnding     = hand.IsGrabEnding(this.gameObject);

            if (startingGrabType != GrabTypes.None)
            {
                hand.HoverLock(interactable);

                initialMappingOffset = linearMapping.value - CalculateLinearMapping(hand.transform);
                sampleCount          = 0;
                mappingChangeRate    = 0.0f;

                hand.AttachObject(gameObject, startingGrabType, attachmentFlags);
            }

            if (isGrabEnding)
            {
                hand.HoverUnlock(interactable);

                hand.DetachObject(gameObject);

                CalculateMappingChangeRate();
            }

            if (hand.currentAttachedObject == interactable.gameObject)
            {
                UpdateLinearMapping(hand.transform);
            }
        }
コード例 #3
0
        //-------------------------------------------------
        protected virtual void HandAttachedUpdate(Hand hand)
        {
            if (hand.IsGrabEnding(this.gameObject))
            {
                hand.DetachObject(gameObject, restoreOriginalParent);

                // Uncomment to detach ourselves late in the frame.
                // This is so that any vehicles the player is attached to
                // have a chance to finish updating themselves.
                // If we detach now, our position could be behind what it
                // will be at the end of the frame, and the object may appear
                // to teleport behind the hand when the player releases it.
                //StartCoroutine( LateDetach( hand ) );
            }
            if (scalingObject != null)
            {
                if (scalingObject.GetComponent <HairObject>().Grabbed)
                {
                    float scale = (Vector3.Distance(transform.position, otherHand.transform.position) / startDistance) * scaleMultip;
                    scale = Mathf.Clamp(scale, scaleMin, scaleMax);
                    scalingObject.transform.localScale = new Vector3(scale, scale, scale);
                }
            }

            if (onHeldUpdate != null)
            {
                onHeldUpdate.Invoke(hand);
            }
        }
コード例 #4
0
        //-------------------------------------------------
        protected virtual void HandAttachedUpdate(Hand hand)
        {
            if (attachEaseIn)
            {
                float t = Util.RemapNumberClamped(Time.time, attachTime, attachTime + snapAttachEaseInTime, 0.0f, 1.0f);
                if (t < 1.0f)
                {
                    t = snapAttachEaseInCurve.Evaluate(t);
                    transform.position = Vector3.Lerp(attachPosition, attachEaseInTransform.position, t);
                    transform.rotation = Quaternion.Lerp(attachRotation, attachEaseInTransform.rotation, t);
                }
                else if (!snapAttachEaseInCompleted)
                {
                    gameObject.SendMessage("OnThrowableAttachEaseInCompleted", hand, SendMessageOptions.DontRequireReceiver);
                    snapAttachEaseInCompleted = true;
                }
            }

            if (hand.IsGrabEnding(this.gameObject))
            {
                hand.DetachObject(gameObject, restoreOriginalParent);

                // Uncomment to detach ourselves late in the frame.
                // This is so that any vehicles the player is attached to
                // have a chance to finish updating themselves.
                // If we detach now, our position could be behind what it
                // will be at the end of the frame, and the object may appear
                // to teleport behind the hand when the player releases it.
                //StartCoroutine( LateDetach( hand ) );
            }
        }
コード例 #5
0
        protected virtual void HandAttachedUpdate(Hand hand)
        {
            if (hand.IsGrabEnding(this.gameObject))
            {
                hand.DetachObject(gameObject, restoreOriginalParent);

                // Uncomment to detach ourselves late in the frame.
                // This is so that any vehicles the player is attached to
                // have a chance to finish updating themselves.
                // If we detach now, our position could be behind what it
                // will be at the end of the frame, and the object may appear
                // to teleport behind the hand when the player releases it.
                //StartCoroutine( LateDetach( hand ) );
            }

            if (onHeldUpdate != null)
            {
                onHeldUpdate.Invoke(hand);
            }

//            var verticalDisplacement = GetVerticalDisplaceScalar(stationaryPosition, hand.transform.position);

//            Debug.Log(verticalDisplacement);

//            ModifyPitchBasedOnVerticalVectorDisplacement(verticalDisplacement, enablePitchModify);
        }
コード例 #6
0
        //-------------------------------------------------
        protected virtual void HandAttachedUpdate(Hand hand)
        {
            if (!toggleGrab)
            {
                if (hand.IsGrabEnding(this.gameObject))
                {
                    hand.DetachObject(gameObject, restoreOriginalParent);

                    // Uncomment to detach ourselves late in the frame.
                    // This is so that any vehicles the player is attached to
                    // have a chance to finish updating themselves.
                    // If we detach now, our position could be behind what it
                    // will be at the end of the frame, and the object may appear
                    // to teleport behind the hand when the player releases it.
                    //StartCoroutine( LateDetach( hand ) );
                }
            }
            else
            {
                GrabTypes startingGrabType = hand.GetGrabStarting();

                if (startingGrabType == GrabTypes.Grip)
                {
                    hand.DetachObject(gameObject, restoreOriginalParent);
                }
            }

            if (onHeldUpdate != null)
            {
                onHeldUpdate.Invoke(hand);
            }
        }
コード例 #7
0
    //-------------------------------------------------
    // Called every Update() while a Hand is hovering over this object
    //-------------------------------------------------
    private void HandHoverUpdate(ValveVR.Hand hand)
    {
        ValveVR.GrabTypes startingGrabType = hand.GetGrabStarting();
        bool isGrabEnding = hand.IsGrabEnding(this.gameObject);

        if (interactable.attachedToHand == null && startingGrabType != ValveVR.GrabTypes.None)
        {
            // Save our position/rotation so that we can restore it when we detach
            //oldPosition = transform.position;
            //oldRotation = transform.rotation;

            // Call this to continue receiving HandHoverUpdate messages,
            // and prevent the hand from hovering over anything else
            hand.HoverLock(interactable);

            // Attach this object to the hand
            hand.AttachObject(gameObject, startingGrabType, attachmentFlags);
        }
        else if (isGrabEnding)
        {
            // Detach this object from the hand
            hand.DetachObject(gameObject);

            // Call this to undo HoverLock
            hand.HoverUnlock(interactable);

            // Restore position/rotation
            //transform.position = oldPosition;
            //transform.rotation = oldRotation;
        }
    }
コード例 #8
0
 protected virtual void HandAttachedUpdate(Hand hand)
 {
     if (hand.IsGrabEnding(this.gameObject))
     {
         hand.DetachObject(gameObject, restoreOriginalParent);
         ShowController();
     }
 }
コード例 #9
0
 protected virtual void HandAttachedUpdate(Hand hand)
 {
     hand.Show();
     if (hand.IsGrabEnding(this.gameObject))
     {
         hand.DetachObject(gameObject);
     }
 }
コード例 #10
0
ファイル: LinearDrive.cs プロジェクト: obkaul/VRTactileDraw
        protected virtual void HandAttachedUpdate(Hand hand)
        {
            UpdateLinearMapping(hand.transform);

            if (hand.IsGrabEnding(this.gameObject))
            {
                hand.DetachObject(gameObject);
            }
        }
コード例 #11
0
        protected virtual void HandAttachedUpdate(Hand hand)
        {
            hovering        = true;
            lastHoveredHand = hand;

            bool wasEngaged = engaged;

            float currentDistance = Vector3.Distance(movingPart.parent.InverseTransformPoint(hand.transform.position), endPosition);
            float enteredDistance = Vector3.Distance(handEnteredPosition, endPosition);

            if (currentDistance > enteredDistance)
            {
                enteredDistance = currentDistance;
                //handEnteredPosition = movingPart.parent.InverseTransformPoint(hand.transform.position);
                handEnteredPosition = movingPart.localPosition;
            }

            float distanceDifference = enteredDistance - currentDistance;

            float lerp = Mathf.InverseLerp(0, localMoveDistance.magnitude, distanceDifference);

            if (lerp > engageAtPercent)
            {
                engaged = true;
            }
            else if (lerp < disengageAtPercent)
            {
                engaged = false;
            }
            print("end position: " + endPosition.x);
            //print("localmovedis: " + localMoveDistance.x);
            print("local position: " + movingPart.localPosition.x);
            if (movingPart.localPosition.x <= endPosition.x)
            {
                print("dsgsgdraesgraehaerhreg\rwhrwhrehraehr");
                hand.DetachObject(gameObject);
                movingPart.localPosition = new Vector3(endPosition.x + 0.2f, endPosition.y, endPosition.z);
                // movingPart.Translate(-1.29f, 0.000f, 1.616f);
            }
            else
            {
                movingPart.localPosition = Vector3.Lerp(startPosition, endPosition, lerp);
            }


            //print("end position: " + endPosition.x);

            //InvokeEvents(wasEngaged, engaged);

            //print(currentDistance);

            if (hand.IsGrabEnding(this.gameObject))
            {
                hand.DetachObject(gameObject);
            }
        }
コード例 #12
0
        //-------------------------------------------------
        protected virtual void HandAttachedUpdate(Hand hand)
        {
            //int index = hand.attachedObjects.FindIndex(l => l.attachedObject == objectToDetach);
            //if (index != -1)
            bool inputForGrab = OculusInputManager.Instance.GetGrabAnyClicked(OculusInputManager.Instance.GetOculusHand(hand.handType));

            // if(inputForGrab){
            //      Debug.Log("[Throwable][HandAttachedUpdate]["+gameObject.name+"] DetachObject "+gameObject.name+" - detached! (Remove this!) inputForGrab: "+inputForGrab);
            //      //hand.DetachObject(gameObject, restoreOriginalParent);
            // }



            if (neverLetGo)
            {
            }
            else
            if (dontLetGoOnInputUp && inputForGrab &&
                ((grabTypeIfKnown == GrabTypes.Scripted || grabTypeIfKnown == GrabTypes.Trigger) ||
                 m_inputUpIgnored > 0)
                )
            {
                hand.DetachObject(gameObject, restoreOriginalParent);
                Debug.Log("Detatching: " + gameObject.name);
            }
            else
            if (hand.IsGrabEnding(this.gameObject, dontLetGoOnInputUp))
            {
                Debug.Log("Detatching2: " + gameObject.name);

                hand.DetachObject(gameObject, restoreOriginalParent);

                // Uncomment to detach ourselves late in the frame.
                // This is so that any vehicles the player is attached to
                // have a chance to finish updating themselves.
                // If we detach now, our position could be behind what it
                // will be at the end of the frame, and the object may appear
                // to teleport behind the hand when the player releases it.
                //StartCoroutine( LateDetach( hand ) );
            }

            if (dontLetGoOnInputUp && inputForGrab)
            {
                m_inputUpIgnored++;
            }

            if (onHeldUpdate != null)
            {
                onHeldUpdate.Invoke(hand);
            }
        }
コード例 #13
0
        protected virtual void HandAttachedUpdate(Hand hand)
        {
            ComputeAngle(hand);
            UpdateAll();

            if (hand.IsGrabEnding(this.gameObject))
            {
                hand.DetachObject(gameObject);

                if (hoverLock)
                {
                    hand.HoverUnlock(interactable);
                    handHoverLocked = null;
                }
            }
        }
コード例 #14
0
 protected virtual void HandAttachedUpdate(Hand hand)
 {
     // Check if we are trying to drop the object, only allowing this if we are hovering over a tower node
     if (hand.IsGrabEnding(this.gameObject))
     {
         if (intersectedNode != null)
         {
             // Attempt to attach the tower at the node
             if (intersectedNode.IsOpen() || intersectedNode.allowsSwapping)
             {
                 hand.DetachObject(gameObject, false);
                 intersectedNode.TryAttachTower(this, nodePositionOffset, nodeRotationOffset, hand);
             }
         }
         else
         {
             // Restore the tower object to its original position
             hand.DetachObject(gameObject, false);
             crtRespawn = StartCoroutine(Respawn());
         }
     }
 }
コード例 #15
0
        //-------------------------------------------------
        protected virtual void HandAttachedUpdate(Hand hand)
        {
            // CHANGE: added check for scripted grab type -> means that the release of the object es
            // managed separately and the object should not be released if the button is released
            if (hand.IsGrabEnding(this.gameObject) && GetGrabbingType(hand, this.gameObject) != GrabTypes.Scripted)
            {
                hand.DetachObject(gameObject, restoreOriginalParent);

                // Uncomment to detach ourselves late in the frame.
                // This is so that any vehicles the player is attached to
                // have a chance to finish updating themselves.
                // If we detach now, our position could be behind what it
                // will be at the end of the frame, and the object may appear
                // to teleport behind the hand when the player releases it.
                //StartCoroutine( LateDetach( hand ) );
            }

            if (onHeldUpdate != null)
            {
                onHeldUpdate.Invoke(hand);
            }
        }
コード例 #16
0
ファイル: CircularDrive.cs プロジェクト: moorthi07/Moondust
        //-------------------------------------------------
        private void HandHoverUpdate(Hand hand)
        {
            GrabTypes startingGrabType = hand.GetGrabStarting();
            bool      isGrabEnding     = hand.IsGrabEnding(this.gameObject);

            if (startingGrabType != GrabTypes.None)
            {
                // Trigger was just pressed
                lastHandProjected = ComputeToTransformProjected(hand.hoverSphereTransform);

                if (hoverLock)
                {
                    hand.HoverLock(interactable);
                    handHoverLocked = hand;
                }

                driving = true;

                ComputeAngle(hand);
                UpdateAll();

                hand.HideGrabHint();
            }

            if (isGrabEnding)
            {
                // Trigger was just released
                if (hoverLock)
                {
                    hand.HoverUnlock(interactable);
                    handHoverLocked = null;
                }
            }
            else if (driving && isGrabEnding == false && hand.hoveringInteractable == this.interactable)
            {
                ComputeAngle(hand);
                UpdateAll();
            }
        }
コード例 #17
0
        //-------------------------------------------------
        // Called every Update() while a Hand is hovering over this object
        //-------------------------------------------------
        private void HandHoverUpdate(Hand hand)
        {
            //Debug.DrawLine(transform.position, transform.position + transform.forward, Color.blue);
            //Debug.DrawLine(transform.position, transform.position + transform.up, Color.green);
            //Debug.DrawLine(transform.position, transform.position + transform.right, Color.red);
            GrabTypes startingGrabType = hand.GetGrabStarting();
            GrabTypes endingGrabType   = hand.GetGrabEnding();
            bool      isGrabEnding     = hand.IsGrabEnding(this.gameObject);

            if (interactable.attachedToHand == null)
            {
                if (startingGrabType != GrabTypes.None)
                {
                    hand.HoverLock(interactable);
                    hand.AttachObject(gameObject, startingGrabType, attachmentFlags);
                }
            }
            else
            {
                if (startingGrabType == GrabTypes.Pinch)
                {
                    magicCircle = Instantiate(magicCirclePrefab, transform.position + transform.up * 3, Quaternion.identity);
                    magicCircle.transform.LookAt(transform.position);

                    point = Instantiate(pointPrefab, magicCircle.transform.position, Quaternion.identity);
                }
                if (hand.IsGrabbingWithType(GrabTypes.Pinch))
                {
                    // 마법 발동? 그리기
                    // holy 12365416851651561651456561561shit
                    magicEffect.SetActive(true);

                    if (Physics.Raycast(transform.position, transform.up, out RaycastHit hit, Mathf.Infinity))
                    {
                        Debug.Log(hit.transform.name);
                        if (hit.transform.CompareTag("paint") || hit.transform.CompareTag("paintTrigger"))
                        {
                            point.transform.position = hit.point;
                            if (hit.transform.CompareTag("paintTrigger") && !isPointTrigger)
                            {
                                isPointTrigger = true;
                                hand.hapticAction.Execute(0, 0.1f, 1, 30, hand.handType);
                                line.positionCount++;
                                line.SetPosition(line.positionCount - 1, hit.transform.position + hit.transform.forward * 0.1f);
                            }
                            else if (hit.transform.CompareTag("paint") && isPointTrigger)
                            {
                                isPointTrigger = false;
                            }
                        }
                    }
                }
                if (endingGrabType == GrabTypes.Pinch)
                {
                    magicEffect.SetActive(false);
                    Destroy(magicCircle.gameObject);
                    Destroy(point.gameObject);
                    line.positionCount = 0;
                }
                if (startingGrabType == GrabTypes.Grip)
                {
                    // 내려놓기
                    // 굳이 없어도 될듯?
                    hand.DetachObject(gameObject);
                    hand.HoverUnlock(interactable);
                }
            }
        }