// 아이템 옮기기 및 교환. public void Swap(Unit_Slot slot, Vector3 Pos) { Unit_Slot FirstSlot = NearDisSlot(Pos); // 현재 슬롯과 옮기려는 슬롯이 같으면 함수 종료. if (slot == FirstSlot || FirstSlot == null) { slot.UpdateInfo(true, slot.slot.Peek().DefaultImg); return; } // 가까운 슬롯이 비어있으면 옮기기. if (!FirstSlot.isSlots()) { //Swap(FirstSlot, slot); } // 교환. else { int Count = slot.slot.Count; ItemObject item = slot.slot.Peek(); Stack <ItemObject> temp = new Stack <ItemObject>(); { for (int i = 0; i < Count; i++) { temp.Push(item); } slot.slot.Clear(); } Swap(slot, FirstSlot); { Count = temp.Count; item = temp.Peek(); for (int i = 0; i < Count; i++) { FirstSlot.slot.Push(item); } FirstSlot.UpdateInfo(true, temp.Peek().DefaultImg); } } }
// 1: 비어있는 슬롯, 2: 안 비어있는 슬롯. void Swap(Unit_Slot xFirst, Unit_Slot oSecond) { int Count = oSecond.slot.Count; ItemObject item = oSecond.slot.Peek(); for (int i = 0; i < Count; i++) { if (xFirst != null) { xFirst.slot.Push(item); } } if (xFirst != null) { xFirst.UpdateInfo(true, oSecond.ItemReturn().DefaultImg); } oSecond.slot.Clear(); oSecond.UpdateInfo(false, oSecond.DefaultImg); }