I've got an array of tk2dSprites with a tk2dUIItem script attached to them. The array items are created at runtime using Unity's Instantiate() command on a prefab with the tk2dSprite/tk2dUIItem setup. I've made a method, Click(tk2dUIItem clickedUIItem) to handle the OnClickUIItem() event. I also have another array that contains references to the tk2dUIItem for each tk2dSprite, for performance.
I've tried adding the Click() method to the sprite_tk2dUIItem[].OnClickUIItem list of delegates it will execute, as follows:
sprite_tk2dUIItem[I].OnClickUIItem += Click;
I've tried doing this at first in the Start() method of the script which is responsible for managing the sprites and their click events (a sprite manager script). When that didn't work, I tried instead to do this initialization in the OnEnable() event of the sprite manager script, and then removing the delegate assignments in the OnDisable() routine of the sprite manager, as is shown in all the example text:
sprite_tkUIItem[I].OnClickUIItem -= Click;
I assume that in the latest version of the 2D Toolkit, the tk2dUIManager is implicitly defined (I don't even see it listed in the list of 2D Toolkit UI scripts that can be added via the Add Component button in the Unity Editor).
Any ideas what is going wrong here?
Is it necessary to add to the OnClickUIItem delegate list only in the OnEnable() method? Can't this be done in the Start() event?