Пример #1
0
 //-------------------------------------------------
 private void RemoveMatchingItemsFromHandStack(VRTRIXGloveItemPackage package, VRTRIXGloveGrab hand)
 {
     for (int i = 0; i < hand.AttachedObjects.Count; i++)
     {
         VRTRIXGloveItemPacakgeReference packageReference = hand.AttachedObjects[i].attachedObject.GetComponent <VRTRIXGloveItemPacakgeReference>();
         if (packageReference != null)
         {
             VRTRIXGloveItemPackage attachedObjectItemPackage = packageReference.itemPackage;
             if ((attachedObjectItemPackage != null) && (attachedObjectItemPackage == package))
             {
                 GameObject detachedItem = hand.AttachedObjects[i].attachedObject;
                 hand.DetachObject(detachedItem);
             }
         }
     }
 }
Пример #2
0
        //-------------------------------------------------
        private VRTRIXGloveItemPackage GetAttachedItemPackage(VRTRIXGloveGrab hand)
        {
            GameObject currentAttachedObject = hand.currentAttachedObject;

            if (currentAttachedObject == null) // verify the hand is holding something
            {
                return(null);
            }

            VRTRIXGloveItemPacakgeReference packageReference = hand.currentAttachedObject.GetComponent <VRTRIXGloveItemPacakgeReference>();

            if (packageReference == null) // verify the item in the hand is matchable
            {
                return(null);
            }

            VRTRIXGloveItemPackage attachedItemPackage = packageReference.itemPackage; // return the ItemPackage reference we find.

            return(attachedItemPackage);
        }
Пример #3
0
        //-------------------------------------------------
        private void OnHandHoverBegin(VRTRIXGloveGrab hand)
        {
            VRTRIXGloveItemPackage currentAttachedItemPackage = GetAttachedItemPackage(hand);

            if (currentAttachedItemPackage == itemPackage)        // the item at the top of the hand's stack has an associated ItemPackage
            {
                if (takeBackItem && !requireTriggerPressToReturn) // if we want to take back matching items and aren't waiting for a trigger press
                {
                    TakeBackItem(hand);
                }
            }

            if (!requireTriggerPressToTake) // we don't require trigger press for pickup. Spawn and attach object.
            {
                SpawnAndAttachObject(hand);
            }

            //if (requireTriggerPressToTake && showTriggerHint)
            //{
            //    ControllerButtonHints.ShowTextHint(hand, Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger, "PickUp");
            //}
        }
Пример #4
0
        //-------------------------------------------------
        private void SpawnAndAttachObject(VRTRIXGloveGrab hand)
        {
            if (hand.otherHand != null)
            {
                //If the other hand has this item package, take it back from the other hand
                VRTRIXGloveItemPackage otherHandItemPackage = GetAttachedItemPackage(hand.otherHand);
                if (otherHandItemPackage == itemPackage)
                {
                    TakeBackItem(hand.otherHand);
                }
            }

            //if (showTriggerHint)
            //{
            //    ControllerButtonHints.HideTextHint(hand, Valve.VR.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 == VRTRIXGloveItemPackage.ItemPackageType.OneHanded)
            {
                RemoveMatchingItemTypesFromHand(VRTRIXGloveItemPackage.ItemPackageType.OneHanded, hand);
                RemoveMatchingItemTypesFromHand(VRTRIXGloveItemPackage.ItemPackageType.TwoHanded, hand);
                RemoveMatchingItemTypesFromHand(VRTRIXGloveItemPackage.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 == VRTRIXGloveItemPackage.ItemPackageType.TwoHanded)
            {
                RemoveMatchingItemTypesFromHand(VRTRIXGloveItemPackage.ItemPackageType.OneHanded, hand);
                RemoveMatchingItemTypesFromHand(VRTRIXGloveItemPackage.ItemPackageType.OneHanded, hand.otherHand);
                RemoveMatchingItemTypesFromHand(VRTRIXGloveItemPackage.ItemPackageType.TwoHanded, hand);
                RemoveMatchingItemTypesFromHand(VRTRIXGloveItemPackage.ItemPackageType.TwoHanded, hand.otherHand);
            }

            spawnedItem = GameObject.Instantiate(itemPackage.itemPrefab);
            spawnedItem.SetActive(true);
            Debug.Log("attachmentPoint: " + attachmentPoint);
            hand.AttachLongBow(spawnedItem, attachmentFlags, attachmentPoint);

            //if ((itemPackage.otherHandItemPrefab != null) && (hand.otherHand.controller != null))
            if ((itemPackage.otherHandItemPrefab != null))
            {
                Debug.Log("Other Hand Prefab not NULL");
                GameObject otherHandObjectToAttach = GameObject.Instantiate(itemPackage.otherHandItemPrefab);
                otherHandObjectToAttach.SetActive(true);
                hand.otherHand.AttachLongBow(otherHandObjectToAttach, attachmentFlags, attachmentPoint);
            }

            itemIsSpawned = true;

            justPickedUpItem = true;

            if (takeBackItem)
            {
                useFadedPreview = true;
                pickupEvent.Invoke();
                CreatePreviewObject();
            }
        }