// Update is called once per frame void Update() { NatNetSocketClient.Update(); if (NatNetSocketClient.IsInit()) { NatNetData streamData = NatNetSocketClient.GetStreamData(); foreach (KeyValuePair <int, NatNetRigidBody> rb in streamData.rigidBodies) { if (rbMap.ContainsKey(rb.Value.name)) { int id = rbMap[rb.Value.name]; if (rigidBodyObjects[id].gameObject != null) { if (rigidBodyObjects[id].applyTranslation) { rigidBodyObjects[id].gameObject.transform.position = transform.TransformPoint(rb.Value.position); } if (rigidBodyObjects[id].applyRotation) { rigidBodyObjects[id].gameObject.transform.rotation = transform.rotation * rb.Value.rotation; } } } } foreach (KeyValuePair <int, NatNetSkeleton> sk in streamData.skeletons) { if (sk.Value.receivedDescription && !sk.Value.initialized) { InitializeSkeleton(sk.Value); } if (sk.Value.initialized) { foreach (KeyValuePair <int, NatNetRigidBody> boneKV in sk.Value.bones) { boneKV.Value.bone.position = transform.TransformPoint(boneKV.Value.position); boneKV.Value.bone.rotation = transform.rotation * boneKV.Value.rotation; } //sk.Value.poseHandler.GetHumanPose(ref sk.Value.currentPose); } } } if (_deinitValue) { _deinitValue = false; NatNetSocketClient.Close(); } }
void OnApplicationQuit() { NatNetSocketClient.Close(); }