2using Microsoft.Azure.Kinect.BodyTracking;
3using Microsoft.Azure.Kinect.Sensor;
5using System.Collections.Generic;
14 [Header(
"References")]
15 [SerializeField, Tooltip(
"The skeleton to control.")]
private BodyTracker bodyTracker;
18 [SerializeField, Tooltip(
"How is the sensor mounted?")]
private SensorOrientation sensorOrientation;
19 [SerializeField, Tooltip(
"Serial number of the device we want to connect to.")]
private string deviceSerial =
"<Insert device serial number here.>";
20 [SerializeField, Tooltip(
"If no serial numbers match, connect to first device found.")]
private bool connectDefaultIfNoSerialMatch =
true;
23 private List<string> availableSerials =
new List<string>();
26 private bool isReady =
true;
27 private bool hasDetectedBodies =
false;
33 public void SetSensorOrientation(SensorOrientation sensorOrientation) { this.sensorOrientation = sensorOrientation; }
36 public void SetDeviceSerial(
string deviceSerial) { this.deviceSerial = deviceSerial; }
42 private void Awake() {
44 if (instance ==
null) {
51 private void OnDestroy() {
52 if (frameDataProvider !=
null) {
54 frameDataProvider =
null;
57 if (instance ==
this) {
62 private void Update() {
64 if (frameDataProvider !=
null &&
67 Debug.Log(
"New serial number " + deviceSerial +
"selected. Shutting down " + frameDataProvider.
DeviceSerial +
".");
69 frameDataProvider =
null;
73 if (isReady &&
null == frameDataProvider) {
78 for (
int i = 0; i < availableSerials.Count; ++i) {
79 if (availableSerials[i] == deviceSerial) {
80 Debug.Log(
"Attempting to start " + deviceSerial +
".");
81 frameDataProvider =
new FrameDataProvider(i, sensorOrientation, OnFrameDataProviderFinish);
87 if (connectDefaultIfNoSerialMatch && 0 < availableSerials.Count && frameDataProvider ==
null) {
88 deviceSerial = availableSerials[0];
93 if (
null == frameDataProvider || !frameDataProvider.
HasStarted) {
94 hasDetectedBodies =
false;
99 if (frameDataProvider.
GetData(ref frameData)) {
100 if (0 < frameData.NumDetectedBodies) {
101 hasDetectedBodies =
true;
102 bodyTracker.UpdateSkeleton(frameData, sensorOrientation);
104 hasDetectedBodies =
false;
110 private void ScanDeviceSerials() {
111 int deviceCount = Device.GetInstalledCount();
112 availableSerials.Clear();
113 for (
int i = 0; i < deviceCount; ++i) {
115 using (Device device = Device.Open(i)) {
116 availableSerials.Add(device.SerialNum);
117 Debug.Log(
"BodyTrackerManager::ScanDeviceSerials - Found device with serial number " + device.SerialNum +
".");
120 }
catch (Exception e) {
121 Debug.LogError(e.ToString());
126 private void OnFrameDataProviderFinish() { isReady =
true; }
Manager class to pass data from FrameDataProvider to BodyTracker.
List< string > GetAvailableSerials()
void SetSensorOrientation(SensorOrientation sensorOrientation)
void SetBodyTracker(BodyTracker bodyTracker)
SensorOrientation GetSensorOrientation()
BodyTracker GetBodyTracker()
void SetDeviceSerial(string deviceSerial)
BodyTracker represents the BodyData from the ORBBEC sensor as a skeleton. Important: BodyTracker pref...
Processes data from the ORBBEC sensor in a background thread to produce FrameData.
bool GetData(ref FrameData output)
SensorOrientation Orientation
bool HasStarted
Flag to determine of the background thread has started.