Пример #1
0
 public void OnSubmit(vItemSlot slot)
 {
     currentSelectedSlot = slot;
     if (slot.item)
     {
         var rect = slot.GetComponent <RectTransform>();
         optionWindow.transform.position = rect.position;
         optionWindow.gameObject.SetActive(true);
         optionWindow.EnableOptions(slot);
         currentSelectedSlot = slot;
     }
 }
Пример #2
0
        public void CreateEquipmentWindow(List <vItem> items, OnSubmitSlot onPickUpItemCallBack = null, OnSelectSlot onSelectSlotCallBack = null, bool destroyAdictionSlots = true)
        {
            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 (count < items.Count)
            {
                for (int i = count; i < items.Count; i++)
                {
                    var slot = Instantiate(slotPrefab) as vItemSlot;
                    slots.Add(slot);
                }
            }
            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 < items.Count)
                {
                    slot = slots[i];
                    slot.AddItem(items[i]);
                    slot.CheckItem(items[i].isInEquipArea);
                    slot.onSubmitSlotCallBack = OnSubmit;
                    slot.onSelectSlotCallBack = OnSelect;
                    var rectTranform = slot.GetComponent <RectTransform>();
                    rectTranform.SetParent(contentWindow);
                    rectTranform.localPosition = Vector3.zero;

                    rectTranform.localScale = Vector3.one;
                    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);
            }
        }