Class TrafficProcess
Abstract base class for a single reactive traffic behaviour — gap-keeping, stopline compliance, or collision avoidance — that runs for a bounded duration and then removes itself from the active list.
[Serializable]
public abstract class TrafficProcess
Inheritance
Derived
Examples
// Minimal concrete process that reduces the actor's speed modifier while a school-zone
// sign is detected by the forward sensor, then restores it when the sign is no longer ahead.
//
// TrafficBehaviour.TryGetProcess maps the detected object to this subclass, constructs it,
// and calls Initialize before adding it to the active list.
[System.Serializable]
public class SchoolZoneSpeedProcess : TrafficProcess
{
private IMoveCommandInvoker invoker;
private float slowSpeed;
// ImpossibleSameProcess ensures only one instance of this rule runs at a time —
// a second sign trigger while the first is active is discarded rather than stacked.
public override ProcessConstraint GetProcessConstraint()
=> ProcessConstraint.ImpossibleSameProcess;
// Read typed parameters from the loosely-typed bag; call base to clear IsCompleted.
public override void Initialize(ProcessData processData)
{
base.Initialize(processData); // resets IsCompleted = false
if (processData.objectParameter.TryGetValue("mine", out Object obj)
&& obj is GameObject go)
invoker = go.GetComponent();
processData.valueParameter.TryGetValue("slowSpeed", out slowSpeed);
if (invoker == null) Completed(); // bail out safely if wired incorrectly
}
// Called every frame by TrafficBehaviour.DoUpdate until IsCompleted is true.
public override void Update(float deltaTime)
{
base.Update(deltaTime);
// Apply speed cap; the zone-exit condition would call Completed() here.
invoker.PauseCommand(); // placeholder — real logic checks distance to sign
}
// Restore normal movement; base sets IsCompleted = true so DoUpdate removes this process.
public override void Completed()
{
base.Completed();
invoker?.ResumeCommand();
}
}
Remarks
Rather than encoding all traffic rules in a monolithic controller, the simulation
decomposes traffic logic into small, independent TrafficProcess instances that each
handle one interaction. When a sensor fires, TrafficBehaviour constructs the
appropriate subclass, populates it via ProcessData), and adds it to the active
list. The process drives the actor's speed each frame until its goal is met, then sets
IsCompleted so DoUpdate removes it.
This design means new traffic rules can be added by subclassing TrafficProcess
without modifying existing code. Multiple independent rules (gap-keeping, stopline hold)
can also run simultaneously on the same actor without interfering.
Properties
EditorDislayName
Human-readable label shown in the Inspector debug view.
public virtual string EditorDislayName { get; }
Property Value
string
IsCompleted
Set to true by Completed when the process has finished;
DoUpdate removes completed processes from the active list.
public bool IsCompleted { get; protected set; }
Property Value
bool
Methods
Completed()
Marks the process as finished, triggering its removal on the next DoUpdate call.
public virtual void Completed()
Remarks
Subclasses should call base.Completed() to set IsCompleted, then
perform any cleanup (e.g., clearing a cached speed override) before returning.
GetProcessConstraint()
Returns the concurrency constraint for this process type.
public virtual TrafficProcess.ProcessConstraint GetProcessConstraint()
Returns
TrafficProcess.ProcessConstraint — The constraint that TrafficProcess) enforces to prevent duplicate processes from stacking.
Initialize(ProcessData)
Applies processData configuration and resets IsCompleted
so the process begins fresh.
public virtual void Initialize(TrafficProcess.ProcessData processData)
Parameters
| Name | Type | Description |
|---|---|---|
processData | TrafficProcess.ProcessData | Parameter bag populated by Collider). |
Remarks
Subclasses should call base.Initialize to clear IsCompleted, then
read their keys from objectParameter and
valueParameter.
Update(float)
Advances the process by one tick; called each frame by DoUpdate until IsCompleted is set.
public virtual void Update(float deltaTime)
Parameters
| Name | Type | Description |
|---|---|---|
deltaTime | float | Elapsed time since the last frame, in seconds. |