public void Sort() { List <BtnCenter> listBtn = new List <BtnCenter>(); foreach (Transform tran in parentPnbuttonCenter.transform) { BtnCenter bt = tran.GetComponent <BtnCenter>(); int value = bt.distant; listBtn.Add(bt); } SortedList = listBtn.OrderBy(o => o.distant).ToList(); ix = 0; foreach (BtnCenter tran in SortedList) { tran.transform.SetSiblingIndex(ix); ix++; } }
void OnDistanFindComplete(string response) { List <OnlineMapsDirectionStep> steps = OnlineMapsDirectionStep.TryParse(response); if (steps != null) { kc = CaculateeKHoangCach(steps); } int c = initCounter; GameObject obj = Instantiate(pnButtonCenter, parentPnbuttonCenter); BtnCenter bt = obj.GetComponent <BtnCenter>(); bt.Init(initCounter, Datacenter.instance.listCenter[initCounter].name, kc); obj.transform.localScale = new Vector3(1, 1, 1); bt.GetComponentInChildren <Button>().onClick.AddListener(delegate { OncenterClick(c); }); Debug.Log(initCounter); initCounter++; Sort(); }