Ejemplo n.º 1
0
        public void CreateEquipmentWindow(List <vItem> items, OnSubmitSlot onPickUpItemCallBack = null, OnSelectSlot onSelectSlotCallBack = null, bool destroyAdictionSlots = true)
        {
            var _items = supportedItems.Count == 0? items:items.FindAll(i => supportedItems.Contains(i.type));

            if (_items.Count == 0)
            {
                if (itemtext)
                {
                    itemtext.text = "";
                }
                if (slots.Count > 0 && destroyAdictionSlots)
                {
                    for (int i = 0; i < slots.Count; i++)
                    {
                        Destroy(slots[i].gameObject);
                    }
                    slots.Clear();
                }
                return;
            }

            bool selecItem = false;

            onSubmitSlot = onPickUpItemCallBack;
            onSelectSlot = onSelectSlotCallBack;
            if (slots == null)
            {
                slots = new List <vItemSlot>();
            }
            var count = slots.Count;

            if (updateSlotCount)
            {
                if (count < _items.Count)
                {
                    for (int i = count; i < _items.Count; i++)
                    {
                        var slot = Instantiate(slotPrefab) as vItemSlot;
                        slots.Add(slot);
                        var rectTranform = slot.GetComponent <RectTransform>();
                        rectTranform.SetParent(contentWindow);
                        rectTranform.localPosition = Vector3.zero;

                        rectTranform.localScale = Vector3.one;
                    }
                }
                else if (count > _items.Count)
                {
                    for (int i = count - 1; i > _items.Count - 1; i--)
                    {
                        Destroy(slots[slots.Count - 1].gameObject);
                        slots.RemoveAt(slots.Count - 1);
                    }
                }
            }

            count = slots.Count;
            for (int i = 0; i < _items.Count; i++)
            {
                vItemSlot slot = null;
                if (i < count)
                {
                    slot = slots[i];
                    slot.AddItem(_items[i]);
                    slot.CheckItem(_items[i].isInEquipArea);
                    slot.onSubmitSlotCallBack = OnSubmit;
                    slot.onSelectSlotCallBack = OnSelect;

                    if (currentItem != null && currentItem == _items[i])
                    {
                        selecItem = true;
                        SetSelectable(slot.gameObject);
                    }
                }
            }

            if (slots.Count > 0 && !selecItem)
            {
                StartCoroutine(SetSelectableHandle(slots[0].gameObject));
            }

            if (onCompleteSlotListCallBack != null)
            {
                onCompleteSlotListCallBack(slots);
            }
        }
Ejemplo n.º 2
0
        public void CreateEquipmentWindow(List <vItem> items, List <vItemType> type, vItem currentItem = null, OnSubmitSlot onPickUpItemCallback = null, OnSelectSlot onSelectSlotCallBack = null)
        {
            this.currentItem = currentItem;
            var _items = items.FindAll(item => type.Contains(item.type));

            CreateEquipmentWindow(_items, onPickUpItemCallback);
        }