Create a gist now

Instantly share code, notes, and snippets.

@kihira /HandInfoPanel.cs Secret
Created Mar 30, 2016

What would you like to do?
[Header("Logs")]
[SerializeField] private GameObject logButtonPrefab;
[SerializeField] private GameObject logList;
private List<LogData> logs = new List<LogData>();
private LogComparer comparer = new LogComparer();
class LogComparer : IComparer<LogData>
{
public int Compare(LogData x, LogData y)
{
return x.message.Length - y.message.Length;
}
}
public void Attach(HandModel handModel, LogData log)
{
// Irrelevant code removed
logs.Add(log);
AddLogButton(log);
}
void AddLogButton(LogData data, bool sort = true)
{
// Create and setup button object
GameObject logButton = Instantiate(logButtonPrefab);
logButton.transform.SetParent(logList.transform, false);
logButton.GetComponentInChildren<Text>().text = data.title;
if (sort)
{
logs.Sort(comparer);
// Remove all children then readd them
for (int i = 0; i < logList.transform.childCount; i++)
{
Destroy(logList.transform.GetChild(i).gameObject);
}
foreach (LogData log in logs)
{
AddLogButton(log, false);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment