public void RefreshUI() { int starUsageCount = CustomStarUsage.m_Instance.m_StarUsageCount; bool isDirty = true; if (m_StarRows != null) { isDirty = starUsageCount != m_StarRows.Length; } if (!isDirty) { for (int i = 0; i < starUsageCount; i++) { isDirty = m_StarRows[i].m_Usage.text != CustomStarUsage.m_Instance.GetUsage(i); if (isDirty) { break; } else { isDirty = m_StarRows[i].m_Stars.Length != CustomStarUsage.m_Instance.GetStarMaxCount(i); if (isDirty) { break; } } } } if (isDirty) { AdjustStarRows(starUsageCount); AdjustStars(starUsageCount); } for (int i = 0; i < starUsageCount; i++) { StarRow starRow = m_StarRows[i]; starRow.m_Usage.text = CustomStarUsage.m_Instance.GetUsage(i); starRow.RefreshColumns(); } }
private void AdjustStars(int starUsageCount) { if (starUsageCount <= 0) { return; } for (int i = 0; i < starUsageCount; i++) { StarRow starRow = m_StarRows[i]; int starMaxCount = CustomStarUsage.m_Instance.GetStarMaxCount(i); Button[] originalStars = starRow.m_Stars; if (starMaxCount == originalStars.Length) { continue; } GameObject templateStarButton = originalStars[0].gameObject; starRow.m_Stars = new Button[starMaxCount]; int jMax = Mathf.Min(starMaxCount, originalStars.Length); for (int j = 0; j < jMax; j++) { starRow.m_Stars[j] = originalStars[j]; } for (int j = originalStars.Length; j < starMaxCount; j++) { GameObject starText = Instantiate(templateStarButton); m_StringBuilder.Append("Button"); m_StringBuilder.Append(j); starText.name = m_StringBuilder.ToString(); m_StringBuilder.Clear(); starText.transform.SetParent(starRow.m_Stars[0].transform.parent); starText.transform.localScale = Vector3.one; starRow.m_Stars[j] = starText.GetComponent <Button>(); } jMax = originalStars.Length; for (int j = starMaxCount; j < jMax; j++) { Destroy(originalStars[j].gameObject); } } }