I have set up an editor script to generate a bunch (700+) of buttons, which is working except for the part that adds the onClick handler. Here’s the code I have so far:
// i is an int from the enclosing for loop
// temp is a RectTransform defined outside the loop
// container is the part of the scroll view which will contain all of the buttons
temp = Instantiate(prefab);
temp.SetParent(container, false);
AddListener(temp.GetComponent<Button>(), i);
void AddListener(Button b, int id)
{
b.onClick.AddListener(() => t.LoadInfo(id));
}
This works at runtime, but when running from a button in the editor the buttons are generated but the click handlers are not added. How do I get this to work?