private void FireSelectionChanged(ListItem newItem) { var oldItem = selected; selected = newItem; if (SelectionChanged != null) { SelectionChanged(oldItem, newItem); } }
private ListItem CreateListItem() { var newChild = new GameObject("ListItem"); var newText = new GameObject("ListItemText"); //Set parents and scale newText.transform.parent = newChild.transform; newChild.transform.parent = transform; ResetTransform(newText.transform); ResetTransform(newChild.transform); var textRect = newText.AddComponent<RectTransform>(); //Create necessary components var background = newChild.AddComponent<Image>(); var text = newText.AddComponent<Text>(); var button = newText.AddComponent<Button>(); var inferrer = newChild.AddComponent<InferSize>(); var trigger = newChild.AddComponent<EventTrigger>(); text.font = font; button.targetGraphic = text; inferrer.targetGraphic = text; var listItem = new ListItem(newChild, text, textRect, background, button); button.onClick.AddListener(() => { FireSelectionChanged(listItem); }); return listItem; }