private static void RepopulateSelection(bool forceRepopulate) { List <Object> objects = new List <Object>(); ErrorReport report = new ErrorReport(); try { if (EditorUtility.DisplayCancelableProgressBar("Repopulating", "Searching...", 0)) { report.Error("User canceled"); } else { foreach (Object o in Selection.objects) { GameObject go = o as GameObject; if (go != null) { if (!objects.Contains(go)) { objects.Add(go); List <GameObject> children = new List <GameObject>(); GetChildrenRecursive(go, children); foreach (GameObject child in children) { if (!objects.Contains(child)) { objects.Add(child); } } } } else { Component component = o as Component; if (component != null) { objects.Add(component); AutoPopulate(component, forceRepopulate, report); } } } for (int i = 0; i < objects.Count; i++) { Object o = objects[i]; if (EditorUtility.DisplayCancelableProgressBar( "Repopulating", o.FullName(Extensions.FullNameFlags.FullSceneOrAssetPath), (float)i / objects.Count)) { report.Error("User canceled"); break; } GameObject go = o as GameObject; if (go != null) { // use non-recursive, because we already unrolled all the child objects when we were searching above AutoPopulate(go, false, forceRepopulate, report); } else { Component component = o as Component; if (component != null) { AutoPopulate(component, forceRepopulate, report); } } } } } catch (Exception e) { report.HandleException(e); } finally { if (objects.Count == 0) { report.Warning("Nothing selected was Auto-populatable"); } report.Done(); EditorUtility.ClearProgressBar(); } }