UnityでScroll View内に動的にボタンを追加する動きを実装しています。
エミュレーター上では追加されているのですが、実機でビルドすると表示されません。
以下、原因特定するために試したことです。全て失敗しました。
1.動的な追加に問題がある可能性がある。
予め、Content内にボタンを配置しました。
2.ボタンの表示がうまくいかないため、テキストを追加
こちらもダメでした。
下記のソースコードは、QRコードを読み取った際にQR情報をContent内に動的に追加する動きを実装しています。
描画順はCanvas→Panel→Scroll View→ViewPort→Contentです。
表示されない原因をご教示頂きたいです。
よろしくお願いいたします。
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using UnityEngine.UI; 5using ZXing; 6using ZXing.QrCode; 7 8public class QRReader : MonoBehaviour { 9 10 public int height = 1920; 11 public int width = 1080; 12 public int fps = 60; 13 public string strqrText; 14 private WebCamTexture webCamTexture; 15 public PQRCodeManager qrManager; 16 public GameObject QRList; 17 RawImage rawImage; 18 19 [SerializeField] 20 GameObject goQRTextResult; 21 Transform QRContent; 22 private List<GameObject> cloneList = new List<GameObject>(); 23 24 // Use this for initialization 25 void Start () { 26 QRList = Resources.Load ("prefab/StepButton") as GameObject; 27 goQRTextResult = GameObject.FindGameObjectWithTag ("parent"); 28 WebCamDevice[] devices = WebCamTexture.devices; 29 //webカメラの検索 30 for (int i = 0; i < devices.Length; i++) { 31 Debug.Log (devices [i].name); 32 if (devices [i].name == null) { 33 break; 34 } 35 } 36 WebCamDevice userWebCamDevice = WebCamTexture.devices [0]; 37 rawImage = this.GetComponent<RawImage> (); 38 webCamTexture = new WebCamTexture (userWebCamDevice.name, height, width, fps); 39 40 rawImage.texture = webCamTexture; 41 webCamTexture.Play (); 42 43 this.qrManager = new PQRCodeManager (); 44 } 45 46 // Update is called once per frame 47 void Update () { 48 strqrText = this.qrManager.read (webCamTexture); 49 createPrefab (strqrText); 50 } 51 52 //子オブジェクトの作成 53 void createPrefab(string strqrText){ 54 55 if (strqrText.Equals ("-1")) { 56 //Debug.Log ("The value is -1"); 57 }else{ 58 //Scroll Viewに要素を追加する 59 GameObject clone = Instantiate (QRList) as GameObject; 60 cloneList.Add (clone); 61 62 clone.transform.Find ("ProcessText").GetComponent<Text> ().text = strqrText; 63 clone.transform.name = strqrText; 64 clone.transform.SetParent (goQRTextResult.transform, false); 65 } 66 } 67} 68