private void OnGUI() { // If scene is null, check again. Scene changes and exports can cause check to fail when it shouldn't. if (!_scene) { _scene = GetRoot(); } if (!_scene) { GUILayout.Label("Could not find Custom Scene component on root game object.", EditorStyles.boldLabel); return; } // Draw the meta data fields GUILayout.Label("Scene metadata", EditorStyles.boldLabel); _scene.SceneName = EditorGUILayout.TextField("Scene Name", _scene.SceneName); _scene.Author = EditorGUILayout.TextField("Author", _scene.Author); _scene.Description = EditorGUILayout.TextField("Description", _scene.Description, GUILayout.MaxHeight(75)); // Game mode stuff _scene.Gamemode = DrawGamemode(_scene.Gamemode); if (GUILayout.Button("Export Scene")) { var scene = SceneManager.GetActiveScene(); var err = new ExportErrors(); Exporter.Export(scene, err); } }
/// <summary> /// In exporting we have the following steps: /// Run ComponentProxy OnExport() /// Find & call the SceneExporter for the given game mode /// If no errors were returned, create the bundle /// </summary> public static void Export(Scene scene, ExportErrors err) { // Get the root objects in the scene var roots = scene.GetRootGameObjects(); // Make sure there's only one and it's name is correct if (roots.Length != 1 || roots[0].name != Constants.RootObjectLevelName) { err.AddError($"You must only have one root object in your scene and it must be named '{Constants.RootObjectLevelName}'"); return; } // Make sure it has the CustomScene component. If not, error out var sceneRoot = roots[0].GetComponent <CustomScene>(); if (!sceneRoot) { err.AddError($"Your root object must have the {nameof(CustomScene)} component on it!"); return; } // Find the exporter class. If none is found, error out SceneExporter.RefreshLoadedSceneExporters(); var exporter = SceneExporter.GetExporterForGamemode(sceneRoot.Gamemode); if (exporter == null) { err.AddError($"Could not find an exporter class for the gamemode '{sceneRoot.Gamemode}'. Are you missing an assembly?"); return; } // We have an exporter class, so let it handle the rest of validating the scene exporter.Validate(scene, sceneRoot, err); // Check for errors after validating if (err.HasErrors) { EditorUtility.DisplayDialog("Validation failed.", "There were errors while validating the scene. Check console for more details.", "Oops"); return; } // Check for warnings, and give the option to continue if (err.HasWarnings) { var result = EditorUtility.DisplayDialog("Validation succeeded with warnings", "There were warnings while validating the scene. This will not prevent you from continuing, but it is recommended you cancel and correct them", "Continue", "Cancel"); if (!result) { return; } } // Now the scene is validated we can export. exporter.Export(); Debug.Log("Scene exported!"); }