To use the Broccoli’s run-time API add the following namespaces to your script:
1 2 |
using Broccoli.Factory; using Broccoli.Pipe; |
static TreeFactory TreeFactory.GetFactory ()
The first step to generate a tree at run-time is to get a TreeFactory object. This factory will load and use a pipeline to spawn trees on your scene. It is recommended to get a factory per pipeline on the scene to avoid having to load a new pipeline everytime a different product is required.
1 |
TreeFactory myFactory = TreeFactory.GetFactory(); |
Pipeline TreeFactory.LoadPipeline (string pathToResource)
After getting a tree factory it is needed to load it with a valid pipeline. In order to have access to a pipeline asset file it should be placed inside a Resources folder. Take in account that the pathToResource parameter should comply with Unity’s resources format, for example a file at Assets/Resources/MyPipelines/myTreePipeline.asset becomes MyPipelines/myTreePipeline. If no pipeline could be loaded the method returns null.
1 |
Pipeline myPipeline = myFactory.LoadPipeline ("myPipelines/myTreePipeline"); |
bool Pipeline.IsValid ()
Checks if a pipeline is valid to generate a tree.
1 |
if (myPipeline.IsValid ()) { Debug.Log ("Pipeline is valid!"); } |
GameObject TreeFactory.Spawn ()
GameObject TreeFactory.Spawn (int seed)
Given a valid pipeline loaded to a tree factory, this method produces a GameObject based on the pipeline instructions. A seed can be used as a parameter to skip randomization every time spawn is called.
1 |
GameObject myTree = myTreeFactory.Spawn (); |