ScrollViewで入力ボタンを設置する所まで出来たので、
入力ボタンを押せばテキストが反映されるようにして行こうと思います。
まず、各ScrollView呼び出しのButtonTextに選択したテキストを反映してみます。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class InputFoamManager : MonoBehaviour {
public GameObject ImageFome; //入力フォーム取得
public GameObject CARDView; //対戦カードView取得
public GameObject ChView; //放送ChView取得
public GameObject TimeView; //放送時間View取得
public GameObject TextCARD; //CARDViewボタンのテキスト取得
public GameObject TextCh; //ChViewボタンのテキスト取得
public GameObject TextTime; //TimeViewボタンのテキスト取得
private int ViewBt; //ビューボタンの番号変数
private string CARDText,ChText,TimeText,DayText; //各テキスト
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
//各ScrollView呼び出し
public void ScrollViewCall(int Bt)
{
//いずれかのViewが開いてる時は他のViewは開かない
if (CARDView.activeSelf || ChView.activeSelf || TimeView.activeSelf)
{
return;
}
ViewBt = Bt; //クラス内でボタンナンバーを共有
switch (Bt)
{
case 1:
CARDView.SetActive(true);
break;
case 2:
ChView.SetActive(true);
break;
case 3:
TimeView.SetActive(true);
break;
}
}
//入力フォームを閉じる
public void Pushclose()
{
//いずれかのViewが開いている時はフォームを閉じない
if (CARDView.activeSelf || ChView.activeSelf || TimeView.activeSelf)
{
return;
}
ImageFome.SetActive(false);
}
//各Viewボタンのテキストに反映する
public void ViewTextRef(string Tx)
{
switch (ViewBt)
{
case 1:
TextCARD.GetComponent<Text>().text = Tx;
CARDView.SetActive(false);
break;
case 2:
TextCh.GetComponent<Text>().text = Tx;
ChView.SetActive(false);
break;
case 3:
TextTime.GetComponent<Text>().text = Tx;
TimeView.SetActive(false);
break;
}
}
}
前回のスクリプトに加筆修正した部分は、
・名前空間にUnityEngine.UIを追加
・各ButtonTextを取得する変数を追加
・ScrollView呼び出しボタンのナンバーを共有する変数追加
・呼び出しボタンのテキストを書き替えるメソッド追加
ここからはエディターで、それぞれの変数やボタンのOnClickをアタッチして、
プレイしてみます。
再生できない場合、ダウンロードは🎥こちら
無事テキストがボタンに反映されるようになりました。
続いて、カレンダー上のテキストに反映されるようにします。
カレンダーのテキストを書き替えるためには、
日ごとに反映させる必要があるので、どの日付か分かるようにします。
ついでに日枠を押すと入力フォームが開いて、テキストが反映されると
入力フォームが閉じるようにします。
上記スクリプトに
public GameObject[] CalendarText; //カレンダー上のテキストを取得
private int FrameNo; //カレンダーの枠番変数
private string CARDText,ChText,TimeText,DayText; //各テキスト
//各Viewボタンのテキストに反映する
public void ViewTextRef(string Tx)
{
switch (ViewBt)
{
case 1:
TextCARD.GetComponent<Text>().text = Tx;
CARDText = Tx;
CARDView.SetActive(false);
break;
case 2:
TextCh.GetComponent<Text>().text = Tx;
ChText = Tx;
ChView.SetActive(false);
break;
case 3:
TextTime.GetComponent<Text>().text = Tx;
TimeText = Tx;
TimeView.SetActive(false);
break;
}
}
//カレンダーの日毎のボタンを押した処理
public void PushDayButton(int frame)
{
if (ImageFome.activeSelf)
{
return;
}
//入力フォームを開く
ImageFome.SetActive(true);
FrameNo = frame;
}
//カレンダー上にテキストを反映させる
public void CalendarRef()
{
DayText = CARDText + "\n" + ChText + "\n" + TimeText;
CalendarText[FrameNo].GetComponent<Text>().text = DayText;
//反映後入力フォームを閉じる
ImageFome.SetActive(false);
}
少し説明すると、
日枠のボタンを押した時にint frameで枠番号を取得します。
クラス内の共有変数FrameNoに代入して、カレンダーのテキストに反映する
オブジェクト番号を指定しました。
CalendarRefメソッドのCalendarText[FrameNo]の部分です。
枠番0=CalendarText[0]の感じです。
最後に「反映する」ボタンを押すと入力フォームが閉じます。
少しエディターを編集します。

「反映する」ボタンを追加します。
OnClickにはCalendarRefメソッドを割り当てます。
入力フォームの準備は整ったので、Inspectorのチェックを外して消しておきます。
続けて、

CalendarText[]にSchedule0~36をアタッチします。

最後にDayButtonParentのButton0~36のOnClickを追加して、
PushDayButtonメソッドを割り当てます。
各ボタンの変数をButton0なら0のように、0~36の数字を入力します。
準備ができたので、プレイしてみます。
再生できない場合、ダウンロードは🎥こちら
無事カレンダー上に反映できるようになりました。
枠に一つのテキストなので、
改行しないと並んでテキストが表示されてしまいます。
スクリプトからテキストの改行を行う際は、”\n”を挟む必要があります。
なぜかVisualStudioで"\n"を入力すると表示は”¥n”になるので注意が必要でっす。
/ではなくて\です。間違い易いです。(´ー`) ウフフ
最後に完成版のスクリプトを載せておきます。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class InputFoamManager : MonoBehaviour {
public GameObject ImageFome; //入力フォーム取得
public GameObject CARDView; //対戦カードView取得
public GameObject ChView; //放送ChView取得
public GameObject TimeView; //放送時間View取得
public GameObject TextCARD; //CARDViewボタンのテキスト取得
public GameObject TextCh; //ChViewボタンのテキスト取得
public GameObject TextTime; //TimeViewボタンのテキスト取得
public GameObject[] CalendarText; //カレンダー上のテキストを取得
private int ViewBt; //ビューボタンの番号変数
private int FrameNo; //カレンダーの枠番変数
private string CARDText,ChText,TimeText,DayText; //各テキスト
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
//各ScrollView呼び出し
public void ScrollViewCall(int Bt)
{
//いずれかのViewが開いてる時は他のViewは開かない
if (CARDView.activeSelf || ChView.activeSelf || TimeView.activeSelf)
{
return;
}
ViewBt = Bt; //クラス内でボタンナンバーを共有
switch (Bt)
{
case 1:
CARDView.SetActive(true);
break;
case 2:
ChView.SetActive(true);
break;
case 3:
TimeView.SetActive(true);
break;
}
}
//入力フォームを閉じる
public void Pushclose()
{
//いずれかのViewが開いている時はフォームを閉じない
if (CARDView.activeSelf || ChView.activeSelf || TimeView.activeSelf)
{
return;
}
ImageFome.SetActive(false);
}
//各Viewボタンのテキストに反映する
public void ViewTextRef(string Tx)
{
switch (ViewBt)
{
case 1:
TextCARD.GetComponent<Text>().text = Tx;
CARDText = Tx;
CARDView.SetActive(false);
break;
case 2:
TextCh.GetComponent<Text>().text = Tx;
ChText = Tx;
ChView.SetActive(false);
break;
case 3:
TextTime.GetComponent<Text>().text = Tx;
TimeText = Tx;
TimeView.SetActive(false);
break;
}
}
//カレンダーの日毎のボタンを押した処理
public void PushDayButton(int frame)
{
if (ImageFome.activeSelf)
{
return;
}
//入力フォームを開く
ImageFome.SetActive(true);
FrameNo = frame;
}
//カレンダー上にテキストを反映させる
public void CalendarRef()
{
DayText = CARDText + "\n" + ChText + "\n" + TimeText;
CalendarText[FrameNo].GetComponent<Text>().text = DayText;
//反映後入力フォームを閉じる
ImageFome.SetActive(false);
}
}
×
この広告は90日以上新しい記事の投稿がないブログに表示されております。
この記事へのコメント