void Update() { Kinect.Body[] data = kinectInputManager.GetBodyData(); if (data == null) { return; } trackedIds.Clear(); foreach (var body in data) { if (body == null) { continue; } if (body.IsTracked) { trackedIds.Add(body.TrackingId); } } // delete untracked bodies /* * foreach(ulong trackingId in bodies.Keys) { * if(!trackedIds.Contains(trackingId)) { * limitedTrackedIds.Remove(trackingId); * bodies.Remove(trackingId); * } * } */ List <ulong> keys = new List <ulong>(bodies.Keys); foreach (ulong trackingId in keys) { if (!trackedIds.Contains(trackingId)) { limitedTrackedIds.Remove(trackingId); bodies.Remove(trackingId); } } foreach (var body in data) { if (body == null) { continue; } if (body.IsTracked) { if ((limitedTrackedIds.Count < nbBodiesTracked) && !limitedTrackedIds.Contains(body.TrackingId)) { limitedTrackedIds.Add(body.TrackingId); bodies[body.TrackingId] = CreateBodyObject(body); } if (limitedTrackedIds.Contains(body.TrackingId)) { RefreshBodyObject(body); } } } }
//// FULL BODY - MID void Update() { //TODO: should be done in "Start" (?) if (BodySourceManager == null) { return; } //TODO: should be done in "Start" (?) _BodyManager = BodySourceManager.GetComponent <KinectInputManager>(); if (_BodyManager == null) { return; } Kinect.Body[] data = _BodyManager.GetBodyData(); if (data == null) { return; } List <ulong> trackedIds = new List <ulong>(); foreach (var body in data) { if (body == null) { continue; } if (body.IsTracked) { trackedIds.Add(body.TrackingId); } } List <ulong> knownIds = new List <ulong>(_Bodies.Keys); // First delete untracked bodies foreach (ulong trackingId in knownIds) { if (!trackedIds.Contains(trackingId)) { //TODO! head.parent = null; Destroy(_Bodies[trackingId]); _Bodies.Remove(trackingId); } } foreach (var body in data) { if (body == null) { continue; } if (body.IsTracked) { if (!_Bodies.ContainsKey(body.TrackingId)) { _Bodies[body.TrackingId] = CreateBodyObject(body.TrackingId); } RefreshBodyObject(body, _Bodies[body.TrackingId]); } } }