private void PickItemUp() { if (_pickedUp) { return; } // Check how far away the player is from the item var distance = Vector3.Distance(this.transform.position, Camera.main.transform.position); // if we're too far away, don't allow the user to pick the item up if (distance > itemData.maxPickupDistance) { return; } var result = _vrInventory.AddItem(itemData.name, quantity); if (result != VRInventory.ePickUpResult.Success) { // if we weren't able to pick up the item, don't continue return; } // prevent this event from being fired again _pickedUp = true; // Disable item collision (it can get in the way of the camera) var collider = this.GetComponent <Collider>(); if (collider != null) { collider.enabled = false; } // Move the item to the player as a 'pick up' animation var position = Camera.main.transform.position + new Vector3(0, -0.5f, 0); iTween.MoveTo(this.gameObject, iTween.Hash("position", position, "time", 0.35f, "oncomplete", "ItemPickupAnimationComplete", "oncompletetarget", this.gameObject)); var sound = itemData.pickupSound; if (quantity > 1 && itemData.pickupMultipleSound != null) { sound = itemData.pickupMultipleSound; } if (sound != null) { _audioSource.clip = sound; _audioSource.Play(); } }
public override void OnInspectorGUI() { SO_target.Update(); bool forceItemReRender = false; EditorGUI.BeginChangeCheck(); itemDatabase.objectReferenceValue = EditorGUILayout.ObjectField("Item Database", itemDatabase.objectReferenceValue, typeof(InventoryItemDatabase), false); if (itemDatabase.objectReferenceValue == null) { EditorGUILayout.HelpBox("Please select an Inventory Item Database", MessageType.Warning); vrInventoryTarget.items.Clear(); return; } EditorGUILayout.PropertyField(inventoryTriggerMode); if (inventoryTriggerMode.enumValueIndex == (int)VRInventory.eInventoryTriggerMode.InputFire1) { EditorGUILayout.PropertyField(hideWhenItemSelected); } EditorGUI.BeginChangeCheck(); { EditorGUILayout.PropertyField(showInventoryItemsInEditMode); } if (EditorGUI.EndChangeCheck()) { forceItemReRender = true; } EditorGUILayout.Space(); EditorGUILayout.LabelField("Save / Load", EditorStyles.boldLabel); EditorGUILayout.PropertyField(autoSave); if (autoSave.boolValue) { EditorGUILayout.PropertyField(saveSlotName); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.PrefixLabel(" "); if (GUILayout.Button("Clear Save")) { PlayerPrefs.SetString("vrInventory_" + saveSlotName.stringValue, ""); PlayerPrefs.Save(); EditorUtility.DisplayDialog("Success", "Save slot '" + saveSlotName.stringValue + "' cleared.", "Okay"); } } EditorGUILayout.EndHorizontal(); } EditorGUILayout.Space(); var changedItems = RenderItemListEditor(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Events", EditorStyles.boldLabel); EditorGUILayout.PropertyField(onItemSelected); EditorGUILayout.PropertyField(onItemPickedUp); EditorGUILayout.Space(); showReferences = EditorGUI.Foldout(EditorGUILayout.GetControlRect(), showReferences, "UI References", true); if (showReferences) { EditorGUILayout.PropertyField(inventoryUIPrefab); EditorGUILayout.PropertyField(itemTemplate); EditorGUILayout.PropertyField(inventoryPositionTransform); EditorGUILayout.PropertyField(handPosition); } if (EditorGUI.EndChangeCheck()) { SO_target.ApplyModifiedProperties(); if (!Application.isPlaying) { UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(vrInventoryTarget.gameObject.scene); } } if (forceItemReRender) { vrInventoryTarget.ItemsUpdated(); } foreach (var addedItemName in changedItems["added"]) { vrInventoryTarget.AddItem(addedItemName, newItemQuantity); } foreach (var removedItemName in changedItems["removed"]) { vrInventoryTarget.RemoveItem(removedItemName, -1); } }