private void UpdatePose() { poseHandler.GetHumanPose(ref poseData); recordablePose = new RecordablePose(); recordablePose.bodyPosition = poseData.bodyPosition; recordablePose.bodyRotation = poseData.bodyRotation; recordablePose.muscles = (float[])poseData.muscles.Clone(); poseDict.Add(currentTime, recordablePose); currentFrame++; }
private void LoadPoseData() { if (!Application.isPlaying && !loadInEditor) { return; } if (loadPath == null) { Debug.LogError("***NO LOAD PATH SET ON " + gameObject.name + "***"); return; } string[] splitPath = loadPath.Split('/'); string filename = splitPath[splitPath.Length - 1]; Debug.Log("===LOADING POSE: " + filename.ToUpper() + "==="); BinaryFormatter formatter = new BinaryFormatter(); SurrogateSelector surrogateSelector = new SurrogateSelector(); Vector3SerializationSurrogate vector3SS = new Vector3SerializationSurrogate(); QuaternionSerializationSurrogate quatSS = new QuaternionSerializationSurrogate(); surrogateSelector.AddSurrogate(typeof(Vector3), new StreamingContext(StreamingContextStates.All), vector3SS); surrogateSelector.AddSurrogate(typeof(Quaternion), new StreamingContext(StreamingContextStates.All), quatSS); formatter.SurrogateSelector = surrogateSelector; FileStream file = File.Open(loadPath, FileMode.Open); Dictionary <float, RecordablePose> recordablePoseData = (Dictionary <float, RecordablePose>)formatter.Deserialize(file); file.Close(); poseDict = new Dictionary <float, HumanPose>(recordablePoseData.Keys.Count); foreach (var key in recordablePoseData.Keys) { RecordablePose rPose = recordablePoseData[key]; HumanPose pose = new HumanPose(); pose.bodyPosition = rPose.bodyPosition; pose.bodyRotation = rPose.bodyRotation; pose.muscles = rPose.muscles; poseDict.Add(key, pose); } sortedKeys = new List <float>(recordablePoseData.Keys); sortedKeys.Sort(); totalFrames = recordablePoseData.Keys.Count; Debug.Log("===SUCCESSFULLY LOADED " + filename.ToUpper() + "==="); if (playOnAwake) { StartPlaying(); } }