void Update() { if (BodyManager == null) { return; } _BodyManager = BodyManager.GetComponent <BodyManager>(); if (_BodyManager == null) { return; } Body[] data = _BodyManager.GetData(); 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)) { Destroy(_Bodies[trackingId]); _Bodies.Remove(trackingId); } } for (int idx = 0; idx < data.Length; idx++) { if (data[idx] == null) { continue; } if (data[idx].IsTracked /*&& idx == modelIndex*/) { RefreshBodyObject(data[idx]); } } }
// Update is called on each frames void Update() { //we need to store the keys of the tracked bodies in order to generate them //We check if the KinectManager has data to work with if (BodyManager == null) { return; } _BodyManager = BodyManager.GetComponent <BodyManager>(); if (_BodyManager == null) { return; } //We store the data of the bodies detected Kinect.Body[] data = _BodyManager.GetData(); if (data == null) { return; } ///////////////////////////////////////////////////////////////////////////////// //List of the tracked bodies (ulong is a an unsigned integer) List <ulong> trackedIds = new List <ulong>(); foreach (var body in data) { if (body == null) { continue; } if (body.IsTracked) { trackedIds.Add(body.TrackingId); //We add the ID of all the tracked body from the the current frame in the tracked body list if (!_Bodies.ContainsKey(body.TrackingId)) { //if the body isn't already in the _Bodies dictionnary, we create a new body object and add it to the dictionnary _Bodies[body.TrackingId] = CreateBodyObject(body.TrackingId, body); } //otherwise the body exists already and we have to refresh it RefreshBodyObject(body, _Bodies[body.TrackingId]); } } List <ulong> knownIds = new List <ulong>(_Bodies.Keys); // First delete untracked bodies foreach (ulong trackingId in knownIds) { if (!trackedIds.Contains(trackingId)) //we check every Ids in knownIds and check if the body are still tracked. If it isn't the case we destroy the body { //by updating the _Bodies dictionnary Destroy(_Bodies[trackingId]); _Bodies.Remove(trackingId); } } }
void Update() { if (BodyManager == null) { return; } SourceManager = BodyManager.GetComponent<BodyManager>(); if (SourceManager == null) { return; } Kinect.Body[] data = SourceManager.GetData(); 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)) { 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]); } } }
void Update() { int state = 0; if (BodyManager == null) { return; } if (Input.GetKeyDown(KeyCode.J)) { //Left platformRotate.TurnLeft(); } if (Input.GetKeyDown(KeyCode.L)) { //Right platformRotate.TurnRight(); } if (Input.GetKeyDown(KeyCode.I)) { //Flip platformRotate.Flip(); } //if (playerScript.flipjump) //{ // // .. increment a timer to count up to restarting. // flipTimer += Time.deltaTime; // if (flipTimer >= flipDelay) // { // playerScript.flipjump = false; // } //} //if (playerScript.flipjump) // playerScript.flipjump = false; _BodyManager = BodyManager.GetComponent<BodyManager>(); if (_BodyManager == null) { return; } Kinect.Body[] data = _BodyManager.GetData(); 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); Debug.Log("Found Body"); } } List<ulong> knownIds = new List<ulong>(_Bodies.Keys); // First delete untracked bodies foreach (ulong trackingId in knownIds) { if (!trackedIds.Contains(trackingId)) { Destroy(_Bodies[trackingId]); _Bodies.Remove(trackingId); } } foreach (var body in data) { if (body == null) { continue; } if (body.IsTracked) { //Check Hand State if body is being Tracked state = CheckLeftHandState(body.HandLeftState) + (2 * CheckRightHandState(body.HandRightState)); Debug.Log("state: " + state); switch (state) { case 0: signalStart = false; break; case 1: //Left Debug.Log("Left"); if (prevState == 0) platformRotate.TurnLeft(); break; case 2: //Right Debug.Log("Right"); signalStart = true; if (prevState == 0) platformRotate.TurnRight(); break; case 3: //Both Debug.Log("Both"); if (prevState == 0) { // playerScript.flipjump = true; platformRotate.Flip(); } break; default: break; } prevState = state; } } }
void Update() { int state = 0; if (BodyManager == null) { return; } if (Input.GetKeyDown(KeyCode.J)) { //Left platformRotate.TurnLeft(); } if (Input.GetKeyDown(KeyCode.L)) { //Right platformRotate.TurnRight(); } if (Input.GetKeyDown(KeyCode.I)) { //Flip platformRotate.Flip(); } //if (playerScript.flipjump) //{ // // .. increment a timer to count up to restarting. // flipTimer += Time.deltaTime; // if (flipTimer >= flipDelay) // { // playerScript.flipjump = false; // } //} //if (playerScript.flipjump) // playerScript.flipjump = false; _BodyManager = BodyManager.GetComponent <BodyManager>(); if (_BodyManager == null) { return; } Kinect.Body[] data = _BodyManager.GetData(); 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); Debug.Log("Found Body"); } } List <ulong> knownIds = new List <ulong>(_Bodies.Keys); // First delete untracked bodies foreach (ulong trackingId in knownIds) { if (!trackedIds.Contains(trackingId)) { Destroy(_Bodies[trackingId]); _Bodies.Remove(trackingId); } } foreach (var body in data) { if (body == null) { continue; } if (body.IsTracked) { //Check Hand State if body is being Tracked state = CheckLeftHandState(body.HandLeftState) + (2 * CheckRightHandState(body.HandRightState)); Debug.Log("state: " + state); switch (state) { case 0: signalStart = false; break; case 1: //Left Debug.Log("Left"); if (prevState == 0) { platformRotate.TurnLeft(); } break; case 2: //Right Debug.Log("Right"); signalStart = true; if (prevState == 0) { platformRotate.TurnRight(); } break; case 3: //Both Debug.Log("Both"); if (prevState == 0) { // playerScript.flipjump = true; platformRotate.Flip(); } break; default: break; } prevState = state; } } }
// Update is called once per frame void Update() { if (BodyManager == null) { return; } _BodyManager = BodyManager.GetComponent <BodyManager>(); if (_BodyManager == null) { return; } Body[] data = _BodyManager.GetData(); 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)) { 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]); } } }
void Update() { int state = 0; if (BodyManager == null) { return; } _BodyManager = BodyManager.GetComponent <BodyManager>(); if (_BodyManager == null) { return; } Kinect.Body[] data = _BodyManager.GetData(); 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)) { 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]); //Check Hand State if body is being Tracked state = (CheckHandState(body.HandLeftState) + (2 * CheckHandState(body.HandRightState))); switch (state) { case 0: break; case 1: //Left Debug.Log("Left"); break; case 2: //Right Debug.Log("Right"); break; case 3: //Both Debug.Log("Both"); break; default: break; } /* * CheckRightHandState(body.HandRightState); * CheckLeftHandState(body.HandLeftState); * * if(rightHandActive && leftHandActive) * { * //flip * Debug.LogError("BOTH"); * } */ } } }
void Update() { int state = 0; if (BodyManager == null) { return; } _BodyManager = BodyManager.GetComponent<BodyManager>(); if (_BodyManager == null) { return; } Kinect.Body[] data = _BodyManager.GetData(); 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)) { 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]); //Check Hand State if body is being Tracked state = (CheckHandState(body.HandLeftState) + (2 * CheckHandState(body.HandRightState))); switch (state) { case 0: break; case 1: //Left Debug.Log("Left"); break; case 2: //Right Debug.Log("Right"); break; case 3: //Both Debug.Log("Both"); break; default: break; } /* CheckRightHandState(body.HandRightState); CheckLeftHandState(body.HandLeftState); if(rightHandActive && leftHandActive) { //flip Debug.LogError("BOTH"); } */ } } }