Skip to main content

Class FeedbackMetricCoordinator

Manages the lifecycle of a feedback metric event by tracking when designated scene actors enter and exit a trigger zone, then sampling metric calculators at a fixed interval until all actors have passed through.

public class FeedbackMetricCoordinator : MonoBehaviour

Inheritance​

Examples​

// A metric calculator on the same GameObject subscribes in OnEnable/OnDisable
// so it receives per-tick samples and the final completion signal:
[RequireComponent(typeof(FeedbackMetricCoordinator))]
public class MyMetricCalculator : MonoBehaviour
{
private FeedbackMetricCoordinator coordinator;

private void Awake() => coordinator = GetComponent();

private void OnEnable()
{
coordinator.OnMetricUpdate += AccumulateData;
coordinator.OnMetricComputed += FinaliseScore;
}

private void OnDisable()
{
coordinator.OnMetricUpdate -= AccumulateData;
coordinator.OnMetricComputed -= FinaliseScore;
}

private void AccumulateData(float elapsed) { /* sample per-tick proximity data */ }
private void FinaliseScore() { /* write result to a FloatVariable asset */ }
}

Remarks​

A single coordinator can be reused for any metric type (prosocial, safe boundary, yield) because it only concerns itself with actor presence and timing. The actual calculation is delegated to IFeedbackMetricCalculator components on the same GameObject via the OnMetricUpdate and OnMetricComputed callbacks, keeping the two concerns separate.

Fields​

ActorsInArea​

Runtime set of actors that are currently inside the trigger zone.

[NonSerialized]
public HashSet<GameObject> ActorsInArea

Field Value​

HashSet<GameObject>

Remarks​

Actors are added on OnTriggerEnter and removed on OnTriggerExit; it is intentionally separate from ActorsToConsider so that transient presence and overall completion tracking remain independent concerns.

ActorsToConsider​

Runtime set of actors that are still expected to enter the trigger zone.

[NonSerialized]
public HashSet<GameObject> ActorsToConsider

Field Value​

HashSet<GameObject>

Remarks​

It is populated from sceneActors (plus the player) at Start and is used as a one-shot countdown: each actor is removed when it first enters the zone, so the completion condition — ActorsToConsider.Count == 0 && ActorsInArea.Count == 0 — fires only after every expected actor has been observed, not merely when the zone happens to be empty at a given frame.

OnEventComplete​

Invoked once all expected actors have entered and exited the trigger zone and the final metric calculation has completed.

[SerializeField]
[Tooltip("")]
public UnityEvent OnEventComplete

Field Value​

UnityEvent

Remarks​

The coordinator fires this event exactly once — after OnMetricComputed — preventing the feedback UI from updating mid-interaction. Triggering the final calculation from this single event rather than from each individual actor exit ensures that all per-actor data has been collected before any display or export logic runs.

OnMetricComputed​

Invoked to notify any subscribled metric calculator to compete their final metric.

public Action OnMetricComputed

Field Value​

Action

OnMetricUpdate​

Invoked to notify any subscribled metric calculator to update their calculation.

public Action<float> OnMetricUpdate

Field Value​

Action<float>

sceneActors​

List of actors in the scene to monitor and include in metric calculation.

public List<GameObject> sceneActors

Field Value​

List<GameObject>

  • Examples
  • Remarks
  • Fields
    • ActorsInArea
    • ActorsToConsider
    • OnEventComplete
    • OnMetricComputed
    • OnMetricUpdate
    • sceneActors