/// <summary> /// Display a tooltip to a particular item above a transformItem /// </summary> /// <param name="item">The DataBasics data item</param> /// <param name="transformItem">the transform of the button or thumbnail</param> private void OnClickItem(DataBasicsTypes.Items item, Transform transformItem) { transform.Find("toolTip").gameObject.SetActive(true); transform.Find("toolTip").transform.position = transformItem.position; //Display the description text transform.Find("toolTip/txt").GetComponent <Text>().text = item.description; }
/// <summary> /// Populates the invenotry UI with thumbails each representing a data entry of the sheet /// </summary> private void PopuplateThumbnails() { //The reference gameObject to instanciate GameObject gameObjectTemplate = transform.Find("groupItems/item0").gameObject; //Create thumbnail objects for each data Item in DataBasics.items foreach (DataBasicsTypes.Items item in DataBasics.items) { GameObject go = GameObject.Instantiate(gameObjectTemplate); go.transform.SetParent(gameObjectTemplate.transform.parent); go.transform.localScale = Vector3.one; //Assign name and cost for the thumbnail go.transform.Find("txtName").GetComponent <Text>().text = item.name; go.transform.Find("txtCost").GetComponent <Text>().text = "$" + item.cost; //Assign icons based on weapon or food go.transform.Find("imgWeapon").GetComponent <Image>().enabled = item.isWeapon; go.transform.Find("imgFood").GetComponent <Image>().enabled = !item.isWeapon; //Setup button actions Button button = go.transform.Find("btn").GetComponent <Button>(); DataBasicsTypes.Items parameter = item; //Create a variable with a pointer inside the {} loop button.onClick.AddListener(() => { //Assign a Lambda expression (Annomynous function) to call the OnClickThumbnail call with the parameter object OnClickItem(parameter, go.transform); }); } //Disable template gameObject gameObjectTemplate.SetActive(false); }