public void Delete(GameObject[] gameObjects) { if (gameObjects == null || gameObjects.Length == 0) { return; } if (!Undo.Enabled) { for (int i = 0; i < gameObjects.Length; ++i) { GameObject go = gameObjects[i]; if (go != null) { ExposeToEditor exposed = go.GetComponent <ExposeToEditor>(); if (exposed == null || exposed.CanDelete) { Destroy(go); } } } return; } ExposeToEditor[] exposeToEditor = gameObjects.Select(o => o.GetComponent <ExposeToEditor>()).Where(exposed => exposed.CanDelete).OrderByDescending(o => o.transform.GetSiblingIndex()).ToArray(); if (exposeToEditor.Length == 0) { return; } HashSet <GameObject> removeObjectsHs = new HashSet <GameObject>(exposeToEditor.Select(exposed => exposed.gameObject)); Undo.BeginRecord(); if (Selection.objects != null) { List <UnityEngine.Object> selection = Selection.objects.ToList(); for (int i = selection.Count - 1; i >= 0; --i) { if (removeObjectsHs.Contains(selection[i])) { selection.RemoveAt(i); } } Selection.objects = selection.ToArray(); } Undo.DestroyObjects(exposeToEditor); Undo.EndRecord(); }
public void Delete(GameObject[] gameObjects) { if (gameObjects == null || gameObjects.Length == 0) { return; } if (!Undo.Enabled) { for (int i = 0; i < gameObjects.Length; ++i) { GameObject go = gameObjects[i]; if (go != null) { Destroy(go); } } return; } ExposeToEditor[] exposeToEditor = gameObjects.Select(o => o.GetComponent <ExposeToEditor>()).OrderByDescending(o => o.transform.GetSiblingIndex()).ToArray(); Undo.BeginRecord(); if (Selection.objects != null) { List <UnityEngine.Object> selection = Selection.objects.ToList(); for (int i = selection.Count - 1; i >= 0; --i) { if (selection[i] == gameObjects[i]) { selection.RemoveAt(i); //NADI: // Destroy(gameObjects[i]); } } Selection.objects = selection.ToArray(); } Undo.DestroyObjects(exposeToEditor); Undo.EndRecord(); }