addWith<T extends Component> method

T addWith<T extends Component>(
  1. T component, {
  2. String? name,
  3. Transform? transform,
  4. Iterable<Component> components = const [],
  5. int layer = 0,
})

Adds a new object below this one with component on it, and returns the component, for a field: _sun = addWith(Light.sun()) where add(GameObject(components: [Light.sun()])).get<Light>()! would. name, transform and layer are the new object's, and components go on it after component, as a camera's rig: addWith(VirtualCamera(), components: [Orbit(player)]).

Implementation

T addWith<T extends Component>(
  T component, {
  String? name,
  Transform? transform,
  Iterable<Component> components = const [],
  int layer = 0,
}) {
  add(GameObject(name: name, transform: transform, components: [component, ...components], layer: layer));
  return component;
}