Beispiel #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);
                }
            }
        }
Beispiel #2
0
        //-------------------------------------------------
        private void HandHoverUpdate(Hand hand)
        {
            if (takeBackItem && requireTriggerPressToReturn)
            {
                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 (requireTriggerPressToTake)
            {
                /*
                 * GrabTypes startingGrab = GrabTypes.None;//hand.GetGrabStarting();
                 *
                 * if (startingGrab != GrabTypes.None)
                 * {
                 *      SpawnAndAttachObject( hand);
                 * }
                 */
            }
        }
        //-------------------------------------------------
        private void OnHandHoverBegin(Hand hand)
        {
            AudioSource.PlayClipAtPoint(hoveringSoundClip, transform.position, hoveringVolume);

            ItemPackage currentAttachedItemPackage = GetAttachedItemPackage(hand);

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

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

            if (requireGrabActionToTake && showTriggerHint)
            {
                hand.ShowGrabHint("PickUp");
            }

            /*if (requireGrabActionToTake)
             * {
             *      if (releaseGun.GetStateUp(SteamVR_Input_Sources.Any))
             *      {
             *              Debug.Log("fghjfhjgf");
             *              SpawnAndAttachObject(hand, GrabTypes.Scripted);
             *      }
             * }*/
        }
        //-------------------------------------------------
        private void OnHandHoverBegin(Hand hand)
        {
            ItemPackage 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, EVRButtonId.k_EButton_SteamVR_Trigger, "PickUp");
            }
        }
Beispiel #5
0
 public void OnUsedEnd(Interactor interactor, int useIndex)
 {
     if (takeBackItem && requireReleaseActionToReturn)
     {
         Inventory   inventory = interactor.GetComponentInParent <Inventory>();
         ItemPackage currentAttachedItemPackage = GetAttachedItemPackage(inventory);
         if (currentAttachedItemPackage == itemPackage)
         {
             TakeBackItem(inventory);
             //return; // So that we don't pick up an ItemPackage the same frame that we return it
         }
     }
 }
Beispiel #6
0
 private void SpawnAndAttachObject(Hand hand)
 {
     if (hand.otherHand != null)
     {
         ItemPackage attachedItemPackage = this.GetAttachedItemPackage(hand.otherHand);
         if (attachedItemPackage == this.itemPackage)
         {
             this.TakeBackItem(hand.otherHand);
         }
     }
     if (this.showTriggerHint)
     {
         ControllerButtonHints.HideTextHint(hand, EVRButtonId.k_EButton_Axis1);
     }
     if (this.itemPackage.otherHandItemPrefab != null && hand.otherHand.hoverLocked)
     {
         return;
     }
     if (this.itemPackage.packageType == ItemPackage.ItemPackageType.OneHanded)
     {
         this.RemoveMatchingItemTypesFromHand(ItemPackage.ItemPackageType.OneHanded, hand);
         this.RemoveMatchingItemTypesFromHand(ItemPackage.ItemPackageType.TwoHanded, hand);
         this.RemoveMatchingItemTypesFromHand(ItemPackage.ItemPackageType.TwoHanded, hand.otherHand);
     }
     if (this.itemPackage.packageType == ItemPackage.ItemPackageType.TwoHanded)
     {
         this.RemoveMatchingItemTypesFromHand(ItemPackage.ItemPackageType.OneHanded, hand);
         this.RemoveMatchingItemTypesFromHand(ItemPackage.ItemPackageType.OneHanded, hand.otherHand);
         this.RemoveMatchingItemTypesFromHand(ItemPackage.ItemPackageType.TwoHanded, hand);
         this.RemoveMatchingItemTypesFromHand(ItemPackage.ItemPackageType.TwoHanded, hand.otherHand);
     }
     this.spawnedItem = UnityEngine.Object.Instantiate <GameObject>(this.itemPackage.itemPrefab);
     this.spawnedItem.SetActive(true);
     hand.AttachObject(this.spawnedItem, this.attachmentFlags, this.attachmentPoint);
     if (this.itemPackage.otherHandItemPrefab != null && hand.otherHand.controller != null)
     {
         GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(this.itemPackage.otherHandItemPrefab);
         gameObject.SetActive(true);
         hand.otherHand.AttachObject(gameObject, this.attachmentFlags, string.Empty);
     }
     this.itemIsSpawned    = true;
     this.justPickedUpItem = true;
     if (this.takeBackItem)
     {
         this.useFadedPreview = true;
         this.pickupEvent.Invoke();
         this.CreatePreviewObject();
     }
 }
Beispiel #7
0
 private void RemoveMatchingItemsFromHandStack(ItemPackage package, Hand hand)
 {
     for (int i = 0; i < hand.AttachedObjects.Count; i++)
     {
         ItemPackageReference component = hand.AttachedObjects[i].attachedObject.GetComponent <ItemPackageReference>();
         if (component != null)
         {
             ItemPackage itemPackage = component.itemPackage;
             if (itemPackage != null && itemPackage == package)
             {
                 GameObject attachedObject = hand.AttachedObjects[i].attachedObject;
                 hand.DetachObject(attachedObject, true);
             }
         }
     }
 }
Beispiel #8
0
 private void HandHoverUpdate(Hand hand)
 {
     if (this.takeBackItem && this.requireTriggerPressToReturn && hand.controller != null && hand.controller.GetHairTriggerDown())
     {
         ItemPackage attachedItemPackage = this.GetAttachedItemPackage(hand);
         if (attachedItemPackage == this.itemPackage)
         {
             this.TakeBackItem(hand);
             return;
         }
     }
     if (this.requireTriggerPressToTake && hand.controller != null && hand.controller.GetHairTriggerDown())
     {
         this.SpawnAndAttachObject(hand);
     }
 }
Beispiel #9
0
 //-------------------------------------------------
 private void RemoveMatchingItemsFromHandStack(ItemPackage package, Hand hand)
 {
     for (int i = 0; i < hand.AttachedObjects.Count; i++)
     {
         ItemPackageReference packageReference = hand.AttachedObjects[i].attachedObject.GetComponent <ItemPackageReference>();
         if (packageReference != null)
         {
             ItemPackage attachedObjectItemPackage = packageReference.itemPackage;
             if ((attachedObjectItemPackage != null) && (attachedObjectItemPackage == package))
             {
                 GameObject detachedItem = hand.AttachedObjects[i].attachedObject;
                 hand.DetachObject(detachedItem);
             }
         }
     }
 }
Beispiel #10
0
        private void OnHandHoverBegin(Hand hand)
        {
            ItemPackage attachedItemPackage = this.GetAttachedItemPackage(hand);

            if (attachedItemPackage == this.itemPackage && this.takeBackItem && !this.requireTriggerPressToReturn)
            {
                this.TakeBackItem(hand);
            }
            if (!this.requireTriggerPressToTake)
            {
                this.SpawnAndAttachObject(hand);
            }
            if (this.requireTriggerPressToTake && this.showTriggerHint)
            {
                ControllerButtonHints.ShowTextHint(hand, EVRButtonId.k_EButton_Axis1, "PickUp", true);
            }
        }
Beispiel #11
0
        //-------------------------------------------------
        // private void HandHoverUpdate( Hand hand )
        // {
        //  if ( takeBackItem && requireReleaseActionToReturn )
        //  {
        //         if (hand.isActive)
        //      {
        //          ItemPackage currentAttachedItemPackage = GetAttachedItemPackage( hand );
        //             if (currentAttachedItemPackage == itemPackage &&

        //              // hand.IsGrabEnding(currentAttachedItemPackage.gameObject)
        //              hand.GetGrabUp()
        //          )
        //          {
        //              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)
        //      if (hand.GetGrabDown())
        //      {
        //          SpawnAndAttachObject( hand);//, GrabTypes.Scripted);
        //      }
        //  }
        // }


        //-------------------------------------------------
        // private void OnHandHoverEnd( Hand hand )
        // {
        //  // if ( !justPickedUpItem && requireGrabActionToTake && showTriggerHint )
        //  // {
        //     //     hand.HideGrabHint();
        //  // }

        //  justPickedUpItem = false;
        // }


        //-------------------------------------------------
        // private void RemoveMatchingItemsFromHandStack( ItemPackage package, Hand hand )
        // {
        //     if (hand == null)
        //         return;

        //  if (hand.currentAttached == null)
        //      return;


        //  // if (!hand.hasCurrentAttached)
        //  //  return;

        //  // for ( int i = 0; i < hand.AttachedObjects.Count; i++ )
        //  // {
        //      // ItemPackageReference packageReference = hand.AttachedObjects[i].attachedObject.GetComponent<ItemPackageReference>();
        //      ItemPackageReference packageReference = hand.currentAttached.attachedObject.GetComponent<ItemPackageReference>();

        //      if ( packageReference != null )
        //      {
        //          ItemPackage attachedObjectItemPackage = packageReference.itemPackage;
        //          if ( ( attachedObjectItemPackage != null ) && ( attachedObjectItemPackage == package ) )
        //          {
        //              // GameObject detachedItem = hand.AttachedObjects[i].attachedObject;
        //              GameObject detachedItem = hand.currentAttached.attachedObject;

        //              hand.DetachObject( detachedItem );
        //          }
        //      }
        //  // }
        // }

        private void RemoveMatchingItemsFromHandStack(ItemPackage package, Inventory inventory)
        {
            for (int i = 0; i < inventory.equippedSlots.Length; i++)
            {
                if (inventory.equippedSlots[i] != null)
                {
                    ItemPackageReference packageReference = inventory.equippedSlots[i].sceneItem.GetComponent <ItemPackageReference>();
                    if (packageReference != null)
                    {
                        ItemPackage attachedObjectItemPackage = packageReference.itemPackage;
                        if ((attachedObjectItemPackage != null) && (attachedObjectItemPackage == package))
                        {
                            inventory.UnequipItem(i, false);
                        }
                    }
                }
            }



            // if (inventory.equippedItem == null)
            //  return;


            // // if (!hand.hasCurrentAttached)
            // //   return;

            // // for ( int i = 0; i < hand.AttachedObjects.Count; i++ )
            // // {
            //  // ItemPackageReference packageReference = hand.AttachedObjects[i].attachedObject.GetComponent<ItemPackageReference>();
            //  ItemPackageReference packageReference = inventory.equippedItem.item.GetComponent<ItemPackageReference>();

            //  if ( packageReference != null )
            //  {
            //      ItemPackage attachedObjectItemPackage = packageReference.itemPackage;
            //      if ( ( attachedObjectItemPackage != null ) && ( attachedObjectItemPackage == package ) )
            //      {
            //          // GameObject detachedItem = hand.AttachedObjects[i].attachedObject;
            //          // GameObject detachedItem = inventory.equippedItem.attachedObject;

            //          inventory.UnequipItem( inventory.equippedItem.item );
            //      }
            //  }
            // // }
        }
Beispiel #12
0
        public void OnInspectedStart(Interactor interactor)
        {
            Inventory   inventory = interactor.GetComponentInParent <Inventory>();
            ItemPackage currentAttachedItemPackage = GetAttachedItemPackage(inventory);

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

            if (!requireGrabActionToTake)                                 // we don't require trigger press for pickup. Spawn and attach object.
            {
                SpawnAndAttachObject(inventory, interactor.interactorID); //, GrabTypes.Scripted );
            }
        }
Beispiel #13
0
        //-------------------------------------------------
        private ItemPackage GetAttachedItemPackage(Hand hand)
        {
            GameObject currentAttachedObject = hand.currentAttachedObject;

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

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

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

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

            return(attachedItemPackage);
        }
Beispiel #14
0
        // private void TakeBackItem( Hand hand )
        // {
        //  RemoveMatchingItemsFromHandStack( itemPackage, hand );

        //  if ( itemPackage.packageType == ItemPackage.ItemPackageType.TwoHanded )
        //  {
        //      RemoveMatchingItemsFromHandStack( itemPackage, hand.otherHand );
        //  }
        // }


        //-------------------------------------------------
        // private ItemPackage GetAttachedItemPackage( Hand hand )
        // {
        //  // GameObject currentAttachedObject = hand.currentAttachedObject;

        //  // if ( currentAttachedObject == null ) // verify the hand is holding something
        //  // if (!hand.hasCurrentAttached)
        //  if (hand.currentAttached == null)
        //  {
        //      return null;
        //  }
        //  GameObject currentAttachedObject = hand.currentAttached.attachedObject;

        //  ItemPackageReference packageReference = currentAttachedObject.GetComponent<ItemPackageReference>();
        //  if ( packageReference == null ) // verify the item in the hand is matchable
        //  {
        //      return null;
        //  }

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

        //  return attachedItemPackage;
        // }
        private ItemPackage GetAttachedItemPackage(Inventory inventory)
        {
            for (int i = 0; i < inventory.equippedSlots.Length; i++)
            {
                if (inventory.equippedSlots[i] != null)
                {
                    ItemPackageReference packageReference = inventory.equippedSlots[i].sceneItem.GetComponent <ItemPackageReference>();
                    if (packageReference == null)                       // verify the item in the hand is matchable
                    {
                        continue;
                        // return null;
                    }

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

                    return(attachedItemPackage);
                }
            }
            return(null);


            // // GameObject currentAttachedObject = hand.currentAttachedObject;

            // // if ( currentAttachedObject == null ) // verify the hand is holding something
            // // if (!hand.hasCurrentAttached)
            // if (inventory.equippedItem == null)
            // {
            //  return null;
            // }
            // GameObject currentAttachedObject = inventory.equippedItem.item.gameObject;

            // ItemPackageReference packageReference = currentAttachedObject.GetComponent<ItemPackageReference>();
            // if ( packageReference == null ) // verify the item in the hand is matchable
            // {
            //  return null;
            // }

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

            // return attachedItemPackage;
        }
Beispiel #15
0
        //-------------------------------------------------
        private void OnHandHoverBegin(Hand hand)
        {
            ItemPackage currentAttachedItemPackage = GetAttachedItemPackage(hand);

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

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

            if (requireGrabActionToTake && showTriggerHint)
            {
                // hand.ShowGrabHint("PickUp");
            }
        }
Beispiel #16
0
        //-------------------------------------------------
        private void OnHandHoverBegin(Hand hand)
        {
            ItemPackage 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)
            {
                Player.instance.input_manager.ShowGrabHint(hand, "PickUp");
            }
        }
Beispiel #17
0
        //-------------------------------------------------
        private void HandHoverUpdate(Hand hand)
        {
            if (takeBackItem && requireTriggerPressToReturn)
            {
                if (hand.controller != null && hand.controller.GetHairTriggerDown())
                {
                    ItemPackage currentAttachedItemPackage = GetAttachedItemPackage(hand);
                    if (currentAttachedItemPackage == itemPackage)
                    {
                        TakeBackItem(hand);
                        return;                         // So that we don't pick up an ItemPackage the same frame that we return it
                    }
                }
            }

            if (requireTriggerPressToTake)
            {
                if (hand.controller != null && hand.controller.GetHairTriggerDown())
                {
                    SpawnAndAttachObject(hand);
                }
            }
        }
        //-------------------------------------------------
        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 = Instantiate(itemPackage.itemPrefab);
            spawnedItem.SetActive(true);
            hand.AttachObject(spawnedItem, attachmentFlags, attachmentPoint);

            if ((itemPackage.otherHandItemPrefab != null) && (hand.otherHand.controller != null))
            {
                GameObject otherHandObjectToAttach = Instantiate(itemPackage.otherHandItemPrefab);
                otherHandObjectToAttach.SetActive(true);
                hand.otherHand.AttachObject(otherHandObjectToAttach, attachmentFlags);
            }

            itemIsSpawned = true;

            justPickedUpItem = true;

            if (takeBackItem)
            {
                useFadedPreview = true;
                pickupEvent.Invoke();
                CreatePreviewObject();
            }
        }
Beispiel #19
0
        //-------------------------------------------------
        // private void SpawnAndAttachObject( Hand hand)//, GrabTypes grabType )
        private void SpawnAndAttachObject(Inventory inventory, int interactorID)         //, GrabTypes grabType )

        {
            // if ( hand.otherHand != null )

            // {
            //If the other hand has this item package, take it back from the other hand

            // Inventory otherInventory = inventory.otherInventory;
            ItemPackage otherHandItemPackage = GetAttachedItemPackage(inventory);                     // otherInventory );//hand.otherHand );

            if (otherHandItemPackage == itemPackage)
            {
                TakeBackItem(inventory);                         // otherInventory) ;//hand.otherHand );
            }
            // }

            // if ( showTriggerHint )
            // {
            //     hand.HideGrabHint();
            // }

            // if ( itemPackage.otherHandItemPrefab != null )
            // {

            //  if (otherInventory.GetComponent<Interactor>().hoverLocked)
            //  // if ( hand.otherHand.hoverLocked )
            //  {
            //         Debug.Log( "<b>[SteamVR Interaction]</b> 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, inventory);                 //hand );
                RemoveMatchingItemTypesFromHand(ItemPackage.ItemPackageType.TwoHanded, inventory);                 //hand );
                // RemoveMatchingItemTypesFromHand( ItemPackage.ItemPackageType.TwoHanded, otherInventory);//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, inventory);                 //hand );
                // RemoveMatchingItemTypesFromHand( ItemPackage.ItemPackageType.OneHanded, otherInventory);//hand.otherHand );
                RemoveMatchingItemTypesFromHand(ItemPackage.ItemPackageType.TwoHanded, inventory);                 //hand );
                // RemoveMatchingItemTypesFromHand( ItemPackage.ItemPackageType.TwoHanded, otherInventory);//hand.otherHand );
            }

            spawnedItem = GameObject.Instantiate(itemPackage.itemPrefab);
            spawnedItem.SetActive(true);



            //dont quick equip
            Item sceneItem = spawnedItem.GetComponent <Item>();

            inventory.EquipItem(sceneItem.itemBehavior, interactorID, null);            // sceneItem.itemBehavior.equipSlot, null);
            // inventory.SwitchMainUsedEquipPoint();


            // inventory.EquipItem( spawnedItem.GetComponent<Item>()//,
            //  // grabType,
            //  // attachmentFlags
            //  );

            if ((itemPackage.otherHandItemPrefab != null))                // && ( hand.otherHand.isActive ) )
            {
                GameObject otherHandObjectToAttach = GameObject.Instantiate(itemPackage.otherHandItemPrefab);
                otherHandObjectToAttach.SetActive(true);

                // otherInventory.EquipItem(otherHandObjectToAttach.GetComponent<Item>());


                sceneItem = otherHandObjectToAttach.GetComponent <Item>();
                //dont quick equip
                // otherInventory.
                inventory.EquipItem(sceneItem.itemBehavior, 1 - interactorID, null);              //sceneItem.itemBehavior.equipSlot, null);
            }

            itemIsSpawned = true;

            justPickedUpItem = true;

            if (takeBackItem)
            {
                useFadedPreview = true;
                pickupEvent.Invoke();
                CreatePreviewObject();
            }
        }
Beispiel #20
0
        //-------------------------------------------------
        private void SpawnAndAttachObject(Hand hand, GrabTypes grabType)
        {
            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)
            {
                hand.HideGrabHint();
            }

            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, grabType, attachmentFlags);

            if ((itemPackage.otherHandItemPrefab != null) && (hand.otherHand.isActive))
            {
                GameObject otherHandObjectToAttach = GameObject.Instantiate(itemPackage.otherHandItemPrefab);
                otherHandObjectToAttach.SetActive(true);
                hand.otherHand.AttachObject(otherHandObjectToAttach, grabType, attachmentFlags);
            }

            itemIsSpawned = true;

            justPickedUpItem = true;

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

            //Destroy the object on pickup
            Destroy(this.gameObject);
            Destroy(GameObject.Find("Highlighter"));
        }