CSVのテキストはテキスト内に\nとかいてても,改行と認識されない.そこで,強制的に@を改行コードに読み替える方法で回避する
テキストの改行カ所に半角の@を入れる.そこが改行される.
using UnityEngine; using System; using System.Collections; using System.Collections.Generic; using System.IO;//use for file read using UnityEngine.UI;//use unity gui public class quiz : MonoBehaviour { //public string[] qq; // Use this for initialization public ArrayList qq =new ArrayList();//question store to this array private int no;//this means number public int maxQ = 3;//count of quiz public Text quizText, kaisetsu; //Text用変数 public Text bt1,bt2,bt3,bt4;//for assign btn tex public int answer;//answer number public int selected;//selected btn //public Toggle tog1, tog2, tog3, tog4; public ToggleGroup tgg1;//select btn group public GameObject kaisetsuPanelAlert; public GameObject seikaiPanelAlert; public GameObject ngPanelAlert; public GameObject selectAlert; void Start () { //Android is load from streming Assets floder // //jar:file://" + Application.dataPath + "!/assets" + "/"; //example // // TextAsset csv = Resources.Load("question") as TextAsset; // StringReader reader = new StringReader(csv.text); // while (reader.Peek () > -1) { // string line = reader.ReadLine (); // string[] values = line.Split (','); // Debug.Log (values[0]); // } kaisetsuPanelAlert.SetActive (false); seikaiPanelAlert.SetActive (false); ngPanelAlert.SetActive (false); selectAlert.SetActive (false); // no = 0;//initialize of quiz count //ArrayList qq =new ArrayList(); TextAsset csv = Resources.Load("question") as TextAsset; StringReader reader = new StringReader(csv.text); while (reader.Peek () > -1) { qq.Add (reader.ReadLine ()); } //Debug.Log ((string)qq[1]); qread ();//show first question } // Update is called once per frame void Update () { } public void tog1press(){ answer = 1; } public void tog2press(){ answer = 2; } public void tog3press(){ answer = 3; } public void tog4press(){ answer = 4; } public void qread(){//next mondai // for(no = 0; no < maxQ; no++){ tgg1.SetAllTogglesOff(); string qqq=(string)qq[no]; string[] values = qqq.Split(',');//values is string array //GameObject.Find ("SectionText").GetComponent<Text>().text=Section[ int.Parse(values[0]) ]; // string atxt = ""; // string atxt1 = ""; // string atxt2 = ""; // string atxt3 = ""; // int mode = Random.Range (0, 10); // if (mode == 0) // { // atxt=values[2];GoodNo=1; // atxt1=values[1]; // atxt2=values[4]; // atxt3=values[5]; // } string test1 = (string)values[0]; // quizText.text = (string)values[0]; quizText.text = test1.Replace("@", "\n"); selected = int.Parse((string)values [1]);//csv is text, so, covert to string bt1.text = (string)values[2]; bt2.text = (string)values[3]; bt3.text = (string)values[4]; bt4.text = (string)values[5]; string kaisetsuKaigyou = (string)values[6]; kaisetsu.text = kaisetsuKaigyou.Replace("@", "\n"); //kaisetsu.text = (string)values[6]; if (no < maxQ) { //quiz count limit no++; }else{ no = maxQ; //kokode resulthe,, } // Debug.Log(tgl); //} } public void answerCheck(){ //Boolean selectCheck = tgg1.AnyTogglesOn; if (!tgg1.AnyTogglesOn()) { selectAlert.SetActive (true); return; } if (selected == answer) { seikaiPanelAlert.SetActive (true); // Debug.Log ("seikai"); } else { ngPanelAlert.SetActive (true); // Debug.Log ("No!"); } } public void hideKaisetsuPanel(){ kaisetsuPanelAlert.SetActive (false); qread (); } public void showKaisetsunOK(){ seikaiPanelAlert.SetActive (false); kaisetsuPanelAlert.SetActive (true); } public void showKaisetsuNG(){ ngPanelAlert.SetActive (false); kaisetsuPanelAlert.SetActive (true); } public void hideSelecyAlert(){ selectAlert.SetActive (false); } }