/// <summary> /// Checks every scene model in every scene manager to determine if the moved /// scene was a dependency and updates the path if so /// </summary> /// <param name="sourcePath">Where the file originated</param> /// <param name="destinationPath">Where the file is going</param> private static void UpdateSceneAssetPaths(string sourcePath, string destinationPath) { if (!IsValidSceneItem(sourcePath)) { return; } foreach (SceneManagerController controller in AssetDatabaseExtensions.GetAssetIterator <SceneManagerController>()) { SerializedObject serializedController = new SerializedObject(controller); SerializedProperty scenesProp = serializedController.FindProperty("scenes"); for (int i = 0; i < scenesProp.arraySize; i++) { SerializedProperty currentProp = scenesProp.GetArrayElementAtIndex(i); SerializedProperty pathProp = currentProp.FindPropertyRelative("sceneAssetPath"); // Check if this scene model is pointing to the active scene if (!pathProp.stringValue.Equals(sourcePath)) { continue; } pathProp.stringValue = destinationPath; SerializedProperty nameProp = currentProp.FindPropertyRelative("sceneName"); string sourcePathSceneName = System.IO.Path.GetFileNameWithoutExtension(nameProp.stringValue); string destPathSceneName = System.IO.Path.GetFileNameWithoutExtension(destinationPath); // If the scene name matched the file path, update the scene // name with the new path name if (nameProp.stringValue.Equals(sourcePathSceneName, StringComparison.OrdinalIgnoreCase)) { nameProp.stringValue = destPathSceneName; } break; } // Renames can't be undone, so updating scene path shouldn't either serializedController.ApplyModifiedPropertiesWithoutUndo(); SceneManagerEditorWindow.RefreshOpenSceneManagementWindow(); } }
private static void RemoveSceneAsset(string sourcePath) { if (!IsValidSceneItem(sourcePath)) { return; } foreach (SceneManagerController controller in AssetDatabaseExtensions.GetAssetIterator <SceneManagerController>()) { controller.RemoveScene(sourcePath); SceneNodeCollection nodes = AssetDatabaseExtensions.GetFirstSubAssetOf <SceneNodeCollection>(controller); if (nodes != null) { nodes.RemoveSceneNodesByPath(sourcePath); } } SceneManagerEditorWindow.RefreshOpenSceneManagementWindow(); }