Container.AddItemMergedItemToContainer C# (CSharp) Method

AddItemMergedItemToContainer() public method

public AddItemMergedItemToContainer ( GameObject item ) : bool
item GameObject
return bool
    public bool AddItemMergedItemToContainer(GameObject item)
    {
        for (int i=0; i<=MaxCapacity (); i++)
        {
            if (items[i]!="")
            {
                GameObject founditem = GameObject.Find (items[i]);
                //if ((founditem.GetComponent<ObjectInteraction>().item_id==item.GetComponent<ObjectInteraction>().item_id) && (founditem.GetComponent<ObjectInteraction>().Quality==item.GetComponent<ObjectInteraction>().Quality))
                if (ObjectInteraction.CanMerge(founditem.GetComponent<ObjectInteraction>(),item.GetComponent<ObjectInteraction>()))
                {
                    //merge
                    //Debug.Log ("Merging");
                    //founditem.GetComponent<ObjectInteraction>().Link =founditem.GetComponent<ObjectInteraction>().Link+ item.GetComponent<ObjectInteraction>().Link;
                    //GameObject.Destroy (item);
                    ObjectInteraction.Merge(founditem.GetComponent<ObjectInteraction>(),item.GetComponent<ObjectInteraction>());
                    return true;
                }
            }
        }
        //otherwise just add in the usual way.
        return AddItemToContainer(item.name);
    }

Usage Example

Exemplo n.º 1
0
 void OnClick()
 {
     if (playerUW.playerInventory.currentContainer == playerUW.name)
     {        //Don't do anything on the top level
         playerUW.playerInventory.ContainerOffset = 0;
         return;
     }
     if (playerUW.playerInventory.ObjectInHand == "")
     {        //Player has no object in their hand. We close up the container.
         ScrollButtonInventory.ScrollValue        = 0;
         playerUW.playerInventory.ContainerOffset = 0;
         Container currentContainerObj = playerUW.playerInventory.GetCurrentContainer();
         playerUW.playerInventory.currentContainer = currentContainerObj.ContainerParent;
         currentContainerObj.isOpenOnPanel         = false;
         //Close child containers as well
         CloseChildContainer(currentContainerObj);
         Container DestinationContainer = playerUW.playerInventory.GetCurrentContainer();
         if (playerUW.playerInventory.currentContainer == "Gronk")
         {
             GetComponent <UITexture>().mainTexture = playerUW.playerInventory.Blank;
         }
         else
         {
             GetComponent <UITexture>().mainTexture = DestinationContainer.transform.GetComponent <ObjectInteraction>().GetInventoryDisplay().texture;
         }
         for (int i = 0; i < 8; i++)
         {
             string sItem = DestinationContainer.GetItemAt(i);
             playerUW.playerInventory.SetObjectAtSlot(i + 11, sItem);
         }
     }
     else
     {
         if (UWCharacter.InteractionMode != UWCharacter.InteractionModePickup)
         {            //Only allow this to happen when in pickup mode.
             return;
         }
         //Move the contents out of the container into the parent.
         Container         CurrentContainer     = GameObject.Find(playerUW.playerInventory.currentContainer).GetComponent <Container>();
         Container         DestinationContainer = GameObject.Find(CurrentContainer.ContainerParent).GetComponent <Container>();
         ObjectInteraction item = GameObject.Find(playerUW.playerInventory.ObjectInHand).GetComponent <ObjectInteraction>();
         if (Container.TestContainerRules(DestinationContainer, 11))
         {
             if ((item.isQuant == false) || (item.isEnchanted))
             {
                 if (DestinationContainer.AddItemToContainer(playerUW.playerInventory.ObjectInHand))
                 {                    //Object has moved
                     playerUW.CursorIcon = playerUW.CursorIconDefault;
                     playerUW.playerInventory.ObjectInHand = "";
                 }
             }
             else
             {
                 if (DestinationContainer.AddItemMergedItemToContainer(item.gameObject))
                 {                    //Object has moved
                     playerUW.CursorIcon = playerUW.CursorIconDefault;
                     playerUW.playerInventory.ObjectInHand = "";
                 }
             }
         }
     }
 }
All Usage Examples Of Container::AddItemMergedItemToContainer