RadialLayoutFactory COMPONENT

The RadialLayoutFactory component is an helper class for dynamic procedural layout generation using scripts.


Setting Up

The RadialLayoutFactory component must be placed on an existing layout gameobject, alongside a RadialLayout component.

For example, you can just add the RadialLayoutFactory component to an empty prefab_RadialLayout gameobject (see QuickStart) and you are all set. Make sure not to apply the component override to the original prefab.

TIP: Unpack the prefab after you placed it in the scene to avoid to accidentally apply overrides to the original.


Building Settings


Building Behaviour

These settings determine how the factory script will behave and are not related to the final layout itself:

  • Run On Start: Turn this on if the layout is purely generated at runtime, or it need additional building operations after the game starts. When this option is on the building script will run on script Start, generating nodes from the build delegate method. If you used the Factory script to generate the layout in the editor and it is already in its final form, you can leave this option off.
  • Clear Layout Before Build: Keep this on if the building script is meant to generate a new layout from scratch, deleting all nodes before the generation. If you need to use the Factory script to add nodes to an already existing layout turn this option off.
  • Destroy After Build: This will just remove the RadialLayoutFactory script from the GameObject once the build script has finished, leaving the final layout unaffected. Will work only at runtime, if you use the Factory script to build a layout in the editor (using the Build button) the component will not be deleted after completion.

The Node Pool

Place here all of your node prefabs and give them an unique id so you can instantiate them using the Factory script:


// Adding 4 nodes

// The first parameter of the AddNode function is the ID in the prefabs pool set in the factory inspector

// The second parameter is the name of the instantiated gameobject

// The third parameter is a list of tags (used by the query system)

factory.AddNode("diamonds","diamondsRoot",new string[] {"diamonds","red","root"});

factory.AddNode("spades", "spadesRoot", new string[] { "spades","black", "root" });

factory.AddNode("hearts", "heartsRoot", new string[] { "hearts","red", "root" });

factory.AddNode("clubs", "clubsRoot", new string[] { "clubs","black", "root" });

              

Layout Settings

This section contains settings that are already present in the RadialLayout component and are placed here so you can quick setup the building phase without having to modify the RadialLayot component directly:

  • Use Query System: Turn this on if you plan to use the Query System for this layout. (see Query System)
  • Prefab Based Instancing: This option works only if you use the Factory to build layouts inside the editor. If turned on, new nodes will mantain reference to their original prefab when created. If this option is not enabled, new nodes will be instantiated as plain GameObjects.

Build Delegate

This is the most important setting of the Factory script and you have to assign this callback to a method containing your building logic.

The building method has the following signature:


public void MyBuildMethod(RadialLayoutFactory factory)

{

  // Inside here you can build your layout and have access to the calling factory object

}

            

You can find a full example of a layout generated dynamically by looking at the RadialLayoutExample_ProceduralGeneration.BuildLayout() function found inside the Example_ProceduralGeneration scene.

IMPORTANT: When assigning the callback method make sure to select the DYNAMIC one found at the top of the methods list:

IMPORTANT: If you are using the Factory to build layouts in the editor (not at runtime) using the 'Build' button, make sure to select the 'Editor And Runtime' execution option, otherwise the script won't run.


Actions

Build

Runs the build script and creates the layout inside the editor. If your script must create the layout only at runtime, you can still use this button to preview the final layout and use the Clear button to delete all nodes after you've checked them.

IMPORTANT: Make sure the callback setting for the build delegate is set to Editor And Runtime, otherwise the script won't run inside the edtor.

Clear Layout

Deletes all the nodes in the layout.