//------------------------------------------------- protected virtual void OnHandHoverBegin(IF_VR_Steam_Hand hand) { currentHand = hand; IF_VR_Steam_InputModule.instance.HoverBegin(gameObject); // ckbang - Hints //IF_VR_Steam_ControllerButtonHints.ShowButtonHint( hand, hand.uiInteractAction); }
protected virtual void HandAttachedUpdate(IF_VR_Steam_Hand hand) { Color grabbedColor; switch (hand.currentAttachedObjectInfo.Value.grabbedWithType) { case IF_VR_Steam_GrabTypes.Grip: grabbedColor = Color.blue; break; case IF_VR_Steam_GrabTypes.Pinch: grabbedColor = Color.green; break; case IF_VR_Steam_GrabTypes.Trigger: grabbedColor = Color.yellow; break; case IF_VR_Steam_GrabTypes.Scripted: grabbedColor = Color.red; break; case IF_VR_Steam_GrabTypes.None: default: grabbedColor = Color.white; break; } if ((onlyColorOnChange && grabbedColor != lastColor) || onlyColorOnChange == false) { ColorSelf(grabbedColor); } lastColor = grabbedColor; }
//------------------------------------------------- protected virtual void OnHandHoverEnd(IF_VR_Steam_Hand hand) { IF_VR_Steam_InputModule.instance.HoverEnd(gameObject); // ckbang - Hints //IF_VR_Steam_ControllerButtonHints.HideButtonHint( hand, hand.uiInteractAction); currentHand = null; }
//------------------------------------------------- protected virtual void OnHandHoverBegin(IF_VR_Steam_Hand hand) { bool showHint = false; // "Catch" the throwable by holding down the interaction button instead of pressing it. // Only do this if the throwable is moving faster than the prescribed threshold speed, // and if it isn't attached to another hand if (!attached && catchingSpeedThreshold != -1) { float catchingThreshold = catchingSpeedThreshold * SteamVR_Utils.GetLossyScale(IF_VR_Steam_Player.instance.trackingOriginTransform); IF_VR_Steam_GrabTypes bestGrabType = hand.GetBestGrabbingType(); if (bestGrabType != IF_VR_Steam_GrabTypes.None) { if (rigidbody.velocity.magnitude >= catchingThreshold) { hand.AttachObject(gameObject, bestGrabType, attachmentFlags); showHint = false; } } } if (showHint) { hand.ShowGrabHint(); } }
protected virtual void OnDetachedFromHand(IF_VR_Steam_Hand hand) { if (activateActionSetOnAttach != null) { if (hand.otherHand == null || hand.otherHand.currentAttachedObjectInfo.HasValue == false || (hand.otherHand.currentAttachedObjectInfo.Value.interactable != null && hand.otherHand.currentAttachedObjectInfo.Value.interactable.activateActionSetOnAttach != this.activateActionSetOnAttach)) { activateActionSetOnAttach.Deactivate(hand.handType); } } if (onDetachedFromHand != null) { onDetachedFromHand.Invoke(hand); } if (skeletonPoser != null) { if (hand.skeleton != null) { hand.skeleton.BlendToSkeleton(releasePoseBlendTime); } } attachedToHand = null; }
//------------------------------------------------- private void HandHoverUpdate(IF_VR_Steam_Hand hand) { if (takeBackItem && requireReleaseActionToReturn) { if (hand.isActive) { IF_VR_Steam_ItemPackage currentAttachedItemPackage = GetAttachedItemPackage(hand); if (currentAttachedItemPackage == itemPackage && hand.IsGrabEnding(currentAttachedItemPackage.gameObject)) { TakeBackItem(hand); return; // So that we don't pick up an IF_VR_Steam_ItemPackage the same frame that we return it } } } if (requireGrabActionToTake) { IF_VR_Steam_GrabTypes startingGrab = hand.GetGrabStarting(); if (startingGrab != IF_VR_Steam_GrabTypes.None) { SpawnAndAttachObject(hand, IF_VR_Steam_GrabTypes.Scripted); } } }
//------------------------------------------------- private bool PhysicsDetach( IF_VR_Steam_Hand hand ) { int i = holdingHands.IndexOf( hand ); if ( i != -1 ) { // Detach this object from the hand holdingHands[i].DetachObject( this.gameObject, false ); // Allow the hand to do other things holdingHands[i].HoverUnlock( null ); // Delete any existing joints from the hand if ( attachMode == AttachMode.FixedJoint ) { Destroy( holdingHands[i].GetComponent<FixedJoint>() ); } IF_VR_Steam_Util.FastRemove( holdingHands, i ); IF_VR_Steam_Util.FastRemove( holdingBodies, i ); IF_VR_Steam_Util.FastRemove( holdingPoints, i ); return true; } return false; }
private void HandHoverUpdate(IF_VR_Steam_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); } float distanceDifference = enteredDistance - currentDistance; float lerp = Mathf.InverseLerp(0, localMoveDistance.magnitude, distanceDifference); if (lerp > engageAtPercent) { engaged = true; } else if (lerp < disengageAtPercent) { engaged = false; } movingPart.localPosition = Vector3.Lerp(startPosition, endPosition, lerp); InvokeEvents(wasEngaged, engaged); }
//------------------------------------------------- private void Freeze(IF_VR_Steam_Hand hand) { frozen = true; frozenAngle = outAngle; frozenHandWorldPos = hand.hoverSphereTransform.position; frozenSqDistanceMinMaxThreshold.x = frozenDistanceMinMaxThreshold.x * frozenDistanceMinMaxThreshold.x; frozenSqDistanceMinMaxThreshold.y = frozenDistanceMinMaxThreshold.y * frozenDistanceMinMaxThreshold.y; }
//------------------------------------------------- protected virtual void HandHoverUpdate(IF_VR_Steam_Hand hand) { if (hand.uiInteractAction != null && hand.uiInteractAction.GetStateDown(hand.handType)) { IF_VR_Steam_InputModule.instance.Submit(gameObject); // ckbang - Hints //IF_VR_Steam_ControllerButtonHints.HideButtonHint( hand, hand.uiInteractAction); } }
protected override void HandAttachedUpdate(IF_VR_Steam_Hand hand) { if (interactable.skeletonPoser != null) { interactable.skeletonPoser.SetBlendingBehaviourEnabled("PinchPose", hand.currentAttachedObjectInfo.Value.grabbedWithType == IF_VR_Steam_GrabTypes.Pinch); } base.HandAttachedUpdate(hand); }
//------------------------------------------------- void OnDisable() { if (handHoverLocked) { handHoverLocked.HideGrabHint(); handHoverLocked.HoverUnlock(interactable); handHoverLocked = null; } }
//------------------------------------------------- protected virtual void OnHandFocusLost(IF_VR_Steam_Hand hand) { gameObject.SetActive(false); if (velocityEstimator != null) { velocityEstimator.FinishEstimatingVelocity(); } }
//------------------------------------------------- protected virtual void OnHandFocusAcquired(IF_VR_Steam_Hand hand) { gameObject.SetActive(true); if (velocityEstimator != null) { velocityEstimator.BeginEstimatingVelocity(); } }
protected virtual void HandAttachedUpdate(IF_VR_Steam_Hand hand) { UpdateLinearMapping(hand.transform); if (hand.IsGrabEnding(this.gameObject)) { hand.DetachObject(gameObject); } }
//------------------------------------------------- private void OnHandHoverEnd(IF_VR_Steam_Hand hand) { if (!justPickedUpItem && requireGrabActionToTake && showTriggerHint) { hand.HideGrabHint(); } justPickedUpItem = false; }
//------------------------------------------------- private void TakeBackItem(IF_VR_Steam_Hand hand) { RemoveMatchingItemsFromHandStack(itemPackage, hand); if (itemPackage.packageType == IF_VR_Steam_ItemPackage.ItemPackageType.TwoHanded) { RemoveMatchingItemsFromHandStack(itemPackage, hand.otherHand); } }
//------------------------------------------------- private void HandHoverUpdate( IF_VR_Steam_Hand hand ) { IF_VR_Steam_GrabTypes startingGrabType = hand.GetGrabStarting(); if (startingGrabType != IF_VR_Steam_GrabTypes.None) { PhysicsAttach( hand, startingGrabType ); } }
//------------------------------------------------- protected virtual void HandHoverUpdate(IF_VR_Steam_Hand hand) { IF_VR_Steam_GrabTypes startingGrabType = hand.GetGrabStarting(); if (startingGrabType != IF_VR_Steam_GrabTypes.None) { hand.AttachObject(gameObject, startingGrabType, attachmentFlags, attachmentOffset); hand.HideGrabHint(); } }
//------------------------------------------------- private void OnHandHoverEnd( IF_VR_Steam_Hand hand ) { if ( holdingHands.IndexOf( hand ) == -1 ) { if (hand.isActive) { hand.TriggerHapticPulse( 500 ); } } }
//------------------------------------------------- private void OnHandHoverEnd(IF_VR_Steam_Hand hand) { hand.HideGrabHint(); if (driving && hand) { //hand.TriggerHapticPulse() //todo: fix StartCoroutine(HapticPulses(hand, 1.0f, 10)); } driving = false; handHoverLocked = null; }
protected virtual void HandHoverUpdate(IF_VR_Steam_Hand hand) { IF_VR_Steam_GrabTypes startingGrabType = hand.GetGrabStarting(); if (interactable.attachedToHand == null && startingGrabType != IF_VR_Steam_GrabTypes.None) { initialMappingOffset = linearMapping.value - CalculateLinearMapping(hand.transform); sampleCount = 0; mappingChangeRate = 0.0f; hand.AttachObject(gameObject, startingGrabType, attachmentFlags); } }
public virtual void GetReleaseVelocities(IF_VR_Steam_Hand hand, out Vector3 velocity, out Vector3 angularVelocity) { if (hand.noSteamVRFallbackCamera && releaseVelocityStyle != ReleaseStyle.NoChange) { releaseVelocityStyle = ReleaseStyle.ShortEstimation; // only type that works with fallback hand is short estimation. } switch (releaseVelocityStyle) { case ReleaseStyle.ShortEstimation: if (velocityEstimator != null) { velocityEstimator.FinishEstimatingVelocity(); velocity = velocityEstimator.GetVelocityEstimate(); angularVelocity = velocityEstimator.GetAngularVelocityEstimate(); } else { Debug.LogWarning("[SteamVR Interaction System] Throwable: No Velocity Estimator component on object but release style set to short estimation. Please add one or change the release style."); velocity = rigidbody.velocity; angularVelocity = rigidbody.angularVelocity; } break; case ReleaseStyle.AdvancedEstimation: hand.GetEstimatedPeakVelocities(out velocity, out angularVelocity); break; case ReleaseStyle.GetFromHand: velocity = hand.GetTrackedObjectVelocity(releaseVelocityTimeOffset); angularVelocity = hand.GetTrackedObjectAngularVelocity(releaseVelocityTimeOffset); break; default: case ReleaseStyle.NoChange: velocity = rigidbody.velocity; angularVelocity = rigidbody.angularVelocity; break; } if (releaseVelocityStyle != ReleaseStyle.NoChange) { float scaleFactor = 1.0f; if (scaleReleaseVelocityThreshold > 0) { scaleFactor = Mathf.Clamp01(scaleReleaseVelocityCurve.Evaluate(velocity.magnitude / scaleReleaseVelocityThreshold)); } velocity *= (scaleFactor * scaleReleaseVelocity); } }
private void Start() { hand = GetComponent <IF_VR_Steam_Hand>(); //spawn hand collider and link it to us handCollider = ((GameObject)Instantiate(handColliderPrefab.gameObject)).GetComponent <IF_VR_Steam_HandCollider>(); Vector3 localPosition = handCollider.transform.localPosition; Quaternion localRotation = handCollider.transform.localRotation; handCollider.transform.parent = IF_VR_Steam_Player.instance.transform; handCollider.transform.localPosition = localPosition; handCollider.transform.localRotation = localRotation; handCollider.hand = this; }
//------------------------------------------------- private void PhysicsAttach( IF_VR_Steam_Hand hand, IF_VR_Steam_GrabTypes startingGrabType ) { PhysicsDetach( hand ); Rigidbody holdingBody = null; Vector3 holdingPoint = Vector3.zero; // The hand should grab onto the nearest rigid body float closestDistance = float.MaxValue; for ( int i = 0; i < rigidBodies.Count; i++ ) { float distance = Vector3.Distance( rigidBodies[i].worldCenterOfMass, hand.transform.position ); if ( distance < closestDistance ) { holdingBody = rigidBodies[i]; closestDistance = distance; } } // Couldn't grab onto a body if ( holdingBody == null ) return; // Create a fixed joint from the hand to the holding body if ( attachMode == AttachMode.FixedJoint ) { Rigidbody handRigidbody = IF_VR_Steam_Util.FindOrAddComponent<Rigidbody>( hand.gameObject ); handRigidbody.isKinematic = true; FixedJoint handJoint = hand.gameObject.AddComponent<FixedJoint>(); handJoint.connectedBody = holdingBody; } // Don't let the hand interact with other things while it's holding us hand.HoverLock( null ); // Affix this point Vector3 offset = hand.transform.position - holdingBody.worldCenterOfMass; offset = Mathf.Min( offset.magnitude, 1.0f ) * offset.normalized; holdingPoint = holdingBody.transform.InverseTransformPoint( holdingBody.worldCenterOfMass + offset ); hand.AttachObject( this.gameObject, startingGrabType, attachmentFlags ); // Update holding list holdingHands.Add( hand ); holdingBodies.Add( holdingBody ); holdingPoints.Add( holdingPoint ); }
private IF_VR_Steam_InteractableDebug CreateSimulation(IF_VR_Steam_Hand fromHand, float timeOffset, Color copyColor) { GameObject copy = GameObject.Instantiate(this.gameObject); IF_VR_Steam_InteractableDebug debugCopy = copy.GetComponent <IF_VR_Steam_InteractableDebug>(); debugCopy.SetIsSimulation(); debugCopy.ColorSelf(copyColor); copy.name = string.Format("{0} [offset: {1:0.000}]", copy.name, timeOffset); Vector3 velocity = fromHand.GetTrackedObjectVelocity(timeOffset); velocity *= throwable.scaleReleaseVelocity; debugCopy.rigidbody.velocity = velocity; return(debugCopy); }
//------------------------------------------------- public void SpawnAndAttach(IF_VR_Steam_Hand passedInhand) { IF_VR_Steam_Hand handToUse = passedInhand; if (passedInhand == null) { handToUse = hand; } if (handToUse == null) { return; } GameObject prefabObject = Instantiate(prefab) as GameObject; handToUse.AttachObject(prefabObject, IF_VR_Steam_GrabTypes.Scripted); }
//------------------------------------------------- protected virtual void OnDetachedFromHand(IF_VR_Steam_Hand hand) { attached = false; onDetachFromHand.Invoke(); hand.HoverUnlock(null); rigidbody.interpolation = hadInterpolation; Vector3 velocity; Vector3 angularVelocity; GetReleaseVelocities(hand, out velocity, out angularVelocity); rigidbody.velocity = velocity; rigidbody.angularVelocity = angularVelocity; }
/// <summary> /// Called when a IF_VR_Steam_Hand stops hovering over this object /// </summary> protected virtual void OnHandHoverEnd(IF_VR_Steam_Hand hand) { wasHovering = isHovering; hoveringHands.Remove(hand); if (hoveringHands.Count == 0) { isHovering = false; if (highlightOnHover && highlightHolder != null) { Destroy(highlightHolder); } } onHandHoverEnd?.Invoke(this, hand); }
protected virtual void OnAttachedToHand(IF_VR_Steam_Hand hand) { if (activateActionSetOnAttach != null) { activateActionSetOnAttach.Activate(hand.handType); } if (onAttachedToHand != null) { onAttachedToHand.Invoke(hand); } if (skeletonPoser != null && hand.skeleton != null) { hand.skeleton.BlendToPoser(skeletonPoser, blendToPoseTime); } attachedToHand = hand; }