예제 #1
0
    public void Insert(IsInventoryItem item)
    {
        IsCountable countable;

        for (int i = 0; i < items.Count; i++)
        {
            if (items[i].itemName == item.itemName)
            {
                countable = item.GetComponent <IsCountable>();
                if (countable)
                {
                    items[i].GetComponent <IsCountable>().ChangeAmount(countable.value);
                }

                // no duplicates
                return;
            }
        }
        // else just add new item
        countable = item.GetComponent <IsCountable>();
        if (countable)
        {
            countable.currentAmount += countable.value;
        }
        items.Add(item);
    }
예제 #2
0
    public void Initialize(IsCollectionView owner)
    {
        this.owner = owner;
        item       = owner.GetCollectionData().GetItemByName(itemName);

        if (item != null)
        {
            HasThumbnail hasThumbnail = item.GetComponent <HasThumbnail>();
            if (hasThumbnail != null)
            {
                // create thumbnail image
                thumbnail = new GameObject();
                thumbnail.transform.SetParent(this.transform);
                Image         image = thumbnail.AddComponent <Image>();
                RectTransform rect  = thumbnail.GetComponent <RectTransform>();
                rect.localPosition = new Vector3(hasThumbnail.thumbHorizontalOffset, hasThumbnail.thumbVerticalOffset, 0.0f);
                rect.localScale    = new Vector3(hasThumbnail.thumbScale, hasThumbnail.thumbScale, 1.0f);
                image.sprite       = hasThumbnail.image;
                image.color        = hasThumbnail.color;
            }
            IsCountable isCountable = item.GetComponent <IsCountable>();
            if (isCountable)
            {
                // create count object
                count = new GameObject();
                count.transform.SetParent(this.transform);
                Text text = count.AddComponent <Text>();
                count.GetComponent <RectTransform>().localPosition = new Vector3(isCountable.countHorizontalOffset, isCountable.countVerticalOffset, 0.0f);
                if (isCountable.maxAmount >= 100)
                {
                    text.text = isCountable.currentAmount.ToString("000");
                }
                else
                {
                    text.text = isCountable.currentAmount.ToString("00");
                }
                text.font      = isCountable.countFont;
                text.fontSize  = isCountable.countScale;
                text.alignment = TextAnchor.MiddleCenter;
            }
        }
    }