'Determine class under interface automatically
destroyComponentPacket.Component is an IComponent (an interface). I want to determine the specific class under it automatically, without having to do it manually using switch(). What are the options for doing so?
switch (destroyComponentPacket.Component)
{
case Tile t:
destroyComponentEntity.Detach<Tile>();
break;
case CollisionActor ca:
destroyComponentEntity.Detach<CollisionActor >();
break;
case Grass g:
destroyComponentEntity.Detach<Grass>();
break;
case Tree t:
destroyComponentEntity.Detach<Tree>();
break;
case Wall w:
destroyComponentEntity.Detach<Wall>();
break;
default:
break;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
