//------------------------------------------------------------------------------------------------------------------------- private void SaveScene() { // If baking a scene individually, save it at the end of each lightmapping process before kickstarting a new one if (display == BakeOptions.Individual) { System.TimeSpan lightmappingSpan = System.DateTime.Now - timeStamp; string bakeTime = string.Format("{0:D2}:{1:D2}:{2:D2}", lightmappingSpan.Hours, lightmappingSpan.Minutes, lightmappingSpan.Seconds); bakeFinal = "(" + EditorSceneManager.GetActiveScene().name + ")" + "," + "[" + bakeTime + "]"; if (logPrintTimes) { UnityEngine.Debug.Log("[" + sceneIndex.ToString() + "/" + scenes.Length.ToString() + "] " + "Done baking: " + EditorSceneManager.GetActiveScene().name + ".unity" + " after " + bakeTime); } EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene()); if (printTiming) { BakeLightmaps.Trace(bakeFinal); } } // If baking a scenes as a group, save them altogether else if (display == BakeOptions.Group) { System.TimeSpan lightmappingSpan = System.DateTime.Now - timeStamp; string bakeTime = string.Format("{0:D2}:{1:D2}:{2:D2}", lightmappingSpan.Hours, lightmappingSpan.Minutes, lightmappingSpan.Seconds); bakeFinal = "Group bake timing:" + "," + "[" + bakeTime + "]"; EditorSceneManager.MarkAllScenesDirty(); // Mark the scenes dirty so all the results are saved in the next step EditorSceneManager.SaveOpenScenes(); isGroupBakingDone = true; // Group baking is done if (logPrintTimes) { UnityEngine.Debug.Log(bakeFinal); } if (printTiming) { BakeLightmaps.Trace(bakeFinal); } } }
//------------------------------------------------------------------------------------------------------------------------- // Update lightmapping process private void UpdateLightmappingProcess() { if (Lightmapping.isRunning) { if (display == BakeOptions.Individual) { status = "Lightmapping " + (sceneIndex + 1).ToString() + " of " + scenes.Length.ToString(); bakeButton = "Cancel"; } else if (display == BakeOptions.Group) { status = "Lightmapping scenes as a group"; bakeButton = "Cancel"; } } // This section only runs when baking stalls, not when baking is completed (API bug) // Baking has been stopped when this code path is executed else if (!Lightmapping.isRunning) { if (display == BakeOptions.Individual) { DoneLightmapping("Generate Lighting"); } else if (display == BakeOptions.Group) { bakeButton = "Generate Lighting"; } } // Handle printing results for group baking if (display == BakeOptions.Group && isGroupBakingDone) { if (printTiming) { SaveOutputGrid(BakeLog); BakeLightmaps.Trace(" "); } DoneLightmapping("done"); isGroupBakingDone = false; // revert bool status to idle state } }
//------------------------------------------------------------------------------------------------------------------------- // Determine which baking option is used // Then iterate through scene list to generate lighting and keep track of process private void BakeNewScene() { if (display == BakeOptions.Individual && !overrideLightSettings) { if (sceneIndex < scenes.Length) { EditorSceneManager.OpenScene(scenePath[sceneIndex], OpenSceneMode.Single); timeStamp = System.DateTime.Now; Lightmapping.BakeAsync(); UpdateLightmappingProcess(); sceneIndex++; } else { DoneLightmapping("done"); if (printTiming) { SaveOutputGrid(BakeLog); BakeLightmaps.Trace(" "); } } } else if (display == BakeOptions.Individual && overrideLightSettings && lightingPreset != null) { if (sceneIndex < scenes.Length) { EditorSceneManager.OpenScene(scenePath[sceneIndex], OpenSceneMode.Single); lightingPreset.Load(); timeStamp = System.DateTime.Now; Lightmapping.BakeAsync(); UpdateLightmappingProcess(); sceneIndex++; } else { DoneLightmapping("done"); if (printTiming) { SaveOutputGrid(BakeLog); BakeLightmaps.Trace(" "); } } } else if ((display == BakeOptions.Individual || display == BakeOptions.Group) && overrideLightSettings && lightingPreset == null) { UnityEngine.Debug.LogError("Please assign a Lighting Preset to override lighting settings for scenes"); } if (display == BakeOptions.Group && !overrideLightSettings) { Lightmapping.giWorkflowMode = Lightmapping.GIWorkflowMode.OnDemand; timeStamp = System.DateTime.Now; Lightmapping.BakeMultipleScenes(scenePath.ToArray()); UpdateLightmappingProcess(); } else if (display == BakeOptions.Group && overrideLightSettings && lightingPreset != null) { EditorSceneManager.OpenScene(scenePath[0], OpenSceneMode.Single); EditorSceneManager.SetActiveScene(EditorSceneManager.GetSceneByName(EditorSceneManager.GetActiveScene().name)); lightingPreset.Load(); Lightmapping.giWorkflowMode = Lightmapping.GIWorkflowMode.OnDemand; EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene()); timeStamp = System.DateTime.Now; Lightmapping.BakeMultipleScenes(scenePath.ToArray()); UpdateLightmappingProcess(); } }