public void UseItem(IActorPart actor) { operations[0]?.callBack?.Invoke(this, actor.GetBackpack()); if (consumable) { this.number--; if (number <= 0) { actor.GetBackpack().RemoveItem(this); Destroy(this); Destroy(gameObject); } } }
public void SetUp(IActorPart actor) { backpack?.RemoveOnAddItemListener(AddNewItem); backpack?.RemoveOnRemoveItemListener(RemoveItem); backpack = actor.GetBackpack(); panel.Init(this); Start(); backpack.AddOnAddItemListener(AddNewItem); backpack.AddOnRemoveItemListener(RemoveItem); gearUI.SetUp(actor.GetGear()); }
public void BindItem(IActorPart item_owner, Item item) { item_name.text = item.GetName(); item_desc.text = item.GetDescription(); item_attr.text = item.GetAttribute(); item_type.text = item.GetItemType(); item_img.sprite = item.GetImage().sprite; item_img.color = item.GetImage().color; int i = 0; IBackpack backpack = item_owner.GetBackpack(); foreach (ItemOperation op in item.GetOperations()) { UIButton btn; if (i < buttons.Count) { btn = buttons[i]; } else { btn = Instantiate(btn_prototype, buttons_group.transform); buttons.Add(btn); } btn.SetText(op.operation_name); switch (op.tag) { default: case OperationOverTag.Default: btn.SetOnclick(() => op.callBack.Invoke(item, backpack)); break; case OperationOverTag.Close_Info_After_Op: btn.SetOnclick(() => { op.callBack.Invoke(item, backpack); Hide(); }); break; case OperationOverTag.Close_Backpack_After_Op: btn.SetOnclick(() => { op.callBack.Invoke(item, backpack); Hide(); backpackUI.Hide(); }); break; } btn.Show(); i++; } for (; i < buttons.Count; i++) { buttons[i].Hide(); } }
private void OnTriggerStay2D(Collider2D other) { if (auto_collect) { IActorPart actor = other.gameObject.GetComponent <IActorPart>(); if (actor != null) { CollectBy(actor.GetBackpack()); } } else if (InputManager.GetCollectDown()) { IActorPart actor = other.gameObject.GetComponent <IActorPart>(); if (actor != null) { CollectBy(actor.GetBackpack()); } } }