public void Redraw(List <GameObject> objects) { CachedTransform.DestroyChildren(); int count = 0; foreach (GameObject @object in objects) { GameObject item = Instantiate(prefab, CachedTransform); item.GetComponentInChildren <Text>().text = $"{count}: {@object.name} [{@object.GetInstanceID()}]"; Button button = item.GetComponentInChildren <Button>(); button.onClick.AddListener(RemoveObject); ++count; void RemoveObject() { objects.Remove(@object); Destroy(item); Redraw(objects); } } Window.SetActive(objects.Count > 0); }
private void DestroyChildren() { #if UNITY_EDITOR if (!UnityEditor.EditorApplication.isPlaying) { DestroyChildrenImmediate(); } else #endif CachedTransform.DestroyChildren(); }