using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; [RequireComponent(typeof(RectTransform))] [DisallowMultipleComponent] public class EmployeeScrollView : ScrollRect { [SerializeField] public RectTransform itemTemplate; public void SetUpdateFunc(List list,Action action) { if(itemTemplate == null) itemTemplate = transform.Find("Item").GetComponent(); ClearData(); int i = 0; foreach (var item in list) { GameObject go = Instantiate(itemTemplate.gameObject,content.transform); go.SetActive(true); action?.Invoke(i,go); i++; } } private void ClearData() { foreach (Transform item in content.transform) { Destroy(item.gameObject); } } }