public static TComponent get_from_pool<TComponent>( this GameObject prefab ) where TComponent: MonoBehaviour { Pooled_object pooled_object = prefab.GetComponent<Pooled_object>(); Contract.Requires(pooled_object != null, "pooled prefabs must have the Pooled_object component"); TComponent returned_component = pooled_object.pool.get().GetComponent<TComponent>(); return returned_component; }
public static TComponent provide_new <TComponent>( this MonoBehaviour prefab_component ) where TComponent : MonoBehaviour { Pooled_object pooled_object = prefab_component.GetComponent <Pooled_object>(); //Contract.Requires(pooled_object != null, "pooled prefabs must have the Pooled_object component"); if (pooled_object != null) { var retrieved_object = pooled_object.instantiate(); var component = retrieved_object.GetComponent <TComponent>(); return(component); } var created_component = GameObject.Instantiate(prefab_component).GetComponent <TComponent>(); return(created_component); }
void Awake() { line_renderer = GetComponent <LineRenderer>(); pooled_object = GetComponent <Pooled_object>(); }