public List <CardItem> CreateItems(Transform parentT, int count, Action action = null) { List <CardItem> items = new List <CardItem>(); for (int i = 0; i < count; i++) { GameObject go = GameObject.Instantiate(LoadRes <GameObject>(CardConst.PathCardItem)); CardItem item = go.GetComponent <CardItem>(); go.transform.SetParent(parentT); UniformTransform(go.transform); item.SetId(i); Texture sp; try { sp = LoadRes <Texture>(CardConst.PicPrefix + i.ToString()); } catch (Exception ex) { sp = LoadRes <Texture>(CardConst.PicPrefix + (i / 2).ToString()); Debug.LogError(ex.ToString()); } item.Init(sp, () => { if (action != null) { action.Invoke(); } }); items.Add(item); } return(items); }
public static int SortPosition(CardItem a, CardItem b) { return(a.transform.localPosition.x.CompareTo(b.transform.localPosition.x)); }