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;
32 public void SetSensorOrientation(SensorOrientation sensorOrientation) { this.sensorOrientation = sensorOrientation; }
35 public void SetDeviceSerial(
string deviceSerial) { this.deviceSerial = deviceSerial; }
39 private void Awake() {
41 if (instance ==
null) {
48 private void OnDestroy() {
49 if (frameDataProvider !=
null) {
51 frameDataProvider =
null;
54 if (instance ==
this) {
59 private void Update() {
61 if (frameDataProvider !=
null &&
64 Debug.Log(
"New serial number " + deviceSerial +
"selected. Shutting down " + frameDataProvider.
DeviceSerial +
".");
66 frameDataProvider =
null;
70 if (isReady &&
null == frameDataProvider) {
75 for (
int i = 0; i < availableSerials.Count; ++i) {
76 if (availableSerials[i] == deviceSerial) {
77 Debug.Log(
"Attempting to start " + deviceSerial +
".");
78 frameDataProvider =
new FrameDataProvider(i, sensorOrientation, OnFrameDataProviderFinish);
84 if (connectDefaultIfNoSerialMatch && 0 < availableSerials.Count && frameDataProvider ==
null) {
85 deviceSerial = availableSerials[0];
90 if (
null == frameDataProvider ||
92 !frameDataProvider.
GetData(ref frameData) ||
93 frameData.NumDetectedBodies == 0) {
return; }
94 bodyTracker.UpdateSkeleton(frameData, sensorOrientation);
98 private void ScanDeviceSerials() {
99 int deviceCount = Device.GetInstalledCount();
100 availableSerials.Clear();
101 for (
int i = 0; i < deviceCount; ++i) {
103 using (Device device = Device.Open(i)) {
104 availableSerials.Add(device.SerialNum);
105 Debug.Log(
"BodyTrackerManager::ScanDeviceSerials - Found device with serial number " + device.SerialNum +
".");
108 }
catch (Exception e) {
109 Debug.LogError(e.ToString());
114 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.