本文整理汇总了C#中Inventory.addItemToInventory方法的典型用法代码示例。如果您正苦于以下问题:C# Inventory.addItemToInventory方法的具体用法?C# Inventory.addItemToInventory怎么用?C# Inventory.addItemToInventory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Inventory
的用法示例。
在下文中一共展示了Inventory.addItemToInventory方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnPointerDown
private bool pressingButtonToSplit; //bool for pressing a item to split it
#endregion Fields
#region Methods
//splitting the item now
public void OnPointerDown(PointerEventData data)
{
inv = transform.parent.parent.parent.GetComponent<Inventory>();
if (transform.parent.parent.parent.GetComponent<Hotbar>() == null && data.button == PointerEventData.InputButton.Left && pressingButtonToSplit && inv.stackable && (inv.ItemsInInventory.Count < (inv.height * inv.width))) //if you press leftclick and and keycode
{
ItemOnObject itemOnObject = GetComponent<ItemOnObject>(); //we take the ItemOnObject script of the item in the slot
if (itemOnObject.item.itemValue > 1) //we split the item only when we have more than 1 in the stack
{
int splitPart = itemOnObject.item.itemValue; //we take the value and store it in there
itemOnObject.item.itemValue = (int)itemOnObject.item.itemValue / 2; //calculate the new value for the splitted item
splitPart = splitPart - itemOnObject.item.itemValue; //take the different
inv.addItemToInventory(itemOnObject.item.itemID, splitPart); //and add a new item to the inventory
inv.stackableSettings();
if (GetComponent<ConsumeItem>().duplication != null)
{
GameObject dup = GetComponent<ConsumeItem>().duplication;
dup.GetComponent<ItemOnObject>().item.itemValue = itemOnObject.item.itemValue;
dup.GetComponent<SplitItem>().inv.stackableSettings();
}
inv.updateItemList();
}
}
}
示例2: OnPointerDown
public void OnPointerDown(PointerEventData data)
{
inv = transform.parent.parent.parent.GetComponent<Inventory>();
if (transform.parent.parent.parent.GetComponent<Hotbar>() == null && data.button == PointerEventData.InputButton.Left && pressingButtonToSplit && inv.stackable && (inv.ItemsInInventory.Count < (inv.height * inv.width)))
{
ItemOnObject itemOnObject = GetComponent<ItemOnObject>();
if (itemOnObject.item.itemValue > 1)
{
int splitPart = itemOnObject.item.itemValue;
itemOnObject.item.itemValue = (int)itemOnObject.item.itemValue / 2;
splitPart = splitPart - itemOnObject.item.itemValue;
inv.addItemToInventory(itemOnObject.item.itemID, splitPart);
inv.stackableSettings();
if (GetComponent<ConsumeItem>().duplication != null)
{
GameObject dup = GetComponent<ConsumeItem>().duplication;
dup.GetComponent<ItemOnObject>().item.itemValue = itemOnObject.item.itemValue;
dup.GetComponent<SplitItem>().inv.stackableSettings();
}
inv.updateItemList();
}
}
}