Notice
Recent Posts
Recent Comments
Link
스토리지
[4.27] NGUI를 이용한 ScrollView 본문
구조
- UI Root에서 Scroll View 설치
- Scroll View 자식으로 Grid설치
Arrangement : 가로로 스크롤 할 경우에는 Horizontal, 아니면 Vertical로 해주면 된다.
Cell Width, Cell Height : 각각의 요소가 차지하는 공간을 설정, 설정 후에는 Execute를 해봐야 설정한 영역을 확인할 수 있다.
Test.cs
using System.Linq;
using System.Collections.Generic;
using UnityEngine;
using Newtonsoft.Json;
public class Test : MonoBehaviour
{
public GameObject prefab;
public GameObject prefabAD;
public UIGrid grid;
public Dictionary<int, ShopData> arrShop;
// Start is called before the first frame update
void Start()
{
var ta = Resources.Load<TextAsset>("ShopData");
var json = ta.text;
this.arrShop = JsonConvert.DeserializeObject<ShopData[]>(json).ToDictionary(x => x.id);
foreach(var item in this.arrShop)
{
if (item.Value.is_add)
{
var goAd = Instantiate(this.prefabAD, this.grid.transform);
var listItem = goAd.GetComponent<UIListItemAD>();
listItem.Init(item.Value);
}
else
{
var go = Instantiate(this.prefab, this.grid.transform);
var listItem = go.GetComponent<UIListItem>();
listItem.Init(item.Value);
}
}
this.grid.Reposition();
}
}
'Unity > 유니티 기본' 카테고리의 다른 글
[4.27] Daily Login Reward 화면 - NGUI (0) | 2021.04.27 |
---|---|
[4.27] 세로 Scroll View (0) | 2021.04.27 |
슈퍼마리오 클론게임 (0) | 2021.04.27 |
[4.26] 메인화면 구성 (NGUI 사용) (0) | 2021.04.26 |
[4.26] NGUI TEXT작성 (0) | 2021.04.26 |
Comments