-
-
Save kihira/a080f77e1685f469cb36143796e6f0b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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