void Start ()
{
ButtonPre.onClick.AddListener(SwitchButtonHandler);
ButtonNext.onClick.AddListener(SwitchButtonHandler);
}
void SwitchButtonHandler()
{
//Here i want to know which button was Clicked.
//or how to pass a param through addListener
}
void Start ()
{
ButtonPre.onClick.AddListener(delegate{SwitchButtonHandler(0);});
ButtonNext.onClick.AddListener(delegate{SwitchButtonHandler(1);});
}
void SwitchButtonHandler(int idx_)
{
//Here i want to know which button was Clicked.
//or how to pass a param through addListener
}
Late to the party, but still relevant. I was looking for something similar in C# and realized I could just cache the enumerated Keycode list into a Dictionary. So:
public static readonly Dictionary KeycodeCache = new Dictionary();
private void FillKeyCodeLookup()
{
foreach (KeyCode code in Enum.GetValues(typeof(KeyCode)))
{
KeycodeCache.Add(code.ToString(), code);
}
}
internal static KeyCode GetKeyCode(string codeName)
{
// Get from cache to prevent unnecessary enum parse
return KeycodeCache[codeName];
}
Simply fill the dictionary at Awake or Start and call the dictionary.