public void GenerateSidebar() { Transform[] children = sidebarContentTransform .Cast <Transform>() .Select(c => c.transform) .ToArray(); foreach (Transform child in children) { if (ReferenceEquals(settingsElement.transform, child)) { continue; } else if (ReferenceEquals(ppidElement.transform, child)) { continue; } else if (ReferenceEquals(localFilePathElement.transform, child)) { continue; } else if (ReferenceEquals(sessionNumElement.transform, child)) { continue; } else { DestroyImmediate(child.gameObject); } } foreach (FormElementEntry entry in participantDataPoints) { FormElement newElement = null; switch (entry.dataType) { case FormDataType.String: case FormDataType.Int: case FormDataType.Float: newElement = Instantiate(textPrefab, sidebarContentTransform); newElement.title.text = entry.displayName; newElement.SetDataType(entry.dataType); break; case FormDataType.Bool: newElement = Instantiate(checkBoxPrefab, sidebarContentTransform); newElement.title.text = entry.displayName; break; case FormDataType.DropDown: newElement = Instantiate(dropDownPrefab, sidebarContentTransform); newElement.title.text = entry.displayName; newElement.SetContents(entry.dropDownOptions); break; } entry.element = newElement; } }