Esempio n. 1
0
        public float y_space;   //垂直间隔

        public void BuildInventory()
        {
            UGUIInventoryItem[] olds = GetComponentsInChildren <UGUIInventoryItem>();
            foreach (var pending_delete in olds)
            {
                DestroyImmediate(pending_delete.gameObject);
            }

            if (prototype != null)
            {
                for (int iy = 0; iy < y_count; iy++)
                {
                    for (int ix = 0; ix < x_count; ix++)
                    {
                        UGUIInventoryItem slot = GameObject.Instantiate <UGUIInventoryItem>(prototype);
                        slot.x    = ix;
                        slot.y    = iy;
                        slot.name = slot.ToString();

                        RectTransform rt = slot.transform as RectTransform;
                        rt.SetParent(content.transform);
                        if (rt != null)
                        {
                            rt.anchoredPosition = new Vector2(x_origin + ix * slot_width + ix * x_space, y_origin - iy * slot_height - iy * y_space);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        public void OnBeginDrag(PointerEventData eventData)
        {
            if (inventory_data != null && draging_image == null)
            {
                draging_image = UGUIManager.Instance.OpenDialog <UGUIInventroyDragingItem>("Draging_Image");
                draging_image.image.sprite = item_image.sprite;

                RectTransform this_rect   = transform as RectTransform;
                Vector2       delta_shift = new Vector2(item_image.rectTransform.sizeDelta.x * 0.5f, -item_image.rectTransform.sizeDelta.y * 0.5f);

                draging_image.image.rectTransform.anchoredPosition = this_rect.anchoredPosition + delta_shift;
                item_image.color = new Color(1, 1, 1, 0.6f);

                last_drag_item     = this;
                discard_after_drag = true;
            }
        }
Esempio n. 3
0
        public void OnDrop(PointerEventData eventData)
        {
            if (last_drag_item != null)
            {
                last_drag_item.discard_after_drag = false;

                for (int i = 0; i < onDropResponseList.Count; i++)
                {
                    //虽然比bool型麻烦,但是结果一目了然,逻辑清晰无歧义,不容易产生bug
                    EMessageChainOperation result = onDropResponseList[i]();
                    if (result == EMessageChainOperation.Interrupt || result == EMessageChainOperation.ReturnSuccess)
                    {
                        break;
                    }
                }

                last_drag_item = null;
            }
        }