public void Initialize(HeaderElementInfo info) { listViewManager = transform.parent. transform.parent.gameObject.GetComponent <ListViewManager>(); gameObject.GetComponent <Button>().onClick.AddListener(SortHandler); ascendIcon = transform.Find("SortAscending").gameObject; descendIcon = transform.Find("SortDescending").gameObject; text = info.text; dataType = info.dataType; preferredWidth = info.preferredWidth; OnValidate(); }
public void Initialize(object[] fieldData, Guid guid) { // Because these are instantiated this gets called before Start so // it is easier to just find the listViewManager here listViewManager = transform.parent. transform.parent. transform.parent.gameObject.GetComponent <ListViewManager>(); transform.localScale = Vector3.one; // Need a reference to this to set the background color image = gameObject.GetComponent <Image>(); this.guid = guid; // Build the row elements (cells) rowElements = new List <GameObject>(); for (int i = 0; i < fieldData.Length; i++) { // For each cell add a new RowElementPrefab and set the row as its parent rowElements.Add(Instantiate(listViewManager.RowElementPrefab)); rowElements[i].transform.SetParent(transform); rowElements[i].transform.localScale = Vector3.one; // Set the text Text rowElementText = rowElements[i].GetComponentInChildren <Text>(); rowElementText.text = StringifyObject(fieldData[i], listViewManager.headerElementInfo[i].formatString, listViewManager.headerElementInfo[i].dataType); // Set the preferred width rowElements[i].GetComponentInChildren <LayoutElement>() .preferredWidth = listViewManager.headerElementInfo[i].preferredWidth; // Set the horizontal alignment if (listViewManager.headerElementInfo[i].horizontalAlignment == HorizontalAlignment.Left) { rowElementText.alignment = TextAnchor.MiddleLeft; } else { rowElementText.alignment = TextAnchor.MiddleRight; } } }