void Start() { m_Rows = (int)Mathf.Ceil(m_Container.size / (float)m_Columns); float width = m_SlotMargin.x * 2 + (m_SlotSize.x + m_SlotSpacing.x) * m_Columns - m_SlotSpacing.x; float height = m_SlotMargin.y * 2 + (m_SlotSize.y + m_SlotSpacing.y) * m_Rows - m_SlotSpacing.y + m_Skin.window.padding.vertical; m_Rect = new Rect(50 ,Screen.height*0.5f - height*0.5f ,width ,height); int i = 0; for (int y = 0; y < m_Rows; y++) { for (int x = 0; x < m_Columns; x++) { if (i >= m_Container.size) break; CRItem item = m_Container.GetItem(i); Rect slotRect = new Rect(m_SlotMargin.x + (m_SlotSpacing.x + m_SlotSize.x)* x, m_SlotMargin.y + (m_SlotSpacing.y + m_SlotSize.y)* y + m_Skin.window.padding.vertical, m_SlotSize.x, m_SlotSize.y); GUIItemSlot slot = new GUIItemSlot(slotRect, item, i); m_Slots.Add(slot); i++; } } }
public virtual void DrawTooltip(GUIItemSlot slot) { if (slot.item) { GUILayout.Label("Test"); } }
public void OnMouseDown(GUIItemSlot slot) { if (slot!=null && !cgui.dragging) { slot.grayed = true; cgui.SelectSlot(slot); } }
public void OnHoverOut(GUIItemSlot slot) { if (cgui.selectedSlot == slot && cgui.mouseDown && !cgui.dragging && slot.item != null) { cgui.Drag(slot, this); } else { slot.showBorder = false; } cgui.ClearHover(); }
public void Initialize() { m_listItemSlots = new List <GUIItemSlot>(m_nMaxSlot); for (int i = 0; i < m_nMaxSlot; i++) { GameObject prefap = Resources.Load <GameObject>("Prefaps/ItemSlot"); GameObject instance = Instantiate(prefap); instance.transform.SetParent(m_tranformContent); GUIItemSlot cItemSlot = instance.GetComponent <GUIItemSlot>(); cItemSlot.Delete(m_spriteSlotNone); m_listItemSlots.Add(cItemSlot); } }
public void OnReleaseMouse(GUIItemSlot dst) { //clean the slot color of the slot we landed on if (dst != null) { if (!cgui.dragging && cgui.hoverSlot == cgui.selectedSlot && dst.item != null) { cgui.Drag(dst, this); return; } else { dst.grayed = false; } } //cache the dragged variables and clean cgui for next use GUIItemSlot src = cgui.dragSlot; GUIItemContainer dragContainer = cgui.dragContainer; cgui.ClearDrag(); //nothing is held by the mouse, exit if (src == null) return; //clean color of the source slot src.grayed = false; //we were not droppped on a gui slot if (dst == null) { if (dragContainer != this) { //if (m_Container.AddItem(src.item)) { //dragContainer.container.RemoveItem(src.item); } } return; } //we have a source slot and destination slot, perfrom swap or move CRItem srcItem = src.item; if (srcItem == null) Debug.LogError("Trying to move a null item"); CRItemContainer srcContainer = dragContainer.container; CRItemContainer dstContainer = m_Container; src.RebuildTexture(); dst.RebuildTexture(); if (srcContainer == dstContainer) { //this is a local move/swap if (dstContainer.IsSlotOccupied(dst.index)) { dstContainer.GetComponent<CRItemContainerBinding>().NetworkSwapItem(src.index, dst.index); } else { dstContainer.GetComponent<CRItemContainerBinding>().NetworkMoveItem(src.index, dst.index); } } else { if (dstContainer.IsSlotOccupied(dst.index)) { dstContainer.GetComponent<CRItemContainerBinding>().NetworkSwapItemFromContainer(srcContainer.networkView.viewID, src.index, dst.index); } else { dstContainer.GetComponent<CRItemContainerBinding>().NetworkMoveItemFromContainer(srcContainer.networkView.viewID, src.index, dst.index); } } }
public void OnUse(GUIItemSlot slot) { if (slot != null && slot.item != null) { Debug.Log ("Use " + slot.item + " from " + this); } }
public void ClearHover() { m_HoverSlot = null; m_Hovering = false; }
public void ClearDrag() { m_DragSlot = null; m_DragContainer = null; m_Dragging = false; }
public void SelectSlot(GUIItemSlot slot) { m_SelectedSlot = slot; }
public void Hover(GUIItemSlot slot) { m_HoverSlot = slot; m_Hovering = true; }
public void Drag(GUIItemSlot slot, GUIItemContainer container) { m_DragSlot = slot; m_DragContainer = container; m_Dragging = true; }