public void Destroy() { GameObjectExtensions.Destroy(GameObject); GameObject = null; MeshFilter = null; MeshRenderer = null; }
// Unity bug workaround private void Update() { // we need to kill a dangling "generated-meshes" when deleting prefab instance in scene if (owner) { return; } GameObjectExtensions.Destroy(this.gameObject); }
internal static void DestroyAllMeshInstances() { if (UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode) { return; } for (var sceneIndex = 0; sceneIndex < SceneManager.sceneCount; sceneIndex++) { var scene = SceneManager.GetSceneAt(sceneIndex); if (!scene.isLoaded) { continue; } var sceneModels = SceneQueryUtility.GetAllComponentsInScene <CSGModel>(scene); for (int i = 0; i < sceneModels.Count; i++) { if (!ModelTraits.IsModelEditable(sceneModels[i])) { continue; } var selfTransform = sceneModels[i].transform; var transforms = selfTransform.GetComponentsInChildren <Transform>(); foreach (var generateMeshesTransform in transforms) { if (!generateMeshesTransform || generateMeshesTransform.parent != selfTransform) { continue; } if (generateMeshesTransform.name != MeshInstanceManager.MeshContainerName) { continue; } var childTransforms = generateMeshesTransform; foreach (Transform childTransform in childTransforms) { GameObjectExtensions.Destroy(childTransform.gameObject); } } } } }