/// <summary> /// Destroys scene prefabs. Unlike DestroyAll(), simulation prefabs are not affected. /// </summary> public static void DestroyLoaded <P>() where P : PrefabInfo { try { int n = PrefabCollection <P> .LoadedCount(); List <P> prefabs = new List <P>(n); for (int i = 0; i < n; i++) { P info = PrefabCollection <P> .GetLoaded((uint)i); if (info != null) { info.m_prefabDataIndex = -1; // leave simulation prefabs as they are prefabs.Add(info); } } PrefabCollection <P> .DestroyPrefabs(string.Empty, prefabs.ToArray(), null); // This has not been necessary yet. However, it is quite fatal if prefabs are left behind so better be sure. if (n != prefabs.Count) { object fastList = Util.GetStatic(typeof(PrefabCollection <P>), "m_scenePrefabs"); Util.Set(fastList, "m_size", 0, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); } object dict = Util.GetStatic(typeof(PrefabCollection <P>), "m_prefabDict"); dict.GetType().GetMethod("Clear", BindingFlags.Instance | BindingFlags.Public).Invoke(dict, null); prefabs.Clear(); prefabs.Capacity = 0; } catch (Exception e) { UnityEngine.Debug.LogException(e); } }