Cloner

Sometimes, it's useful to generate child objects instead of defining them statically. The Flexalon Cloner can generate objects from a set of prefabs iteratively or randomly, and can optionally bind to a data source.

Cloner Options

Cloner Options
Objects Prefabs which should be cloned as children.
Clone Type If Iterative, the cloner will clone each prefab in the Objects list in order and then repeat. If Random, the cloner will select randomly from the prefabs.
Random Seed Seed used for the Random clone type, to ensure results remain consistent.
Count Number of clones to create.
Data Source Can be an gameObject with a component that implements DataSource. The number of objects cloned is set to the number of items in the Data property.

Data Binding

When the Cloner creates objects from a DataSource, it will search the cloned objects for any component which implements DataBinding to bind the data entry from the data source to the visual item. The component can then use this data to change its appearance.

Google Search Example

Putting these pieces together, you can create this Google image search example, which you can find in the sample scenes.

In this example, the Cloner is configured to use a GoogleImageDataSource component as its DataSource and to instantiate the RemoteTexture prefab. This prefab has a RemoteTextureDataBinding component which implements DataBinding.

When the cloner gets new data from the data source, it instantiates a RemoteTexture for each data entry, finds DataBinding component, and passes along the data. The RemoteTextureDataBinding uses this data to download the image texture and apply it to its material.

The gameObject with the Cloner component also has a wrapping Flexible Layout to arrange the images in sequence. Finally, the RemoteTexture prefab has a custom adapter called IamgeAdapter which ensures the images maintain their aspect ratio.