public void CancelSelection() { EquipBar.Get().CancelSelection(); CraftBar.Get().CancelSelection(); InventoryBar.Get().CancelSelection(); PlayerCharacter.Get().CancelConstruction(); }
//When the character interact with this selectable, check all the actions and see if any should be triggered. public void Use(PlayerCharacter character) { if (enabled) { ItemSlot islot = InventoryBar.Get().GetSelectedSlot(); ItemSlot eslot = EquipBar.Get().GetSelectedSlot(); ItemSlot slot = eslot != null ? eslot : islot; MAction maction = slot != null && slot.GetItem() != null?slot.GetItem().FindMergeAction(this) : null; AAction aaction = FindAutoAction(); if (maction != null && maction.CanDoAction(character, this)) { maction.DoAction(character, slot, this); TheUI.Get().CancelSelection(); } else if (aaction != null && aaction.CanDoAction(character, this)) { aaction.DoAction(character, this); } else if (actions.Length > 0) { ActionSelector.Get().Show(character, this); } if (onUse != null) { onUse.Invoke(character); } } }
private void OnClickSlot(int slot, CraftData item) { PlayerControlsMouse controls = PlayerControlsMouse.Get(); ItemSlot islot = InventoryBar.Get().GetSelectedSlot(); ItemSlot eslot = GetSlot(slot); selected_right_slot = -1; //Merge items if (eslot != null && islot != null) { ItemSlot slot1 = eslot; ItemSlot slot2 = islot; ItemData item1 = slot1.GetItem(); ItemData item2 = slot2.GetItem(); MAction action1 = item1 != null?item1.FindMergeAction(item2) : null; MAction action2 = item2 != null?item2.FindMergeAction(item1) : null; if (action1 != null && action1.CanDoAction(PlayerCharacter.Get(), slot2)) { action1.DoAction(PlayerCharacter.Get(), slot1, slot2); TheUI.Get().CancelSelection(); return; } else if (action2 != null && action2.CanDoAction(PlayerCharacter.Get(), slot1)) { action2.DoAction(PlayerCharacter.Get(), slot2, slot1); TheUI.Get().CancelSelection(); return; } } if (islot != null) { ItemData idata = islot.GetItem(); if (idata != null && idata.type == ItemType.Equipment) { PlayerData.Get().EquipItemTo(islot.slot_index, ItemData.GetEquipIndex(idata.equip_slot)); TheUI.Get().CancelSelection(); } } else if (item != null && slot != selected_slot) { TheUI.Get().CancelSelection(); selected_slot = slot; } else { CancelSelection(); } if (onClickSlot != null && eslot != null) { onClickSlot.Invoke(eslot); } }
public int GetInventorySelectedSlotIndex() { if (InventoryBar.Get()) { return(InventoryBar.Get().GetSelectedSlotIndex()); } return(-1); }
void Update() { Vector3 wPos = InventoryBar.Get().GetSlotWorldPosition(slot_target); Vector3 dir = wPos - transform.position; Vector3 tDir = wPos - start_pos; float mdist = Mathf.Min(fx_speed * Time.deltaTime, dir.magnitude); float scale = dir.magnitude / tDir.magnitude; transform.position += dir.normalized * mdist; transform.localScale = start_scale * scale; transform.rotation = Quaternion.LookRotation(TheCamera.Get().transform.forward, Vector3.up); if (dir.magnitude < 0.1f) { Destroy(gameObject); } timer += Time.deltaTime; if (timer > 2f) { Destroy(gameObject); } }
void Update() { transform.position = PlayerControlsMouse.Get().GetPointingPos(); transform.rotation = Quaternion.LookRotation(TheCamera.Get().transform.forward, Vector3.up); ItemSlot islot = InventoryBar.Get().GetSelectedSlot(); ItemSlot eslot = EquipBar.Get().GetSelectedSlot(); ItemSlot slot = eslot != null ? eslot : islot; Selectable select = Selectable.GetNearestHover(transform.position); MAction maction = slot != null && slot.GetItem() != null?slot.GetItem().FindMergeAction(select) : null; title.enabled = maction != null; title.text = maction != null ? maction.title : ""; if ((slot != null) != icon_group.activeSelf) { icon_group.SetActive(slot != null); } if (slot != null && slot.GetItem()) { icon.sprite = slot.GetItem().icon; } }