public void SetQuestion_type1(Question.QuesStructor ques) { var myCanvas = GameObject.Find("Canvas").GetComponent <Canvas>(); QuestionDefaultlySetting(ques); Vector2 offset = new Vector2(10, Screen.height / 2); for (int i = 0; i < ques.ans.Count; ++i) { //ボタン生成 Button button = Instantiate(AnswerPrefab); button.transform.SetParent(myCanvas.transform.FindChild("Panel")); button.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1); //ボタンの名前は答え番号で button.name = (i + 1).ToString(); //答えの内容設定 Text ButtonText = button.transform.GetChild(0).GetComponent <Text>(); ButtonText.text = ques.ans[i]; /*ボタンのサイズ設定*/ Vector2 buttonsize = button.GetComponent <RectTransform>().sizeDelta; SetButtonSize(ButtonText, button.GetComponent <RectTransform>(), ref buttonsize); //位置設定 //float offset = buttonsize.x; button.transform.position = offset; offset = new Vector2(offset.x + buttonsize.x * myCanvas.GetComponent <RectTransform>().localScale.x, offset.y); //管理のため、リストに入れる CurAnswers.Add(button); } }
void QuestionDefaultlySetting(Question.QuesStructor ques) { //タイプ curType = ques.type; //質問 QuestionText.text = "Q. " + ques.ques; }
/*******************************************************/ /*ファイルから問題を読み込み、questionsリストに格納する*/ public void SetQuestions(ref List <Question.QuesStructor> question) { question.Clear(); SetTypeText(); //ファイルからList<string>を得て格納 List <string> allLines = SetToStringList(LoadStringFromFile()); for (int i = 0; i < allLines.Count; ++i) { //現在の行 string aLine = allLines[i]; if (aLine[0] == 'Q') { try { //問題からずれる行数を数える int cnt = 0; //問題の構造体を作成 Question.QuesStructor temp = new Question.QuesStructor(); temp.ans = new List <string>(); //次の行に該当する要素を当てる temp.type = int.Parse(allLines[i + ++cnt].TrimStart('T')); //タイプ文字 temp.typetext = TypeText[temp.type - 1]; temp.ques = allLines[i + ++cnt]; //答えの数は可変的。Aが出るまで答えとして読み続ける while (allLines[i + cnt + 1][0] != 'A') { temp.ans.Add(allLines[i + ++cnt]); } //正解 temp.corAns = int.Parse(allLines[i + (++cnt)].TrimStart('A')); //リストに格納 question.Add(temp); i += cnt; } catch (System.ArgumentOutOfRangeException e) { Debug.Log(e); return; } } } }