public static void SetLootItemIcon(GameObject holder, Storable item) { string name = ""; object type = item.GetType(); if (item is Module) { name = (item as Module).type.ToString(); name = name.ToLower(); } if (item is Consumable) { name = (item as Consumable).type.ToString(); name = name.ToLower(); } Texture2D texture = Resources.Load("Prefabs/Icons/" + name) as Texture2D; holder.transform.FindChild("Image").FindChild("Image").GetComponent <Image>().sprite = Sprite.Create(texture, new Rect(Vector2.zero, new Vector2(texture.width, texture.height)), new Vector2(0.5f, 0.5f)); RectTransform itemRect = holder.GetComponent <RectTransform>(); itemRect.pivot = new Vector2(0.5f, 0.5f); itemRect.anchorMin = new Vector2(0, 0); itemRect.anchorMax = new Vector2(1, 1); itemRect.sizeDelta = new Vector2(0, 0); }
public void OnItemPointerEnter(Storable subject) { UI.Show("ItemDescription"); Vector3 p = new Vector3(Input.mousePosition.x - (Screen.width / 2), Input.mousePosition.y - (Screen.height / 2), 0); GameObject container = gui.transform.FindChild("ItemDescription").FindChild("Container").gameObject; Storable item = subject; container.transform.FindChild("Name").GetComponent <Text>().text = item.name; container.transform.FindChild("Description").GetComponent <Text>().text = item.description; container.transform.FindChild("Weight").GetComponent <Text>().text = item.weight + " kg"; container.transform.FindChild("Price").GetComponent <Text>().text = item.price + " $"; string prefab = "Prefabs/UI/ItemDescriptionRow"; List <System.Reflection.FieldInfo> fields = new List <System.Reflection.FieldInfo>(); fields.AddRange(item.GetType().GetFields()); for (int i = 0; i < fields.Count; i++) { if (fields[i].GetCustomAttributes(typeof(Serializable), false).Length == 0 && !Functions.Contains <string>(Storable.baseFields, fields[i].Name)) { GameObject g = GameObject.Instantiate(Resources.Load(prefab), Vector3.zero, Quaternion.identity) as GameObject; g.transform.SetParent(container.transform); g.transform.localPosition = Vector3.zero; g.transform.localScale = Vector3.one; g.transform.localRotation = Quaternion.Euler(0, 0, 0); g.name = char.ToUpper(fields[i].Name[0]) + fields[i].Name.Substring(1); string label = ConvertToLabel(fields[i].Name).ToUpper(); string text = fields[i].GetValue(item).ToString(); g.GetComponent <Text>().text = label + ":\n<color=yellow>" + text + "</color>"; } } container.GetComponent <RectTransform>().localPosition = p; }
public void OnStorableMouseOver(GameObject slot, Storable s) { if (!Dragable.inProgress) { var slotRect = slot.GetComponent <RectTransform>(); Vector3[] corners = new Vector3[4]; slotRect.GetWorldCorners(corners); var position = Camera.main.WorldToScreenPoint(corners[2]); position.x += 3; UI.Show("ItemDescription"); var panel = GameObject.Find("GUI/ItemDescription/Container"); panel.GetComponent <RectTransform>().anchoredPosition = position; string color = Functions.GetRarityColor(s.rarity); var tooltip = GameObject.Find("GUI/ItemDescription/Container/Background/Text"); string text = $"<b><color={color}>{s.name}</color></b>\n<i><color=#757575>{s.GetType()}</color></i>"; if (s is Module) { Module m = s as Module; text += $"\n\n+{m.hp} hp\n+{m.armor} armor"; if (m is Weapon) { Weapon w = m as Weapon; text += $"\n{w.attackSpeed} attack speed\n{w.damage} damage"; } } text += $"\n\n<i><color=#757575>{s.description}</color></i>"; tooltip.GetComponent <Text>().text = text; } }