public override void PutItemIn(ItemBase iItemType, CharacterItemController iPlayerInfo) { base.PutItemIn(iItemType, iPlayerInfo); if (itemOne == null) { itemOne = iItemType; itemOne.transform.parent = this.transform; itemOne.transform.position = itemOnAnilPosition.transform.position; itemOne.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll; iPlayerInfo.RemoveItem(); } else if (itemOne.WhatItemTierAmI == ItemTiers.TIER2 && iItemType.WhatItemTierAmI == ItemTiers.TIER2) { Recipe tRecipeToMake = RecipeHolder.Instance.ReturnRecipeFromItem(itemOne, iItemType); if (tRecipeToMake != null) { _isSomeoneInteracting = true; CreateRecipe(tRecipeToMake); iPlayerInfo.RemoveItem(); Destroy(itemOne.gameObject); Destroy(iItemType.gameObject); ClearAnvilItem(); ItemBase tItemBase = CollectHandout().GetComponentInChildren <ItemBase>(); #if UNITY_EDITOR Debug.Log(tItemBase); #endif iPlayerInfo.PickItemUp(tItemBase); } } }
// Use this for initialization public void Initialize() { character = GetComponentInParent <Character>(); CreateSlot(); itemStored = ItemManager.instance.GetItemReference(itemPrefab.GetComponent <ItemBase>().itemProperties.itemDescription.GetItemType()); itemStored.GetComponent <ItemBase>().isFromEnemy = true; for (int i = 0; i < slots.Count; i++) { slots[i].maxStorage = 10; slots[i].imageSlotPrefab.transform.SetParent(transform); } //adding the item once is enough //Add(); //Adding items to inventory for (int i = 0; i < maxItem; i++) { Add(); } //GameObject temp = Instantiate(itemPrefab, GetComponentInParent<Character>().Hand.transform.position, Quaternion.identity) as GameObject; //itemStored = temp.GetComponent<ItemBase>(); SetActiveItem(); }
private IEnumerator PlayPickUpAnimation(ItemBase item) { item.transform.parent = transform; item.transform.localPosition = Vector3.zero + new Vector3(0, 3.0f, 0); item.GetComponent <SpriteRenderer>().sortingLayerName = "Player"; item.GetComponent <SpriteRenderer>().sortingOrder = 10; Animator.Play("PickUpItem"); _headObject.SetHeadDirection(PlayerHeadController.HeadDirection.Down); DisableCharacter(); yield return(new WaitForSeconds(1f)); EnableCharacter(); _headObject.SetHeadDirection(PlayerHeadController.HeadDirection.Down); item.Disable(); yield return(null); }
public void DropItem() { Debug.Log("Drop item"); //TODO add functionality to drop the item if (itemIAmHolding == null) { return; } itemIAmHolding.transform.parent = null; itemIAmHolding.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.None; itemIAmHolding = null; amIHoldingAnItem = false; }
public void PickItemUp(ItemBase iItem) { //TODO make a functionality to hold the item Debug.Log("Pick item up"); itemIAmHolding = iItem; #if UNITY_EDITOR Debug.Log(iItem); #endif itemIAmHolding.transform.position = transform.position; itemIAmHolding.transform.parent = this.transform; Rigidbody tRigidbody = itemIAmHolding.GetComponent <Rigidbody>(); tRigidbody.constraints = RigidbodyConstraints.FreezeAll; amIHoldingAnItem = true; }
public static ItemBase GetItemFromPool(ItemProperties properties = null, bool createObjectIfPoolIsEmpty = false) { Debug.Log("Getting item from item pool"); if (itemsPool.Count == 0) { if (createObjectIfPoolIsEmpty) { ItemBase item = ItemManager.GenerateItemTemplate(); item.gameObject.SetActive(true); item.GetComponent <SpriteRenderer>().sprite = properties.imageSprite; if (properties != null) { item.itemProperties = properties; } return(item); } return(null); } else { ItemBase item = itemsPool[0]; //Item must be removed from the pool itemsPool.RemoveAt(0); //Automatically activate the item when retrieving from the pool item.gameObject.SetActive(true); //itemsPool[0].GetComponent<SpriteRenderer>().sprite = properties.imageSprite; item.GetComponent <SpriteRenderer>().sprite = properties.imageSprite; if (properties != null) { item.itemProperties = properties; } return(item); } }
void ItemPickedUp(ItemBase item) { ItemsDescription des = item.GetComponent <ItemsDescription>(); if (des == null) { return; } //Check if the item is already present in the journal bool present = IsItemPresentInTheJournal(des); //Add the item if not. if (!present) { Debug.Log("Item is not present in the journal.....Attempting to add it"); AddItem(des); AddItemDetails(des); } else { Debug.Log("Item is already present in the journal....No need to add again"); } }
public virtual void AddItem(ItemBase l_ItemBase) { bool assigned = false; if (l_ItemBase.itemProperties.isAnInventoryItem) { for (int i = 0; i < activeSlotCount; i++) { Debug.Log("active slot count: " + activeSlotCount); Debug.Log("slot is:.................................................." + slots.Count); if (slots[i].itemStored != null) { Debug.Log("adding?"); if (slots[i].itemStored.itemProperties == l_ItemBase.itemProperties) { if (slots[i].itemStored.itemProperties.itemDescription.itemType == l_ItemBase.itemProperties.itemDescription.itemType && slots[i].itemStored.itemProperties.itemDescription.hasPH == l_ItemBase.itemProperties.itemDescription.hasPH && slots[i].itemStored.itemProperties.itemDescription.pHValue == l_ItemBase.itemProperties.itemDescription.pHValue) { Debug.Log("Added to already present slot"); slots[i].AddItem(l_ItemBase); assigned = true; break; } } /* else * { * Debug.Log("Added to already present slot"); * slots[i].AddItem(l_ItemBase); * assigned = true; * break; * }*/ } } Debug.Log("Active Slot Count : " + activeSlotCount); //The purpose of this block is to assign the item for the first time if (activeSlotCount < maxSlotCount && !assigned) { for (int i = activeSlotCount; i < slots.Count; i++) { if (!slots[i].imageSlotPrefab.activeSelf && slots[i].itemStored == null) { Debug.Log("Adding item to slot For first time"); slots[i].AddItem(l_ItemBase); slots[i].imageSlotPrefab.SetActive(true); slots[i].displaySprite.sprite = l_ItemBase.GetComponent <SpriteRenderer>().sprite; // slots[i].itemStored.GetComponent<SpriteRenderer>().enabled = false; slots[i].isActive = true; slots[i].itemStored = l_ItemBase; slots[i].imageSlotPrefab.gameObject.transform.localScale = Vector3.one; activeSlotCount = ActiveSlotCount(); break; } } } else { // Debug.Log("Max Slots reached"); } } else { Debug.Log(l_ItemBase.name + "Is not an Inventory item"); } SetActiveSlotCount(); }