LogicBlock 2

Scripting

Run, check and stop Blocks from C#, and use call fields in your own components.

Scripting

Everything is in the Fullscreen.LogicBlock2.Runtime namespace. Calls use Visual Script's Args, which carry the Source and Target.

Running a Block

csharp
using Fullscreen.LogicBlock2.Runtime;
using UnityEngine;
using VisualScript.Runtime;

public class Door : MonoBehaviour
{
    [SerializeField] private InstructionBlock m_Open;
    [SerializeField] private ConditionBlock m_CanOpen;

    public async void Interact(GameObject player)
    {
        using Args args = Args.Get(this.gameObject, player); // Source, Target

        if (!this.m_CanOpen.Check(args)) return;
        await this.m_Open.Run(args);
    }
}

Calls made from code use each parameter's default value.

LogicBlock lists

LogicBlock methods take the list's id. Find it by name through Entries:

csharp
using System.Linq;

string chase = this.m_EnemyAI.Entries.First(entry => entry.Name == "Chase").Id;

await this.m_EnemyAI.Run(chase, args);                 // an Instructions list
bool canAttack = this.m_EnemyAI.Check(attackId, args); // a Conditions list
this.m_EnemyAI.Stop(chase, this.gameObject);           // stop this object's Chase calls

Calls with parameter fields in your own components

To call a Block with parameter values from your own script, use the same fields as Run Block. Call holds the Block (and list), and Arguments holds the parameter values. In the inspector they look and work exactly like Run Block's fields, prefab-style overrides included.

csharp
using Fullscreen.LogicBlock2.Runtime;
using UnityEngine;
using VisualScript.Runtime;

public class Spawner : MonoBehaviour
{
    [SerializeField, CallKind(CallKind.Run)]
    private Call m_Block = new Call();

    [SerializeField]
    private Arguments m_Parameters = new Arguments();

    public async void Spawn(GameObject target)
    {
        using Args args = Args.Get(this.gameObject, target);
        await this.m_Block.Run(args, this.m_Parameters.Items, this.gameObject, target, null);
    }
}
  • CallKind sets which Blocks the field accepts: Run (Instruction Blocks and Instructions lists), Check (Condition Blocks and Conditions lists) or Stop (like Run, plus All Lists).
  • The Arguments field finds its Call by the field name m_Block. If yours is named differently, add [ArgumentsFor("m_YourField")] to the Arguments field.

API summary

TypeMember
InstructionBlockAwaitable Run(Args args, IReadOnlyList<Argument> arguments = null, ICancelToken cancelToken = null)
InstructionBlockAwaitable Run(Args, IReadOnlyList<Argument>, GameObject source, GameObject target, ICancelToken)
InstructionBlockint Stop(GameObject source = null) stops this source's calls, or all calls when source is null; returns how many stopped
InstructionBlockInstructions Instructions
ConditionBlockbool Check(Args args, IReadOnlyList<Argument> arguments = null)
ConditionBlockbool Check(Args, IReadOnlyList<Argument>, GameObject source, GameObject target)
ConditionBlockConditions Conditions, Conditions.Operation Operation
LogicBlockAwaitable Run(string listId, Args args, ...) (same overloads as above)
LogicBlockbool Check(string listId, Args args, ...)
LogicBlockint Stop(string listId, GameObject source = null)
LogicBlockIReadOnlyList<Entry> Entries, bool TryGetEntry<T>(string id, out T entry), string GetEntryName(string id)
Block (base of all three)Note Note, IReadOnlyList<Parameter> Parameters, bool TryGetParameter(string id, out Parameter parameter)
Entry (a LogicBlock list)string Id, string Name, Note Note; EntryInstructions.Instructions; EntryConditions.Conditions and .Operation
Parameterstring Id, string Name, Value Default, string TypeName, Type DataType
CallBlock Block, string EntryId, Run(...), Check(...), Stop(GameObject source, bool anySource), IsRunning(GameObject source, bool anySource)
Runsstatic bool IsRunning(Block block, string listId, GameObject source, bool anySource)
Runsstatic int Stop(Block block, string listId, GameObject source, bool anySource)
RunsUse "" as the list id for an Instruction Block, or to mean all lists of a LogicBlock.
Keysconst int MAX_DEPTH (32)