임 CSV 파일을 통해 읽은 Quaternions의 배열을 통해 게임 객체를 회전하려고합니다. 그것의 현재 내가 아닙니다 transform.rotation을 올바르게 업데이트하지 않는다고 생각하는 objectas를 회전시키지 않습니다. 이 문제를 해결하는 데 큰 도움이 될 것입니다. 더 이상 정보가 필요하면 알려주세요.Quaternions 배열을 통해 게임 개체를 회전하는 방법은 무엇입니까?
RotationAnimator.cs 회 스크립트 :
public class RotationAnimator : MonoBehaviour
{
public Transform playbackTarget;
[HideInInspector]
public bool playingBack = false;
public CSVReader csvReader;
public void PlayRecording()
{
// -1 as it reads the last blank line of the CSV for reasons
for (int row = 0; row < csvReader.quaternionRecords.Length-1; row++)
{
playbackTarget.rotation = new Quaternion(csvReader.quaternionRecords[row].x, csvReader.quaternionRecords[row].y, csvReader.quaternionRecords[row].z, csvReader.quaternionRecords[row].w);
}
}
}
CSVReader.cs CSV 파일
public class CSVReader : MonoBehaviour
{
public QuaternionRecord[] quaternionRecords;
public List<List<String>> fileData;
ILogging logger;
string path = "Assets\\Logs\\RotationList.csv";
private void OnEnable()
{
logger = Logging.GetCurrentClassLogger();
}
public void ReadFile()
{
var r = File.OpenText(path);
fileData = r.ReadToEnd().Split('\n').Select(s => s.Split(',').ToList()).ToList();
quaternionRecords = new QuaternionRecord[fileData.Count];
// skip last empty line at "file data.count -1"
for(int row = 0; row < fileData.Count-1; row++)
{
try
{
quaternionRecords[row] = new QuaternionRecord();
quaternionRecords[row].time = float.Parse(fileData[row][0]);
quaternionRecords[row].x = float.Parse(fileData[row][1]);
quaternionRecords[row].y = float.Parse(fileData[row][2]);
quaternionRecords[row].z = float.Parse(fileData[row][3]);
quaternionRecords[row].w = float.Parse(fileData[row][4]);
}
catch(Exception e)
{
Debug.Log("Ouch!");
}
}
r.Close();
}
public struct QuaternionRecord
{
public float time;
public float x;
public float y;
public float z;
public float w;
}
}
을 읽는 스크립트 PlayRecording이라고합니다
:
public void Playback()
{
Debug.Log("Beginning Playback...");
csvReader.ReadFile();
rotationAnimator.PlayRecording();
}
을 어떻게 사용하고 있습니까? PlayRecording을 어디에서 전화하고 있습니까? –
다른 스크립트에서 함수는 다음과 같습니다. public void Playback() { Debug.Log ("Beginning Playback ..."); csvReader.ReadFile(); rotationAnimator.PlayRecording(); rotationAnimator.playingBack = true; } – Nilmag
나는 당신이 무엇을보고 있는지, 나는 bool을 없애고 필요한 통화 기능을 추가했습니다. – Nilmag