UFeelAPI is a static singleton MonoBehaviour for reacting to player biometric signals in real time:
Define rules - condition + action pairs - that fire automatically rather than polling each frame.
All methods are static. Required objects are created automatically if absent from the scene and persist across scene loads (DontDestroyOnLoad).
A rule has a condition, an action, and a mode:
Once - triggered once, then removedContinuous - triggered every frame while the condition holdsRules are evaluated every Update().
When you register a rule, you receive a RuleKey:
RuleKey key;
This key allows you to manually remove the rule later if needed.
UFeelAPI.StartEmotionDetection();
UFeelAPI.StopEmotionDetection();
Emotion detection must be started before reading data or registering rules.
EmotionData? emotions = UFeelAPI.CurrentEmotionsData;
EmotionData.EmotionType? dominant = UFeelAPI.DominantEmotion;
Returns null if the system is not running. DominantEmotion returns the highest-confidence emotion.
UFeelAPI.TriggerActionOnEmotionOnce(
EmotionData.EmotionType.Happy,
() => Debug.Log("Player is happy!")
);
RuleKey key = UFeelAPI.TriggerActionOnEmotionContinuous(
EmotionData.EmotionType.Angry,
() => TakeDamageOverTime()
);
UFeelAPI.RemoveRule(key);
UFeelAPI.StartEyeTrackingDetection();
UFeelAPI.StopEyeTrackingDetection();
EyeTrackingData? data = UFeelAPI.CurrentDirections;
EyeTrackingData.EyeTrackingDirection? direction = UFeelAPI.DominantDirection;
UFeelAPI.TriggerActionOnDirectionOnce(
EyeTrackingData.EyeTrackingDirection.Left,
() => OpenLeftDoor()
);
or continuously:
UFeelAPI.TriggerActionOnDirectionContinuous(
EyeTrackingData.EyeTrackingDirection.Up,
() => AimUpwards()
);
UFeelAPI.StartSpeechDetection();
UFeelAPI.StopSpeechDetection();
string spokenText = UFeelAPI.CurrentSpeech;
Returns null if speech detection is not running.
Triggers when the detected text contains the target string (case-insensitive).
UFeelAPI.TriggerActionOnSpeechOnce(
"open the door",
() => OpenDoor()
);
Continuous mode:
UFeelAPI.TriggerActionOnSpeechContinuous(
"attack",
() => TriggerCombatMode()
);
UFeelAPI.StartHeartRateDetection();
UFeelAPI.StopHeartRateDetection();
int? bpm = UFeelAPI.CurrentHeartRate;
Define a target BPM with an optional tolerance (±).
UFeelAPI.TriggerActionOnHeartRateOnce(
rate: 120,
action: () => EnterStressMode(),
tolerance: 10
);
Triggers if BPM is within ±tolerance of the target (here: 110–130).
Continuous variant:
UFeelAPI.TriggerActionOnDirectionContinuous(
rate: 90,
action: () => CalmState(),
tolerance: 5
);
RuleKey key = UFeelAPI.TriggerActionOnEmotionContinuous(...);
UFeelAPI.RemoveRule(key);
UFeelAPI.StopAPI();
Stops all detectors and shuts down the Python server. Called automatically when the UFeelAPI GameObject is disabled.
UFeelAPI.Status();
Logs the running state of all systems in the Unity Console.
Contains, not exact match.async void Start()
{
await UFeelAPI.StartAPI();
UFeelAPI.StartEmotionDetection();
UFeelAPI.Status();
Debug.Log("Here is the current emotion " + UFeelAPI.CurrentEmotionsData);
Debug.Log("Here is the dominant emotion " + UFeelAPI.DominantEmotion);
UFeelAPI.TriggerActionOnEmotionOnce(EmotionData.EmotionType.Anger, async () =>
{
UFeelAPI.StopEmotionDetection();
UFeelAPI.Status();
UFeelAPI.StartEyeTrackingDetection();
UFeelAPI.Status();
Debug.Log("Here is the current eye data " + UFeelAPI.CurrentDirections);
Debug.Log("Here is the dominant direction " + UFeelAPI.DominantDirection);
UFeelAPI.TriggerActionOnDirectionOnce(EyeTrackingData.EyeTrackingDirection.UpRight, () =>
{
UFeelAPI.StopEyeTrackingDetection();
UFeelAPI.StartSpeechDetection();
// Continuous Emotion
UFeelAPI.StartEmotionDetection();
RuleKey key = UFeelAPI.TriggerActionOnEmotionContinuous(EmotionData.EmotionType.Happiness, async () =>
{
await Task.Delay(1000);
Debug.Log("Emotion Continuellement");
});
//
UFeelAPI.Status();
UFeelAPI.TriggerActionOnSpeechOnce("Camion", async () =>
{
Debug.Log("Here is the current speech " + UFeelAPI.CurrentSpeech);
// Remove Continuous Emotion
UFeelAPI.RemoveRule(key);
UFeelAPI.StopEmotionDetection();
//
UFeelAPI.StopSpeechDetection();
UFeelAPI.StartHeartRateDetection();
UFeelAPI.Status();
UFeelAPI.TriggerActionOnHeartRateOnce(80, () =>
{
UFeelAPI.StopAPI();
});
});
});
});
}
See also: <- README - Architecture - Testing & Debugging