Learn how to start a schematic in your code.
You can start a schematic in your custom scripts without having to use a machine component, you just need the schematic asset.
When dealing with schematics, you’ll need to use the schematic namespace:
using GamingIsLove.Makinom.Schematics;
Loading from a Schematic Asset #
Before a schematic can be started, you need to create it using a schematic asset.
You can e.g. add it as a field in your component.
public MakinomSchematicAsset schematicAsset;
Use this code to load the schematic asset into an actual runtime schematic.
Schematic schematic = new Schematic(this.schematicAsset);
Starting a schematic #
You can either start the schematic with or without priority through one of the PlaySchematic functions.
Non-Priority Start #
Let’s take a look at the function to start without priority first:
public virtual void PlaySchematic(object source, ISchematicStarter starter, object machineObject, object startingObject, bool isBlocking, MachineUpdateType updateType, int inputID)
- object source
The source that starts the schematic, e.g. the machine component or global machine starting it.
Can be ignored in most cases (passing on null).
This sets the schematic instance’s Source property, which can be used in custom nodes to check what started the schematic (e.g. used in the ORK Framework extension by some nodes to determine if it’s a battle action). - ISchematicStarter starter
The ISchematicStarter interface used as an argument will be notified by the schematic when it finished playing.
Implement the ISchematicStarter interface in a class (e.g. the class starting the schematic), or just use null as an argument to not get notified.
You can also get notified by a schematic when it finished by adding a parameterless function to the Notify function of the schematic. - object machineObject
The object that will be used as machine object in the schematic, usually you’ll use a game object. - object startingObject
The object that will be used as starting object in the schematic, usually you’ll use a game object. - bool isBlocking
Use true if this is a blocking schematic, otherwise false.
Only one blocking schematic can be executed at a time. - MachineUpdateType updateType
The MachineUpdateType enum handles which update function (Update, LateUpdate or FixedUpdate) will be used by the schematic. - int inputID
The input ID that will be used by this schematic.
You can use Maki.Control.InputID to pass on the current global input ID of Makinom.
A call of this function can look like this.
schematic.PlaySchematic(null, null, machineObject, startObject, false, MachineUpdateType.Update, Maki.Control.InputID);
Priority Start #
Starting a schematic with priority is also done through the PlaySchematic function, using one additional parameter (1st parameter):
public virtual void PlaySchematic(int priority, object source, ISchematicStarter starter, object machineObject, object startingObject, bool isBlocking, MachineUpdateType updateType, int inputID)
- int priority
The priority of the schematic.
The highest priority number will be executed first.
The rest of the parameters are the same as using the non-priority start function.
A call of this function can look like this.
schematic.PlaySchematic(10, null, null, machineObject, startObject, false, MachineUpdateType.Update, Maki.Control.InputID);
Starting a schematic in a single line #
You can also start a schematic with a single line by using one of the static Schematic.Play
functions.
They don’t require to first create an instance of a schematic, but you also don’t have a reference to the started schematic – i.e. it’s more used as a fire-and-forget functionality.
Getting notified by a finished schematic #
There are 2 ways to get notified by a schematic when it finished execution.
The ISchematicStarter Interface #
Implement the ISchematicStarter interface in your class. The interface will add 1 function to the class.
An example implementation in a component can look like this.
public virtual void SchematicFinished(Schematic schematic) { // the schematic finished playing }
The function will be called with the instance of the schematic that finished execution as a parameter.
Registering Notify function #
Registering a parameterless function using the Notify function of the schematic, e.g. when the function is added to the same class the call is made from:
schematic.Notify(this.SchematicFinished);
The registered function would look like this:
public virtual void SchematicFinished() { }
The functions added via Notify will be called before the ISchematicStarter interface. You should add the function via Notify before starting the schematic, in case the schematic finishes immediately (e.g. due to no wait time in nodes being used).