private void ProcInit_InventorySlot() { IInventorySlot[] arrInventoryslot = GetComponentsInChildren <IInventorySlot>(true); int iLen = arrInventoryslot.Length; for (int i = 0; i < iLen; i++) { IInventorySlot pSlot = arrInventoryslot[i]; if (_mapInventorySlot.ContainsKey(i)) { Debug.LogWarning("이미 _mapInventorySlot 에 " + pSlot + " 가 있습니다..."); } else { _mapInventorySlot.Add(i, pSlot); pSlot.DoInit(this); pSlot.OnEnableSlot(false); } } _iMaxSlotCount = iLen; }
private void ProcInit_InventoryData(List <CLASS_DATA> listInventoryData) { _mapInventoryData.Clear(); int iCount_InventoryData = listInventoryData.Count; int iCount = _mapInventorySlot.Count; for (int i = 0; i < iCount; i++) { IInventorySlot pSlot = _mapInventorySlot[i]; bool bContains_InventoryData = i < iCount_InventoryData; if (bContains_InventoryData) { CLASS_DATA sInfoData = listInventoryData[i]; string strSpriteName = GetSpriteName(sInfoData); pSlot.OnSetSprite(strSpriteName); OnSetInventoryData(sInfoData, (CLASS_SLOT)pSlot); _mapInventoryData.Add(i, sInfoData); } pSlot.OnEnableSlot(bContains_InventoryData); } }
/// <summary> /// Sets up the display properly based on slot data /// </summary> /// <param name="slot">The slot to display</param> public void Set(IInventorySlot slot) { if (_slot != null) { _slot.PropertyChanged -= Slot_PropertyChanged; } _slot = slot; _slot.PropertyChanged += Slot_PropertyChanged; UpdateVisuals(); }
public void EquippedToSlot(IInventorySlot slot) { if (ContainingSlot != null) { throw new InvalidOperationException("Item is already in a slot."); } ContainingSlot = slot; foreach (var component in Owner.GetComponents <ISpriteRenderableComponent>()) { component.Visible = false; } }
public void RemovedFromSlot() { if (ContainingSlot == null) { throw new InvalidOperationException("Item is not in a slot."); } ContainingSlot = null; foreach (var component in Owner.GetComponents <ISpriteRenderableComponent>()) { component.Visible = true; } }
/// <summary> /// Swaps the content of the slot with another one /// </summary> /// <param name="left">The slot to swap from</param> /// <param name="right">The slot to swap to</param> public static void Swap(IInventorySlot left, IInventorySlot right) { //Only swap if slot types match if (!left.CanSet(right.Item.Type) || !right.CanSet(left.Item.Type)) { return; } var leftId = left.Id; var leftAmount = left.Amount; left.Set(right.Id, right.Amount); right.Set(leftId, leftAmount); }
/// <summary> /// Swaps the content of the slot with another one /// </summary> /// <param name="other">The other slot to swap the content with</param> public void Swap(IInventorySlot other) { //Only swap if slot types match if (!CanSet(other.Item.Type) || !other.CanSet(Item.Type)) { return; } var id = Id; var amount = Amount; Set(other.Id, other.Amount); other.Set(id, amount); }
private int?GetOpenSlot(Item item) { for (int i = 0; i < totalSlots; i++) { IInventorySlot inventorySlot = inventorySlots[i]; Item itemInSlot = inventorySlot.Item; if (itemInSlot == null || (item.Id == itemInSlot.Id && inventorySlot.Count + 1 <= item.MaxStackSize)) { return(i); } } return(null); }
//public CLASS_DATA GetInventoryData(int iRealID) //{ // return _mapInventoryData[iRealID]; //} //public CUGUIInventorySlot GetInventorySlot(int iSlotID) //{ // return _mapInventorySlot[iSlotID]; //} /* public - [Event] Function * 프랜드 객체가 호출(For Friend class call)*/ //public void OnRegisterSlot(CUGUIInventorySlot pSlot) //{ // int iSlotID = pSlot.p_iSlotID; // if (_mapInventorySlot.ContainsKey(iSlotID)) // { // Debug.Log( "이미 슬롯 키 값이 들어가있습니다." ); // return; // } // _mapInventorySlot.Add(iSlotID, pSlot); //} //public void OnPickItem(Vector3 v3CursorPos, int iPickSlotID) //{ // if (_bEnableDragItem == false) return; // _bIsSlotContainItem = _mapInventoryData.ContainsKey(iPickSlotID); //} //public void OnDragItem(Vector3 v3CursorPos, int iPickSlotID) //{ // if (_bEnableDragItem == false) return; // if (_bIsSlotContainItem == false) return; // CUGUIInventorySlot pSlot = _mapInventorySlot[iPickSlotID]; // _pInventoryCursor.DoSetImage(pSlot.p_pImage.sprite); // _pInventoryCursor.DoUpdatePosition(v3CursorPos); //} //public void OnDropItem(GameObject pGameObject, int iOwnerSlotID, int iOwnerSlotHashCode) //{ // if (_bEnableDragItem == false) return; // if (_bIsSlotContainItem == false) return; // _pInventoryCursor.SetActive(false); // if (pGameObject == null) return; // // 일단 슬롯이 있는지 체크 // CUGUIInventorySlot pTargetSlot = pGameObject.GetComponent<CUGUIInventorySlot>(); // if (pTargetSlot == null) return; // CLASS_DATA pOwnerData_Backup = _mapInventoryData[iOwnerSlotID]; // IInventoryEquipSlot<CLASS_DATA> ITargetEquipSlot = pTargetSlot.GetComponent<IInventoryEquipSlot<CLASS_DATA>>(); // if (ITargetEquipSlot != null) // { // CUGUIInventorySlot pOwnerSlot = GetInventorySlot(iOwnerSlotID); // if (ITargetEquipSlot.CheckSlotType(pOwnerData_Backup) == false) return; // } // if (iOwnerSlotHashCode == pTargetSlot.p_iInvenHashCode) // { // // 같은 슬롯일 경우 데이터만 스왑해준다. // if (_bEnableSwapItemInSameInventory) // EventSwapData(iOwnerSlotID, pTargetSlot.p_iSlotID); // } // else // { // // 다른 슬롯일 경우 데이터 발신 // if (_bRemoveItem) // EventRemoveData(iOwnerSlotID); // pTargetSlot.OnReceiveData(pOwnerData_Backup); // } //} //public void OnSelectSlot(CUGUIInventorySlot pSlot) //{ // if (_bEnableSelectSlot == false) return; // EventSelectSlot(pSlot); //} //protected void EventSelectSlot(CUGUIInventorySlot pSlot) //{ // int iSlotID = pSlot.p_iSlotID; // if (_mapInventoryData.ContainsKey(iSlotID) == false) return; // if (_pSelectedSlot != null) // { // _pSelectedSlot.DoEnableImageSelected(false); // if (_pSelectedSlot.p_iSlotID == pSlot.p_iSlotID) // { // EventUnSelectSlot(); // OnUnSelectedSlot(); // return; // } // } // pSlot.DoEnableImageSelected(true); // OnSelectedSlot(pSlot, _mapInventoryData[pSlot.p_iSlotID]); // _pSelectedSlot = pSlot; //} //protected void EventUnSelectSlot() //{ // if (_pSelectedSlot != null) // { // _pSelectedSlot.DoEnableImageSelected(false); // _pSelectedSlot = null; // } //} //public void OnReceiveData(int iReceiveSlotID, CInventoryData_Test IReceiveData) //{ // CLASS_DATA pData = (CLASS_DATA)IReceiveData; // if (_mapInventoryData.ContainsKey(iReceiveSlotID)) // { // // 일단 옮기기 전에 들어있던 데이터 백업 // CLASS_DATA pDataDroppedPos_Backup = _mapInventoryData[iReceiveSlotID]; // IInventoryListener pInventoryListner_Backup = pData.p_pInventoryOwner; // int iSlot_Backup = pData.p_iSlotID; // // 현재 드래그된 아이템을 현재 인벤토리에 일단 옮긴다.. // EventSetSlotData(iReceiveSlotID, pData); // pInventoryListner_Backup.OnReceiveData(iSlot_Backup, pDataDroppedPos_Backup); // } // else // { // EventSetSlotData(iReceiveSlotID, pData); // } //} public void OnClickSlot(IInventorySlot IInventorySlot) { }
/// <summary> /// Sets an item into a slot /// </summary> /// <param name="slot">The slot</param> /// <param name="item">The item</param> /// <param name="amount">The amount to add</param> /// <returns>The amount not set</returns> public int Set(IInventorySlot slot, int itemId, int amount) { return(Set(slot.Index, itemId, amount)); }
/// <summary> /// Unsets a slot /// </summary> /// <param name="slot">The slot</param> public void Unset(IInventorySlot slot) { Unset(slot.Index); }