C言語で書き出されるcsvファイルをUnityでStreamReader()を用いて読み込んでいます。
CSVファイルは随時更新され,UnityがCSVファイルを読み込み、その中身に適したテクスチャをUnityで貼りたいと考えています。
以下はシステムの流れになります。
0. スペースキー入力
0. C言語が、CSVファイルを書き出し、フラグ(csvファイル)をたてる
0. Unityはフラグを確認し、立っていたらCSVファイルを読み込む
0. CSVファイルの内容に適したテクスチャを貼りつける
これを繰り返すシステムになります。
Unityのエディタ上ではうまくいったのですが、ビルドをすると、外部に置いていたCSVファイルが見つからないと言われます。
エディタ上では適応されたので、ファイルの場所は間違ってないと思います。が、ビルドすると場所が変わってしまうのでしょうか?
また、Assets/StreamingAssetsにも置いてみましたが、そこでは組み込まれてしまうため、テクスチャが変更されません。
ビルドをしたときのCSVファイルに従ったテクスチャが貼られています。
なにか方法があれば、教えていただければと思います。
Unity
1/* この上部でテクスチャの宣言 */ 2void Update() 3{ 4 if (Input.GetKeyDown(KeyCode.Space)) 5 { 6 StartCoroutine("WaitCoordinateLeft"); 7 } 8} 9 10IEnumerator WaitCoordinateLeft() 11{ 12 int e, c, p, s; 13 string str1 = "error"; 14 string str2 = "error"; 15 16 for (int count = 0; count < 10; count++) 17 { 18 19 /* フラグの確認 */ 20 while (true) 21 { 22 //string f = Application.dataPath + "/StreamingAssets/flag_coordinate.csv"; 23 string f = Application.dataPath + "../../../csv/flag_coordinate.csv"; 24 StreamReader sr = new StreamReader(f, Encoding.GetEncoding("Shift_JIS")); 25 str1 = sr.ReadToEnd(); 26 27 int sets = int.Parse(str1); 28 29 Debug.Log(str1 + " : " + sets); 30 sr.Close(); 31 if (sets == count) 32 { 33 break; 34 } 35 else 36 { 37 Debug.Log("now loading..."); 38 break; 39 }; 40 } 41 42 //Debug.Log("コーディネートの読み込み " + count); 43 44 /* コーディネートの読み込み */ 45 //string f2 = Application.dataPath + "/StreamingAssets/coordinate.csv"; 46 string f2 = Application.dataPath + "../../../csv/coordinate.csv"; 47 StreamReader sr2 = new StreamReader(f2, Encoding.GetEncoding("Shift_JIS")); 48 str2 = sr2.ReadToEnd(); 49 50 sr2.Close(); 51 52 var csvDatas = str2.Split(new[] { ',', '\n' }, StringSplitOptions.RemoveEmptyEntries); 53 54 e = int.Parse(csvDatas[1]); 55 c = int.Parse(csvDatas[2]); 56 p = int.Parse(csvDatas[3]); 57 s = int.Parse(csvDatas[4]); 58 59 /* コーディネートの設定 */ 60 SetEye(e); 61 SetCloth(c); 62 SetPattern(p); 63 SetShoes(s); 64 65 Debug.Log("コーディネートの設定" + (count + 1)); 66 Debug.Log("Left Coordinate " + count + " is " + e + " " + c + " " + p + " " + s); 67 68 Flag.CatchFlag(count); 69 //string f3 = Application.dataPath + "/../../csv/flag_coordinateSets.csv"; 70 //StreamWriter sw = new StreamWriter(f3, false, Encoding.GetEncoding("Shift_JIS")); 71 //sw.WriteLine(count); 72 //sw.Close(); 73 74 yield return new WaitForSeconds(12); 75 } 76}
C
1int main(){ 2 int c; //現対戦数 3 if (GetAsyncKeyState(VK_SPACE)){ //スペースキー入力により開始 4 5 /* 各対戦 */ 6 for (c = 0; c < NUMBER - 1; c++){ 7 printf("%d対戦目\n", c + 1); 8 9 select_individual(); //対戦する個体の選択 10 OutputChoiceIndividual(); //対戦する個体をunityに渡す 11 printf("%d対戦個体:%d vs %d\n", c + 1, D.indivi[0], D.indivi[1]); 12 13 Check_coordinatie(c); //コーディネートを出力しましたよ 14 15 EyeTrack(); //視線情報の取得 16 OutputGazeposi(); //視線位置の出力 17 18 judgement_game(); //勝敗判定 19 calclation_fitness(); //評価値計算 20 } 21 } 22 23 return 0; 24} 25 26void OutputChoiceIndividual(){ 27 FILE *fci; 28 29 sprintf(F.nIndividual, "..\..\..\csv\coordinate.csv", C.NumG); 30 //sprintf(F.nIndividual, "..\..\..\DisplayCoordinate\Assets\StreamingAssets\coordinate.csv", C.NumG); 31 32 /* ファイルオープン */ 33 if ((fci = fopen(F.nIndividual, "w")) == NULL){ 34 printf("Individualファイルオープン失敗\n"); 35 exit(-1); 36 } 37 38 for (int i = 0; i < 2; i++){ 39 for (int j = 0; j < 5; j++){ 40 fprintf(fci, "%d, ", CG[D.indivi[i]].decimal[j]); 41 printf("%d, ", CG[D.indivi[i]].decimal[j]); 42 } 43 fprintf(fci, "\n"); 44 printf("\n"); 45 } 46 47 fclose(fci); 48}
回答2件
あなたの回答
tips
プレビュー