7 using System.Collections.Generic;
16 private static readonly
Map interfaces =
new Map();
20 internal Component Component;
24 Type type = typeof(Tc);
25 if (interfaces[type].Found)
return;
29 void initialiser(T t) {
30 if (t.Instantiated)
return;
32 if (primary || (t.defaultComponent == null)) t.defaultComponent = type;
34 var component = t.GetComponent<Tc>();
35 if (component != null) {
36 Component = component;
45 public override string ToString() => Component == null ?
"null" : Component.gameObject.name;
48 private ComponentInterface componentInterface;
50 private Type defaultComponent;
58 if (componentInterface != null)
return componentInterface;
61 if ((componentInterface != null) || (defaultComponent == null))
return componentInterface;
63 gameObject.AddComponent(defaultComponent);
65 return componentInterface;
void Instantiate< Tc >(bool primary)
Called in concrete class constructor
bool Instantiated
Set when the component is first instantiated (used internally)
override string ToString()
Returns game object name as the most useful
Creating Decoupled Components
ComponentInterface Instance
Called in concrete component instances to get the correct backing component
static Action< T > Initialisers
List of component initialisers (used internally)
Parent class for component interfaces