示例#1
0
        //-------------------------------------------------
        public void SpawnAndAttach(Hand passedInhand)
        {
            Hand handToUse = passedInhand;

            if (passedInhand == null)
            {
                handToUse = hand;
            }

            if (handToUse == null)
            {
                return;
            }

            GameObject prefabObject = Instantiate(prefab) as GameObject;

            handToUse.AttachGameObject(prefabObject);             //, GrabTypes.Scripted );
        }
示例#2
0
        //-------------------------------------------------
        void Update()
        {
            if (itemPrefab != null)
            {
                if (hand.isActive && hand.isPoseValid)
                {
                    GameObject objectToAttach = GameObject.Instantiate(itemPrefab);
                    objectToAttach.SetActive(true);
                    hand.AttachGameObject(objectToAttach);
                    Player.instance.input_manager.TriggerHapticPulse(hand, 800);

                    Destroy(gameObject);

                    // If the player's scale has been changed the object to attach will be the wrong size.
                    // To fix this we change the object's scale back to its original, pre-attach scale.
                    objectToAttach.transform.localScale = itemPrefab.transform.localScale;
                }
            }
        }
示例#3
0
        //-------------------------------------------------
        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)
            {
                Player.instance.input_manager.HideGrabHint(hand);
            }

            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.AttachGameObject(spawnedItem, attachmentFlags);

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

            itemIsSpawned = true;

            justPickedUpItem = true;

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