//録画データを再生 private void PlayMotion() { //現在のインデックスが録画データ長を超えたら終了 if (this.playingTransformIndex >= this.playingTransformList.Count) { OnRecieveToStop(); return; } UpdatingTransformTimeSeries updatingTransformList = null; //経過時間を超える時刻のデータになるまで待つ while (this.elapsedTime >= this.playingTransformList[this.playingTransformIndex].elapsedTime) { updatingTransformList = this.playingTransformList[this.playingTransformIndex]; this.playingTransformIndex++; if (this.playingTransformIndex >= this.playingTransformList.Count) { break; } } if (updatingTransformList == null) { return; } //対象物体の位置・姿勢を現在のデータで更新 foreach (UpdatingTransformData updatingTransformData in updatingTransformList.GetUpdatingTransformList()) { updatingTransformData.UpdateTransform(); } //現在の把持物体を格納 this.graspedObjectsString = updatingTransformList.GetGraspedObjectsString(); //現在の接触物体を格納 this.collidingObjectsMap = new Dictionary <string, string>(updatingTransformList.GetCollidingObjectsMap()); }
//録画データの再生リストを作成 private void CreatePlayingTransformList() { this.playingTransformList.Clear(); List <Transform> transformOrder = new List <Transform>(); List <int> ignoredPathIndexes = new List <int>(); List <string> targetNames = new List <string>(); for (int index = 0; index < this.motionData.Count; index++) { string[] columnArray = this.motionData[index].Split(new char[] { '\t' }, 2); if (columnArray.Length < 2) { continue; } string headerStr = columnArray[0]; string dataStr = columnArray[1]; string[] headerArray = headerStr.Split(','); List <string> dataArray = new List <string>(dataStr.Split('\t')); List <string> collidingArray = new List <string>(this.collidingData[index].Split('\t')); //最初の定義の行の場合 if (int.Parse(headerArray[1]) == CookingSupportPlaybackCommon.TypeDefMotion) { transformOrder.Clear(); ignoredPathIndexes.Clear(); targetNames.Clear(); for (int i = 0; i < dataArray.Count; i++) { string transformPath = dataArray[i]; if (transformPath.Contains("Avatar")) { //再生対象のアバタにパスを変更 string replacedPath = transformPath.Replace("Avatar", this.instructor.name); transformOrder.Add(this.targetPathTransformMap[replacedPath]); } else if (this.targetPathTransformMap.ContainsKey(transformPath)) { transformOrder.Add(this.targetPathTransformMap[transformPath]); } else { //存在しないパスのインデックスを保存 ignoredPathIndexes.Add(i); Debug.Log("Couldn't find the object that path is " + transformPath); } } targetNames = collidingArray; } //それ以外のデータの行の場合 else if (int.Parse(headerArray[1]) == CookingSupportPlaybackCommon.TypeValMotion) { if (transformOrder.Count == 0) { continue; } //経過時間を格納 UpdatingTransformTimeSeries timeSeriesMotionsData = new UpdatingTransformTimeSeries { elapsedTime = float.Parse(headerArray[0]) }; for (int i = dataArray.Count - 1; i >= 0; i--) { //存在しないパスのインデックスのデータを削除 if (ignoredPathIndexes.Contains(i)) { dataArray.RemoveAt(i); } } //動作データを格納 for (int i = 0; i < dataArray.Count; i++) { string[] transformValues = dataArray[i].Split(','); UpdatingTransformData transformPlayer = new UpdatingTransformData(); transformPlayer.UpdatingTransform = transformOrder[i]; transformPlayer.LocalPosition = new Vector3(float.Parse(transformValues[0]), float.Parse(transformValues[1]), float.Parse(transformValues[2])); transformPlayer.LocalRotation = new Vector3(float.Parse(transformValues[3]), float.Parse(transformValues[4]), float.Parse(transformValues[5])); //スケールがある場合 if (transformValues.Length == 9) { transformPlayer.LocalScale = new Vector3(float.Parse(transformValues[6]), float.Parse(transformValues[7]), float.Parse(transformValues[8])); } //トランスフォームを追加 timeSeriesMotionsData.AddUpdatingTransformData(transformPlayer); } //把持物体の文字列を格納 timeSeriesMotionsData.AssignGraspedObjectsString(graspingData[index]); //接触物体のマップを格納 for (int i = 0; i < collidingArray.Count; i++) { timeSeriesMotionsData.AddCollidingObjectsMap(targetNames[i], collidingArray[i]); } //再生リストに追加 this.playingTransformList.Add(timeSeriesMotionsData); } } }