Source: Gig.cs, UGig.cs - Last Updated: 2021.8.2
The Gig
base class is a restricted Task
with minimal memory and performance overheads; this provides a template for your tasks and behavior trees:
public class MyTask : Gig{
override public status Step
=> /* your implementation */
}
NOTE: when using Active Logic, implementing a comprehensive BT as a single class is not uncommon; bearing in mind that a complex status expression is already a BT, good OOP should guide your design.
To invoke a gig, prefer the implicit notation to gig.Step()
status x = Strike() && myTask; // instead of `myTask.Step()`
To parameterize gigs, prefer indexers to explicit Step()
variants.
status x = Strike() && myTask[params];
Note: C# allows overloading indexers with distinct parameter sets; however optional parameters should not be used
In Unity UGig
inherits from MonoBehaviour
; to use a gig as root within a stepper (such as Agent
or PhysicsAgent
) override its status Step()
method as above.
public virtual status Step()
Stub for your step method
protected action Do(params object[] args)
Convert the result of a non void expression to done
.
Example: status Step() => Do( myVar = 34 )
protected status Do<T>() where T : UGig
Retrieve/create and evaluate a component task of type T.
protected loop Pause(float duration)
Pause the underlying stepper for a specified duration (seconds)
protected loop Push(Func<status> φ)
Execute φ as BT root ('stack φ') until it has completed or failed, then resume running this gig.
protected status Resume()
Resume execution while paused or suspended
protected status Suspend()
Suspend the underlying stepper indefinitely
protected loop this[Func<status> φ]
Sames as Push
(see above)
public bool suspended
True if the underlying stepper is suspended or paused
Gigs are implicitly convertible to status
, and Func<status>
which is equivalent to calling or retrieving the Step
function; if Step
is not implemented, a runtime error occurs.