I have the following class and my question lies with it's GetComponent function
class GameObject
{
private List<GameComponent> _components = new List<GameComponent>();
public void AddComponent(GameComponent component)
void RemoveComponent(string name)
public T GetComponent<T>(string name) where T : GameComponent
}
class GameComponent
{
public string Name { get; set; }
}
So in GetComponent i want to get the component identified by name
and return it as T.
So i would call
NavigationComponent navigation = gameObject.GetComponent<NavigationComponent>("navigation");
where NavigationComponent would be a subclass of GameComponent
Since each NavigationComponent instance is only ever going to have the same name, "navigation", i am pondering if i can do something to simplify the GetComponent to the following
NavigationComponent navigation = gameObject.GetComponent<NavigationComponent>();
Thanks in advance.
Update 1
Well i should mention that the GameObject works like a set of GameObjects, identified by their name, so there can be only one of each in it.
So to elaborate lets say we have
class SimpleNavigation : GameComponent {...}
class AdvancedNavigation : GameComponent {...}
class SensorSystem : GameComponent {...}
Then i would give SimpleNavigation and AdvancedNavigation the Name "navigation" and to the SensorSystem the name "sensor"
So i cannot have both SimpleNavigation and AdvancedNavigation in the above example.
Hope that makes sense.
Thanks in advance.
p.s. I fear that i might be placing too many constrains when there isn't much to gain and longterm the specifications might change, but that is outside of the scope of the question i guess