/// <summary> /// Will return a clone of this slot, without the background (useful when you want to simulate item dragging). /// </summary> public RectTransform GetDragTemplate(SavableItem forItem, float alpha) { var template = Instantiate <Slot>(this); // HACK: We shouldn't know about the frame object, only the hotbar script should know. var frame = template.transform.FindDeepChild("Frame"); if (frame != null) { Destroy(frame.gameObject); } template.enabled = false; template.image.enabled = false; template.m_ItemIcon.enabled = true; template.m_StackDisplayer.enabled = forItem.CurrentInStack > 1; template.m_StackDisplayer.text = string.Format("x{0}", forItem.CurrentInStack); //error handly make sure ammo displayer variable hase a value if (template.m_AmmoDisplayer) { template.m_AmmoDisplayer.enabled = forItem.HasProperty("Ammo"); } //error handly make sure ammo displayer variable hase a value if (template.m_AmmoDisplayer && template.m_AmmoDisplayer.enabled) { template.m_AmmoDisplayer.text = string.Format("x{0}", forItem.GetPropertyValue("Ammo").Int.Current); } template.m_DurabilityBar.SetActive(forItem.HasProperty("Durability")); var group = template.gameObject.AddComponent <CanvasGroup>(); group.alpha = alpha; return(template.GetComponent <RectTransform>()); }
private void ShowInfo(SavableItem item) { // Name. m_ItemName.text = (item.ItemData.DisplayName == string.Empty) ? item.ItemData.Name : item.ItemData.DisplayName; // Main description. if (item.ItemData.Descriptions.Length > 0) { m_MainDescription.text = item.GetDescription(0); } else { m_MainDescription.text = ""; } // Secondary description. if (item.ItemData.Descriptions.Length > 1) { m_SecondaryDescription.text = item.GetDescription(1); } else { m_SecondaryDescription.text = ""; } // Icon. m_Icon.sprite = item.ItemData.Icon; // Durability bar. if (item.HasProperty("Durability")) { if (!m_DurabilityBar.Active) { m_DurabilityBar.SetActive(true); } m_DurabilityBar.SetFillAmount(item.GetPropertyValue("Durability").Float.Ratio); } else if (m_DurabilityBar.Active) { m_DurabilityBar.SetActive(false); } // Magazine. ItemProperty.Value property; if (item.FindPropertyValue("Magazine", out property)) { var magazine = property.IntRange; m_Magazine.text = "Magazine: " + magazine.ToString(); } else { m_Magazine.text = ""; } // Consume action. m_ConsumeButton.gameObject.SetActive(item.HasProperty("Can Consume")); // Dismantle action. m_DismantleButton.gameObject.SetActive(item.HasProperty("Can Dismantle")); }