facebook twitter hatena line email

「Unity/リスト表示」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(リストの部品がずれる場合)
(リストの部品がずれる場合)
行20: 行20:
  
 
ContentのHeightを動的に変更
 
ContentのHeightを動的に変更
  GameObject panel = GameObject.Find('/Canvas/');
+
  GameObject panel = GameObject.Find("/Canvas/Scroll View/Viewport/Content/Panel");
 
  panel.GetComponent<RectTransform>().sizeDelta = new Vector2(w, h);
 
  panel.GetComponent<RectTransform>().sizeDelta = new Vector2(w, h);

2019年2月28日 (木) 19:30時点における版

リストのUIを作る

unity/UIScrollView [ショートカット]

  1. リスト内の部品はPanelで作ってprefub化する
  2. prehubはAssets/Resourcesにいれる

参考:https://tech.pjin.jp/blog/2016/08/30/unity_skill_3/

prefubを画面にロード

リストの部品(panel)をprefubからロードする

unity/3d [ショートカット]]

Instantiateのunity公式: https://docs.unity3d.com/jp/current/ScriptReference/Object.Instantiate.html

リストの部品がずれる場合

  1. prefub部品をダブルクリックして、RectTransformのTopとBottomを0にしてprefubを作り直す。
  2. ContentのHeightを3000とかに広げる(選択できない場合は、ContentSizeFilterのチェックを外す)

ContentのHeightを動的に変更

GameObject panel = GameObject.Find("/Canvas/Scroll View/Viewport/Content/Panel");
panel.GetComponent<RectTransform>().sizeDelta = new Vector2(w, h);