bool InContext(Class[] array, Item item)
{
for(int i = 0;i<array.length;i++)
{
if(item is array[i])
{
return true;
}
}
return false;
}
Is there anyway to store a bunch of classes in an array, so that I can tell if one of my items is inheriting from it?
I want this function for checking if an item is within context (for context sensitive menus) to be fairly dynamic. so writing it in manually isn't really an option.
Use Type instead of 'Class' in your header line.
Then you can have:
bool InContext(Item item, Type[] accepted)
{
Type itemType = item.GetType();
return accepted.Any(x=> x.IsAssignableFrom(itemType));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With