ã¯ããã«
ã©ãããåéã§ãã
UI Toolkitã使ã£ã¦ãã¦uGUIã«ãã£ãã°ãªããã¬ã¤ã¢ã¦ããã§ããªãï¼ã¨ããåé¡ããã£ãã®ã§ãä»åã¯èªåã§å®è£ ãã¾ãã
uxmlãæ¸ãã¦è§£æ±ºããè¨äºããã£ãã®ã§ãããUI Builderã ãã§è§£æ±ºã§ãã¾ããã
å®è£ æ¹æ³
UI Builder
Grid
ScrollViewã®unity-content-containeré
ä¸ã«Gridç¨ã®VisualElementã追å ãã¾ãã
å®éã®è¦ç´ ã¯ãã®GridVisualElementé
ä¸ã«é
ç½®ãã¾ãã
次ã«GridVisualElementãé¸æããFlexã®Directionã¨Wrapãç»åã®ããã«å¤ãã¾ãã
ã¾ãGrowã1ã«ãã¦ãã ããã
ããã§ã²ã¨ã¾ãã°ãªããã¬ã¤ã¢ã¦ãã£ã½ããªãã¾ãã
ã³ã³ãã³ã
ã°ãªããã«é ç½®ããã³ã³ãã³ãã®uxmlãä½æãã¾ãã
ããããã§ã«Grid以ä¸ã«ã³ã³ãã³ããä½ã£ã¦ããããå³ã¯ãªãã¯ãã¦Create Templateã§uxmlãçæã§ãã¾ãã
ã³ã³ãã³ãã®ä¸èº«ã¯ç»å表示ã ãã§ããããµã¤ãºãåºå®ãããã£ãã®ã§ä»¥ä¸ã®ããã«ãã¾ããã
Data Binding
ç¨æããã¦ããListViewãªã©ã§ããã°ç°¡åã«ãã¼ã¿ã½ã¼ã¹ããã³ãã¬ã¼ããè¨å®ã§ããã®ã§ãããä»åã®ãã®ã¯èªä½ãã¦ããã®ã§èªåã§Bindãã¦ãããå¿ è¦ãããã¾ãã
public class ConstructMenu : MonoBehaviour { [SerializeField] private VisualTreeAsset buildingElement; [SerializeField] private BuildingList buildingList; private void Start() { var root = GetComponent<UIDocument>().rootVisualElement; foreach (var building in buildingList.buildings) { var buildingTemplate = buildingElement.Instantiate(); Debug.Log(building.name); buildingTemplate.dataSource = building; root.Q<VisualElement>("Grid").contentContainer.Add(buildingTemplate); } } }
ã³ã³ãã³ãã®uxmlãã¤ã³ã¹ãã¯ã¿ã¼ããã»ããããã«ã¯VisualTreeAssetã使ãå¿ è¦ãããã¾ãã
ããã¯ããã¾ã§ãã³ãã¬ã¼ããªã®ã§ãInstantiate()ã§çæãã¦Gridã«è¿½å ãã¦ãã¾ãã
åè
https://discussions.unity.com/t/ui-toolkit-items-scrollable-grid-using-a-scrollview/899308/6