/// <summary> /// Recording happens here... depending on the FPS... I hope you have an okay bucket (PC) ;) /// </summary> /// <returns></returns> IEnumerator Coroutine_Recording() { inputData = new List <string>(); while (_recording) { yield return(null); string decimalPoint = "F5"; //how precise input do you want to capture //roll,pitch,yaw,throttle in that particular order as in betaflight string posX = PlaybackScript.GetComponent <Rigidbody>().position.x.ToString(); string posY = PlaybackScript.GetComponent <Rigidbody>().position.y.ToString(); string posZ = PlaybackScript.GetComponent <Rigidbody>().position.z.ToString(); string _dataToAdd = PlaybackScript.Roll.ToString(decimalPoint) + "#" + PlaybackScript.Pitch.ToString(decimalPoint) + "#" + PlaybackScript.Yaw.ToString(decimalPoint) + "#" + PlaybackScript.Throttle.ToString(decimalPoint) + "#" + "(" + posX + "," + posY + "," + posZ + ")" + "#" + PlaybackScript.GetComponent <Rigidbody>().rotation.eulerAngles + "#" + PlaybackScript.GetComponent <Rigidbody>().velocity + "#" + PlaybackScript.GetComponent <Rigidbody>().angularVelocity + "#" + PlaybackScript.GetComponent <Rigidbody>().drag + "#" + PlaybackScript.GetComponent <Rigidbody>().angularDrag + "#" + PlaybackScript.LeftHanded.ToString(); inputData.Add(_dataToAdd); } if (OnRecordingStop != null) { OnRecordingStop(); } }
/// <summary> /// Recording happens here... depending on the FPS... I hope you have an okay bucket (PC) ;) /// </summary> /// <returns></returns> IEnumerator Coroutine_Recording() { inputData = new List <string>(); while (_recording) { yield return(null); string decimalPoint = "F5"; //how precise input do you want to capture //roll,pitch,yaw,throttle in that particular order as in betaflight string posX = PlaybackScript.GetComponent <Rigidbody>().position.x.ToString(); string posY = PlaybackScript.GetComponent <Rigidbody>().position.y.ToString(); string posZ = PlaybackScript.GetComponent <Rigidbody>().position.z.ToString(); string posXFixed = PlaybackScript.droneMovement.droneObject.localRotation.eulerAngles.x.ToString(); string posYFixed = PlaybackScript.droneMovement.droneObject.localRotation.eulerAngles.y.ToString(); string posZFixed = PlaybackScript.droneMovement.droneObject.localRotation.eulerAngles.z.ToString(); string rotX = PlaybackScript.GetComponent <Rigidbody>().rotation.eulerAngles.x.ToString(); string rotY = PlaybackScript.GetComponent <Rigidbody>().rotation.eulerAngles.y.ToString(); string rotZ = PlaybackScript.GetComponent <Rigidbody>().rotation.eulerAngles.z.ToString(); string rotAnimatedX = PlaybackScript.droneMovement.animatedGameObject.transform.localRotation.eulerAngles.x.ToString(); string rotAnimatedY = PlaybackScript.droneMovement.animatedGameObject.transform.localRotation.eulerAngles.y.ToString(); string rotAnimatedZ = PlaybackScript.droneMovement.animatedGameObject.transform.localRotation.eulerAngles.z.ToString(); string velocityX = PlaybackScript.GetComponent <Rigidbody>().velocity.x.ToString(); string velocityY = PlaybackScript.GetComponent <Rigidbody>().velocity.y.ToString(); string velocityZ = PlaybackScript.GetComponent <Rigidbody>().velocity.z.ToString(); string _dataToAdd = "(" + posX + "," + posY + "," + posZ + ")" + "#" + "(" + posXFixed + "," + posYFixed + "," + posZFixed + ")" + "#" + "(" + rotX + "," + rotY + "," + rotZ + ")" + "#" + "(" + rotAnimatedX + "," + rotAnimatedY + "," + rotAnimatedZ + ")" + "#" + PlaybackScript.Vertical_W.ToString() + "#" + PlaybackScript.Vertical_S.ToString() + "#" + PlaybackScript.Horizontal_A.ToString() + "#" + PlaybackScript.Horizontal_D.ToString() + "#" + PlaybackScript.Vertical_I.ToString() + "#" + PlaybackScript.Vertical_K.ToString() + "#" + PlaybackScript.Horizontal_J.ToString() + "#" + PlaybackScript.Horizontal_L.ToString() + "#" + "(" + velocityX + "," + velocityY + "," + velocityZ + ")"; inputData.Add(_dataToAdd); } if (OnRecordingStop != null) { OnRecordingStop(); } }
IEnumerator Coroutine_Playback(DataReadingStructure[] dataFromSaveFile, FlightRecorderPlayback flightRecorderPlayback, Action callback) { Debug.Log("•Started playing playback"); //Position on starting od recording point flightRecorderPlayback.GetComponent <Rigidbody>().position = dataFromSaveFile[0].Position; flightRecorderPlayback.droneMovement.droneObject.localRotation = Quaternion.Euler(dataFromSaveFile[0].RotationFixed); flightRecorderPlayback.GetComponent <Rigidbody>().rotation = Quaternion.Euler(dataFromSaveFile[2].Rotation); flightRecorderPlayback.droneMovement.animatedGameObject.transform.localRotation = Quaternion.Euler(dataFromSaveFile[0].RotationAnimated); //start playing data on our drone int i = 0; while (i < dataFromSaveFile.Length - 1) { yield return(null); flightRecorderPlayback.GetComponent <Rigidbody>().position = Vector3.Lerp(flightRecorderPlayback.GetComponent <Rigidbody>().position, dataFromSaveFile[i].Position, Time.deltaTime * 15); flightRecorderPlayback.droneMovement.droneObject.localRotation = Quaternion.Euler(dataFromSaveFile[i].RotationFixed); flightRecorderPlayback.GetComponent <Rigidbody>().rotation = Quaternion.Euler(dataFromSaveFile[i].Rotation); flightRecorderPlayback.droneMovement.animatedGameObject.transform.localRotation = Quaternion.Euler(dataFromSaveFile[i].RotationAnimated); flightRecorderPlayback.Vertical_W = dataFromSaveFile[i].Vertical_W; flightRecorderPlayback.Vertical_S = dataFromSaveFile[i].Vertical_S; flightRecorderPlayback.Horizontal_A = dataFromSaveFile[i].Horizontal_A; flightRecorderPlayback.Horizontal_D = dataFromSaveFile[i].Horizontal_D; flightRecorderPlayback.Vertical_I = dataFromSaveFile[i].Vertical_I; flightRecorderPlayback.Vertical_K = dataFromSaveFile[i].Vertical_K; flightRecorderPlayback.Horizontal_J = dataFromSaveFile[i].Horizontal_J; flightRecorderPlayback.Horizontal_L = dataFromSaveFile[i].Horizontal_L; flightRecorderPlayback.GetComponent <Rigidbody>().velocity = dataFromSaveFile[i].Velocity; i++; } Debug.Log("•Finished playing playback"); callback.Invoke(); }
IEnumerator Coroutine_Playback(DataReadingStructure[] dataFromSaveFile, FlightRecorderPlayback flightRecorderPlayback, Action callback) { Debug.Log("•Started playing playback"); //Position on starting od recording point flightRecorderPlayback.Pitch = dataFromSaveFile[0].Pitch; flightRecorderPlayback.Roll = dataFromSaveFile[0].Roll; flightRecorderPlayback.Yaw = dataFromSaveFile[0].Yaw; flightRecorderPlayback.Throttle = dataFromSaveFile[0].Throttle; flightRecorderPlayback.GetComponent <Rigidbody>().position = dataFromSaveFile[0].Position; flightRecorderPlayback.GetComponent <Rigidbody>().rotation = Quaternion.Euler(dataFromSaveFile[0].Rotation); flightRecorderPlayback.GetComponent <Rigidbody>().velocity = dataFromSaveFile[0].Velocity; flightRecorderPlayback.GetComponent <Rigidbody>().angularVelocity = dataFromSaveFile[0].AngularVelocity; flightRecorderPlayback.GetComponent <Rigidbody>().drag = dataFromSaveFile[0].Drag; flightRecorderPlayback.GetComponent <Rigidbody>().angularDrag = dataFromSaveFile[0].AngularDrag; flightRecorderPlayback.LeftHanded = bool.Parse(dataFromSaveFile[0].LeftHanded); //start playing data on our drone int i = 0; while (i < dataFromSaveFile.Length - 1) { yield return(null); flightRecorderPlayback.Pitch = dataFromSaveFile[i].Pitch; flightRecorderPlayback.Roll = dataFromSaveFile[i].Roll; flightRecorderPlayback.Yaw = dataFromSaveFile[i].Yaw; flightRecorderPlayback.Throttle = dataFromSaveFile[i].Throttle; flightRecorderPlayback.GetComponent <Rigidbody>().position = Vector3.Lerp(flightRecorderPlayback.GetComponent <Rigidbody>().position, dataFromSaveFile[i].Position, Time.deltaTime * 15); flightRecorderPlayback.GetComponent <Rigidbody>().rotation = Quaternion.Lerp(flightRecorderPlayback.GetComponent <Rigidbody>().rotation, Quaternion.Euler(dataFromSaveFile[i].Rotation), Time.deltaTime * 15); flightRecorderPlayback.GetComponent <Rigidbody>().velocity = dataFromSaveFile[i].Velocity; flightRecorderPlayback.GetComponent <Rigidbody>().angularVelocity = dataFromSaveFile[i].AngularVelocity; flightRecorderPlayback.GetComponent <Rigidbody>().drag = dataFromSaveFile[i].Drag; flightRecorderPlayback.GetComponent <Rigidbody>().angularDrag = dataFromSaveFile[i].AngularDrag; flightRecorderPlayback.LeftHanded = bool.Parse(dataFromSaveFile[0].LeftHanded); i++; } Debug.Log("•Finished playing playback"); callback.Invoke(); }