public static InventoryUIDragLookup BeginDrag(InventoryUIItemWrapper toDrag, uint startIndex, ItemCollectionBase collection, PointerEventData eventData) { if (draggingItem != null) { Debug.LogWarning("Item still attached to cursor, can only drag one item at a time", draggingItem.gameObject); return null; // Can only drag one item at a time } if (eventData.button != PointerEventData.InputButton.Left) return null; draggingItem = toDrag; //draggingButtonCollection = collection; // Canvas group allows object to ignore raycasts. CanvasGroup group = draggingItem.gameObject.GetComponent<CanvasGroup>(); if(group == null) group = draggingItem.gameObject.AddComponent<CanvasGroup>(); group.blocksRaycasts = false; // Allows rays to go through so we can hover over the empty slots. group.interactable = false; var lookup = new InventoryUIDragLookup(); lookup.startIndex = (int)startIndex; lookup.startItemCollection = collection; return lookup; }
public static InventoryUIDragLookup BeginDrag(InventoryUIItemWrapper toDrag, uint startIndex, ItemCollectionBase collection, PointerEventData eventData) { if (draggingItem != null) { Debug.LogWarning("Item still attached to cursor, can only drag one item at a time", draggingItem.gameObject); return(null); // Can only drag one item at a time } if (eventData.button != PointerEventData.InputButton.Left) { return(null); } draggingItem = toDrag; //draggingButtonCollection = collection; // Canvas group allows object to ignore raycasts. CanvasGroup group = draggingItem.gameObject.GetComponent <CanvasGroup>(); if (group == null) { group = draggingItem.gameObject.AddComponent <CanvasGroup>(); } group.blocksRaycasts = false; // Allows rays to go through so we can hover over the empty slots. group.interactable = false; var lookup = new InventoryUIDragLookup(); lookup.startIndex = (int)startIndex; lookup.startItemCollection = collection; return(lookup); }
public static void Drag(InventoryUIItemWrapper toDrag, uint startSlot, ItemCollectionBase handler, PointerEventData eventData) { if (eventData.button == PointerEventData.InputButton.Left) { draggingItem.transform.position = new Vector3(eventData.position.x, eventData.position.y, 0.0f); } }
/// <summary> /// Repaint the infobox with the given data. /// </summary> /// <param name="data"> /// An array of all the rows and it's data to be displayed. /// </param> public virtual void Repaint(InventoryUIItemWrapper item, LinkedList <InfoBox.Row[]> rows) { pool.DestroyAll(); poolObjs.DestroyAll(); poolCategoryBoxes.DestroyAll(); // The usual stuff uiIcon.sprite = item.item.icon; uiName.text = item.item.name; uiName.color = (item.item.rarity != null) ? item.item.rarity.color : uiName.color; uiDescription.text = item.item.description; int i = 0; foreach (var box in rows) { i++; var boxObj = poolCategoryBoxes.Get(); //var boxLayout = boxObj.AddComponent<VerticalLayoutGroup>(); //boxLayout.childForceExpandHeight = false; //boxLayout.childForceExpandWidth = true; foreach (var row in box) { var rowObj = pool.Get(); //var rowObj = GameObject.Instantiate<InfoBoxRowUI>(infoBoxRowPrefab); rowObj.transform.SetParent(boxObj.transform); rowObj.title.text = row.title; rowObj.title.color = row.titleColor; rowObj.message.text = row.text; rowObj.message.color = row.textColor; } boxObj.transform.SetParent(container); boxObj.transform.localScale = Vector3.one; boxObj.transform.localPosition = new Vector3(boxObj.transform.localPosition.x, boxObj.transform.localPosition.y, 0.0f); if (i < rows.Count && separatorPrefab != null) { // Add a separator if (separatorPrefab != null) { var separator = poolObjs.Get(); //var separator = GameObject.Instantiate<GameObject>(separatorPrefab); separator.transform.SetParent(container); separator.transform.localScale = Vector3.one; separator.transform.localPosition = new Vector3(separator.transform.localPosition.x, separator.transform.localPosition.y, 0.0f); } } } }
public static InventoryUIDragLookup EndDrag(InventoryUIItemWrapper toDrag, uint startSlot, ItemCollectionBase handler, PointerEventData eventData) { if (eventData.button == PointerEventData.InputButton.Left) { var lookup = new InventoryUIDragLookup(); lookup.startIndex = (int)draggingItem.index; lookup.startItemCollection = draggingItem.itemCollection; if (hoveringItem != null) { lookup.endIndex = (int)hoveringItem.index; lookup.endItemCollection = hoveringItem.itemCollection; } Object.Destroy(draggingItem.gameObject); // No longer need it draggingItem = null; //draggingButtonCollection = null; return(lookup); } return(null); }
private IEnumerator DestroyItem(InventoryUIItemWrapper inst) { yield return destroyTimer; pool.Destroy(inst); }
public static void Drag(InventoryUIItemWrapper toDrag, uint startSlot, ItemCollectionBase handler, PointerEventData eventData) { if(eventData.button == PointerEventData.InputButton.Left) draggingItem.transform.position = new Vector3(eventData.position.x, eventData.position.y, 0.0f); }
/// <summary> /// When the cursor exits an item /// </summary> /// <param name="item"></param> /// <param name="slot">The slot is the IButtonHandler index not the inventory index.</param> /// <param name="handler"></param> /// <param name="eventData"></param> public static void ExitItem(InventoryUIItemWrapper item, uint slot, ItemCollectionBase handler, PointerEventData eventData) { hoveringItem = null; //hoveringItemCollection = null; }
public static InventoryUIDragLookup EndDrag(InventoryUIItemWrapper toDrag, uint startSlot, ItemCollectionBase handler, PointerEventData eventData) { if(eventData.button == PointerEventData.InputButton.Left) { var lookup = new InventoryUIDragLookup(); lookup.startIndex = (int)draggingItem.index; lookup.startItemCollection = draggingItem.itemCollection; if (hoveringItem != null) { lookup.endIndex = (int)hoveringItem.index; lookup.endItemCollection = hoveringItem.itemCollection; } Object.Destroy(draggingItem.gameObject); // No longer need it draggingItem = null; //draggingButtonCollection = null; return lookup; } return null; }
/// <summary> /// Repaint the infobox with the given data. /// </summary> /// <param name="data"> /// An array of all the rows and it's data to be displayed. /// </param> public virtual void Repaint(InventoryUIItemWrapper item, LinkedList<InfoBox.Row[]> rows) { pool.DestroyAll(); poolObjs.DestroyAll(); poolCategoryBoxes.DestroyAll(); // The usual stuff uiIcon.sprite = item.item.icon; uiName.text = item.item.name; uiName.color = (item.item.rarity != null) ? item.item.rarity.color : uiName.color; uiDescription.text = item.item.description; int i = 0; foreach (var box in rows) { i++; var boxObj = poolCategoryBoxes.Get(); //var boxLayout = boxObj.AddComponent<VerticalLayoutGroup>(); //boxLayout.childForceExpandHeight = false; //boxLayout.childForceExpandWidth = true; foreach (var row in box) { var rowObj = pool.Get(); //var rowObj = GameObject.Instantiate<InfoBoxRowUI>(infoBoxRowPrefab); rowObj.transform.SetParent(boxObj.transform); rowObj.title.text = row.title; rowObj.title.color = row.titleColor; rowObj.message.text = row.text; rowObj.message.color = row.textColor; } boxObj.transform.SetParent(container); boxObj.transform.localScale = Vector3.one; boxObj.transform.localPosition = new Vector3(boxObj.transform.localPosition.x, boxObj.transform.localPosition.y, 0.0f); if(i < rows.Count && separatorPrefab != null) { // Add a separator if (separatorPrefab != null) { var separator = poolObjs.Get(); //var separator = GameObject.Instantiate<GameObject>(separatorPrefab); separator.transform.SetParent(container); separator.transform.localScale = Vector3.one; separator.transform.localPosition = new Vector3(separator.transform.localPosition.x, separator.transform.localPosition.y, 0.0f); } } } }