//------------------------------------------------- private void OnHandHoverEnd(Hand hand) { ControllerButtonHints.HideButtonHint(hand, EVRButtonId.k_EButton_SteamVR_Trigger); }
//------------------------------------------------- private void OnHandFocusLost(Hand hand) { gameObject.SetActive(false); velocityEstimator.FinishEstimatingVelocity(); }
//------------------------------------------------- private void OnHandFocusAcquired(Hand hand) { gameObject.SetActive(true); velocityEstimator.BeginEstimatingVelocity(); }
//------------------------------------------------- private IEnumerator LateDetach(Hand hand) { yield return(new WaitForEndOfFrame()); hand.DetachObject(gameObject, restoreOriginalParent); }
//------------------------------------------------- private void SpawnAndAttachObject(Hand hand) { if (hand.otherHand != null) { //If the other hand has this item package, take it back from the other hand ItemPackage otherHandItemPackage = GetAttachedItemPackage(hand.otherHand); if (otherHandItemPackage == itemPackage) { TakeBackItem(hand.otherHand); } } if (showTriggerHint) { ControllerButtonHints.HideTextHint(hand, EVRButtonId.k_EButton_SteamVR_Trigger); } if (itemPackage.otherHandItemPrefab != null) { if (hand.otherHand.hoverLocked) { //Debug.Log( "Not attaching objects because other hand is hoverlocked and we can't deliver both items." ); return; } } // if we're trying to spawn a one-handed item, remove one and two-handed items from this hand and two-handed items from both hands if (itemPackage.packageType == ItemPackage.ItemPackageType.OneHanded) { RemoveMatchingItemTypesFromHand(ItemPackage.ItemPackageType.OneHanded, hand); RemoveMatchingItemTypesFromHand(ItemPackage.ItemPackageType.TwoHanded, hand); RemoveMatchingItemTypesFromHand(ItemPackage.ItemPackageType.TwoHanded, hand.otherHand); } // if we're trying to spawn a two-handed item, remove one and two-handed items from both hands if (itemPackage.packageType == ItemPackage.ItemPackageType.TwoHanded) { RemoveMatchingItemTypesFromHand(ItemPackage.ItemPackageType.OneHanded, hand); RemoveMatchingItemTypesFromHand(ItemPackage.ItemPackageType.OneHanded, hand.otherHand); RemoveMatchingItemTypesFromHand(ItemPackage.ItemPackageType.TwoHanded, hand); RemoveMatchingItemTypesFromHand(ItemPackage.ItemPackageType.TwoHanded, hand.otherHand); } spawnedItem = GameObject.Instantiate(itemPackage.itemPrefab); spawnedItem.SetActive(true); hand.AttachObject(spawnedItem, attachmentFlags, attachmentPoint); if ((itemPackage.otherHandItemPrefab != null) && (hand.otherHand.controller != null)) { GameObject otherHandObjectToAttach = GameObject.Instantiate(itemPackage.otherHandItemPrefab); otherHandObjectToAttach.SetActive(true); hand.otherHand.AttachObject(otherHandObjectToAttach, attachmentFlags); } itemIsSpawned = true; justPickedUpItem = true; if (takeBackItem) { useFadedPreview = true; pickupEvent.Invoke(); CreatePreviewObject(); } }
//------------------------------------------------- private void RemoveMatchingItemTypesFromHand(ItemPackage.ItemPackageType packageType, Hand hand) { for (int i = 0; i < hand.AttachedObjects.Count; i++) { ItemPackageReference packageReference = hand.AttachedObjects[i].attachedObject.GetComponent <ItemPackageReference>(); if (packageReference != null) { if (packageReference.itemPackage.packageType == packageType) { GameObject detachedItem = hand.AttachedObjects[i].attachedObject; hand.DetachObject(detachedItem); } } } }