示例#1
0
    private void RegistInventory()
    {
        for (int i = 0; i < mSlotList.Length; i++)
        {
            RectTransform   tr       = mSlotList[i].GetComponent <RectTransform>();
            GridLayoutGroup grid     = mSlotList[i].GetComponent <GridLayoutGroup>();
            Vector2         cellSize = grid.cellSize;
            Vector2         spacing  = grid.spacing;

            InvenSlot[] slots = mSlotList[i].GetComponentsInChildren <InvenSlot>();

            int tX = (int)Mathf.Round((tr.sizeDelta.x / (cellSize.x + spacing.x)));
            int tY = (int)Mathf.Round((tr.sizeDelta.y / (cellSize.y + spacing.y)));

            for (int y = 0; y < tY; y++)
            {
                List <InvenSlot> lTemp = new List <InvenSlot>();
                for (int x = 0; x < tX; x++)
                {
                    InvenSlot temp = slots[(y * tX) + x];
                    temp.Init();
                    lTemp.Add(temp);
                }
                Slots.Add(lTemp);
            }
        }
    }
示例#2
0
    private void ChangeSlot(InvenSlot _invenSlot)
    {
        if (!_invenSlot.Item)
        {
            SetAlpha(0f);
            return;
        }

        Item            = _invenSlot.Item;
        mItemImg.sprite = Item.Sprite;
        Count           = _invenSlot.Count;
        MaxCount        = Item.Kind == Items.ITEM_KIND.RESOURCE ? 99 : 1;
        SetAlpha(1f);
    }
示例#3
0
    public override List <Items> GetItems()
    {
        Items mCraftItem = GetComponentInParent <CraftLine>().CurItem;

        if (!mCraftItem)
        {
            return(null);
        }
        List <Items> tList = new List <Items>();

        Items.ItemRecipe[] recipe = mCraftItem.Recipe;

        for (int i = 0; i < recipe.Length; i++)
        {
            List <Items> temp = new List <Items>();
            if (recipe[i].Recipe.Length > slotId)
            {
                Items.ITEM_DETAILTYPE type  = recipe[i].Recipe[slotId];
                List <Items>          ttemp = Inventory.GetInvenItemList(type);

                if (ttemp != null)
                {
                    temp.AddRange(ttemp);
                }
            }

            if (recipe[i].SpecialRecipe.Length > slotId)
            {
                InvenSlot tSlot = Inventory.GetInvenSlot(recipe[i].SpecialRecipe[slotId]);
                if (tSlot)
                {
                    temp.Add(tSlot.Item);
                }
            }


            if (temp.Count != 0)
            {
                tList.AddRange(temp);
            }
        }

        if (tList.Count == 0)
        {
            return(null);
        }

        return(tList);
    }
示例#4
0
    private void SwapSlot()
    {
        Items temp   = Item;
        int   tCount = Count;

        InvenSlot _dragging = DragSlot.instance.mDragSlot;

        ChangeSlot(_dragging);

        if (!temp)
        {
            _dragging.ClearSlot();
        }
        else
        {
            _dragging.ChangeSlot(temp, tCount);
        }
    }
示例#5
0
    public void OnPointerDown(PointerEventData eventData)
    {
        InvenSlot slot = Inventory.GetInvenSlot(mWantItem);

        if (!slot)
        {
            mGaugeBar.fillAmount -= 0.2f;
            return;
        }

        IncreaseHandler(slot.Item);

        if (guestDoHandler != null)
        {
            guestDoHandler();
        }

        StartCoroutine(PlayEndAudioCoroutine(mBuyClip, 0.5f));
    }
示例#6
0
    static public void StoreItem(Items _item)
    {
        for (int y = 0; y < Slots.Count; y++)
        {
            for (int x = 0; x < Slots[y].Count; x++)
            {
                InvenSlot temp = Slots[y][x];

                if (!temp.Item)
                {
                    temp.AddItem(_item);
                    return;
                }
                else if (temp.Item.ItemName == _item.ItemName && temp.MaxCount > temp.Count)
                {
                    temp.AddItem(_item);
                    return;
                }
            }
        }
    }
示例#7
0
    static public bool UseItem(Items _item)
    {
        for (int y = Slots.Count - 1; y >= 0; y--)
        {
            for (int x = Slots[y].Count - 1; x >= 0; x--)
            {
                InvenSlot temp = Slots[y][x];
                if (!temp.Item)
                {
                    continue;
                }

                if (temp.Item.ItemName == _item.ItemName)
                {
                    temp.UseItem();
                    return(true);
                }
            }
        }

        return(false);
    }
示例#8
0
文件: Inven.cs 项目: wlsdud5938/BTD
    public bool AddItemInSlot(ItemObject item)
    {
        int slotCount = AllSlot.Count;

        for (int i = 0; i < slotCount; i++)
        {
            InvenSlot slot = AllSlot[i].GetComponent <InvenSlot>();

            if (slot.IsSlotEmpty())
            {
                continue;
            }

            if (slot.ItemReturn().type == item.type && slot.ItemMax(item))
            {
                slot.AddItem(item);
                Debug.Log("Add item success");
                return(true);
            }
        }

        for (int i = 0; i < slotCount; i++)
        {
            InvenSlot slot = AllSlot[i].GetComponent <InvenSlot>();

            if (!slot.IsSlotEmpty())
            {
                continue;
            }

            slot.AddItem(item);
            Debug.Log("Add item success");
            return(true);
        }

        Debug.Log("Add item fails");
        return(false);
    }
示例#9
0
    static public InvenSlot GetInvenSlot(Items item)
    {
        InvenSlot slots = null;

        for (int y = Slots.Count - 1; y >= 0; y--)
        {
            for (int x = Slots[y].Count - 1; x >= 0; x--)
            {
                if (!Slots[y][x].Item)
                {
                    continue;
                }
                if (Slots[y][x].Item.ItemName != item.ItemName)
                {
                    continue;
                }
                slots = Slots[y][x];
                break;
            }
        }

        return(slots);
    }
示例#10
0
	private void SetItem( sITEM sitem, int iSlot)
	{	
		if( 0 > iSlot || m_ItemList.Length <= iSlot)
		{
			Debug.LogError( "Inventory::SetItem() [m_ItemList.Length <= iSlot] [ index : " + iSlot);
			return;
		}		
		
		if( null == sitem)
		{
			Debug.LogError("Inventory::SetItem()[null == sitem ] ");
		}
		
		if ( 0 == sitem.nItemTableIdx) 
		{
			if( null != m_ItemList[ iSlot ])
				m_ItemList[ iSlot ].Clear();			
		}
		else
		{
			if( null == m_ItemList[ iSlot ])
			{
				m_ItemList[ iSlot ] = new InvenSlot( new RealItem( sitem, iSlot));
			}
			else
			{	
				if( null == m_ItemList[ iSlot ])
				{
					Debug.LogError("Inventory::SetItem()[null == m_ItemList[ iSlot ] ] slot:  " + iSlot );
				}
				m_ItemList[ iSlot ].SetItem( sitem, iSlot);
			}
		}	
		
		#region -GameGuide_Item
		AsGameGuideManager.Instance.CheckUp( eGameGuideType.Item, sitem.nItemTableIdx);
		#endregion
		
		SetExpireItem( iSlot, GetRealItemInSlot( iSlot ) );
	}	
示例#11
0
    public void InnerClassTest()
    {
        InvenSlot NewInvenSlot = new InvenSlot();

        NewInvenSlot.Select(this);
    }
示例#12
0
 public void InnerClassTest()
 {
     InvenSlot NewSlot = new InvenSlot();
 }