private Body GetKinectBody() { if (_sourceManager == null) { return(null); } if (_bodySource == null) { _bodySource = _sourceManager.GetComponent <VRKinectBodySource>(); } if (_bodySource == null) { return(null); } Body[] kinectBodies = _bodySource.GetData(); if (kinectBodies == null) { return(null); } var kinectBody = kinectBodies[_bodyIndex]; return(kinectBody); }
void Update() { if (BodySourceManager == null) { return; } _bodyManager = BodySourceManager.GetComponent <VRKinectBodySource>(); if (_bodyManager == null) { return; } Kinect.Body[] data = _bodyManager.GetData(); if (data != null) { var body = ClosestBody(data); if (body != null) { if (body.IsTracked) { Joint[0].transform.localPosition = GetVector3FromJoint(body.Joints[Kinect.JointType.Head]); } } } }
void Update() { if (_sensor == null) { _sensor = _bodySource.Sensor; if (_sensor == null) { return; } _avatars = new GameObject[_sensor.BodyFrameSource.BodyCount]; _activeAvatars = new bool[_sensor.BodyFrameSource.BodyCount]; } Body[] kinectBodies = _bodySource.GetData(); if (kinectBodies == null) { //Destroy all avatars that exist for (int bodyIndex = 0; bodyIndex < _sensor.BodyFrameSource.BodyCount; bodyIndex++) { if (_avatars[bodyIndex] == null) { continue; } Destroy(_avatars[bodyIndex]); _avatars[bodyIndex] = null; _activeAvatars[bodyIndex] = false; } return; } for (int bodyIndex = 0; bodyIndex < _sensor.BodyFrameSource.BodyCount; bodyIndex++) { if (kinectBodies[bodyIndex] != null) { if (!_activeAvatars[bodyIndex] && kinectBodies[bodyIndex].IsTracked) { _avatars[bodyIndex] = Instantiate(_avatar); _avatars[bodyIndex].transform.SetParent(gameObject.transform); _avatars[bodyIndex].GetComponent <JointPositionControl>().SetBodyIndex(bodyIndex); _avatars[bodyIndex].GetComponent <JointOrientationControl>().SetBodyIndex(bodyIndex); _activeAvatars[bodyIndex] = true; } else if (_activeAvatars[bodyIndex] && !kinectBodies[bodyIndex].IsTracked) { //Destroy the avatar if it exists but the corresponding body is not being tracked Destroy(_avatars[bodyIndex]); _avatars[bodyIndex] = null; _activeAvatars[bodyIndex] = false; } } else { //Destroy the avatar if the body is null Destroy(_avatars[bodyIndex]); _avatars[bodyIndex] = null; _activeAvatars[bodyIndex] = false; } } }