Esempio n. 1
0
        /// <inheritdoc />
        protected override bool OnStepStart()
        {
            if (ClearDiskCache)
            {
                Lightmapping.ClearDiskCache();
            }

            if (ClearLightingDataAsset)
            {
                Lightmapping.ClearLightingDataAsset();
            }

            return(true);
        }
Esempio n. 2
0
    private IEnumerator BuildLightingAsync(string ScenarioName)
    {
        if (clearCache)
        {
            Lightmapping.ClearDiskCache();
        }
        var newLightmapMode = new LightmapsMode();

        newLightmapMode = LightmapSettings.lightmapsMode;
        Lightmapping.BakeAsync();
        while (Lightmapping.isRunning)
        {
            yield return(null);
        }
        Lightmapping.lightingDataAsset = null;
        EditorSceneManager.SaveScene(EditorSceneManager.GetSceneByPath("Assets/Demo/" + ScenarioName + ".unity"));
        EditorSceneManager.CloseScene(EditorSceneManager.GetSceneByPath("Assets/Demo/" + ScenarioName + ".unity"), true);
        LightmapSettings.lightmapsMode = newLightmapMode;
    }
Esempio n. 3
0
        private static void ApplyAction(int option)
        {
            turnOffBakedLightsAfterBake = false;

            if (option == BakeScene)
            {
                Lightmapping.BakeAsync();
            }
            else if (option == TurnOnAllLightsBakeSceneAndTurnOffBakedLights)
            {
                turnOffBakedLightsAfterBake = true;
                ActivateLights(true);
                Lightmapping.BakeAsync();
            }
            else if (option == TurnOnBakedLightsBakeSceneAndTurnOffBakedLights)
            {
                turnOffBakedLightsAfterBake = true;
                ActivateLights(true, true);
                Lightmapping.BakeAsync();
            }
            else if (option == ClearBakeData)
            {
                Lightmapping.Clear();
                Lightmapping.ClearDiskCache();
                Lightmapping.ClearLightingDataAsset();
            }
            else if (option == CancelBake)
            {
                Lightmapping.Cancel();
            }
            else
            {
                var enableComponent = option == ActivateAllLights || option == ActivateBakedLights || option == ActivateNotBakedLights;
                var justBaked       = option == ActivateBakedLights || option == DeactivateBakedLights;
                var justNotBaked    = option == ActivateNotBakedLights || option == DeactivateNotBakedLights;
                ActivateLights(enableComponent, justBaked, justNotBaked);
            }
        }
Esempio n. 4
0
        static void OnBakeComplete()
        {
            // 4. Clear progress & events

            BakeFinished( );

            // 5. Fetch lightmaps, apply to prefab and save them in selected folder

            SaveLightmaps();

            if (Window.AutoClean)
            {
                // 6. Delete scene lightmap data

                Lightmapping.ClearLightingDataAsset( );
                Lightmapping.ClearDiskCache( );
                Lightmapping.Clear( );
            }

            // 7. Combine prefab lightmaps with scene lightmaps

            EditorUtils.GetAllPrefabs( ).ForEach(x => Utils.Apply(x));
        }
Esempio n. 5
0
    private static void BakeBuild()
    {
        if (EditorUtility.DisplayDialog("Bake Build Settings Scenes?", "Bake Build Settings Scenes?", "Yes", "No"))
        {
            Debug.Log("Starting Batch Bake...");
            AssetDatabase.SaveAssets();

            EditorBuildSettingsScene[]   scenes = EditorBuildSettings.scenes;
            System.Diagnostics.Stopwatch watch  = new System.Diagnostics.Stopwatch();

            foreach (EditorBuildSettingsScene scn in scenes)
            {
                Debug.Log("Baking: " + scn.path);
                EditorSceneManager.OpenScene(scn.path);

                //CLEAR THE LIGHTMAPS AND THE CACHE
                //THIS IS AN ATTEMPT TO PREVENT SYSTEM HANGS SEE
                //http://forum.unity3d.com/threads/bake-runtime-job-failed-with-error-code-11-failed-reading-albedo-texture-file.326474/
                Lightmapping.Clear();
                Lightmapping.ClearDiskCache();

                watch.Reset();
                watch.Start();

                Lightmapping.Bake();

                //Stop the timer
                watch.Stop();

                EditorApplication.SaveScene();

                Debug.Log("Finished Bake Time: " + watch.Elapsed.TotalMinutes.ToString() + " Scene: " + scn.path);
            }

            Debug.Log("Finished Batch Bake.");
        }
    }
 public void LightingOptionHandler()
 {
     if (ClearCache)
     {
         Lightmapping.Clear();
         Lightmapping.ClearDiskCache();
         Lightmapping.ClearLightingDataAsset();
         Debug.Log("PixelSpice - Cache Cleared");
         Last_Clear = true;
     }
     else if (!HasBaked)
     {
         Debug.Log("PixelSpice - Prebakeing Lightmap");
         Lightmapping.Bake();
         HasBaked = true;
         Debug.Log("PixelSpice - Prebake Complete");
         Last_Clear = false;
     }
     else
     {
         Debug.Log("PixelSpice - No Prebake Needed - Skipping");
         Last_Clear = false;
     }
 }
Esempio n. 7
0
    public void RefProbeAPI(string settings, BakeAPI bakeAPI)
    {
        EditorSceneManager.OpenScene(sceneFileName, OpenSceneMode.Single);

        // Bake with a lighting settings asset.
        string[] settingsAssets = AssetDatabase.FindAssets(settings + " t:lightingsettings", foldersToLookIn);
        Debug.Log("Found " + settingsAssets.Length + " matching lighting settings assets in " + foldersToLookIn[0]);
        Assert.That(settingsAssets.Length, Is.EqualTo(1));
        string lsaPath = AssetDatabase.GUIDToAssetPath(settingsAssets[0]);

        Debug.Log("Loading " + lsaPath);
        LightingSettings lightingSettings = (LightingSettings)AssetDatabase.LoadAssetAtPath(lsaPath, typeof(LightingSettings));

        Lightmapping.lightingSettings = lightingSettings;
        string fileName = System.IO.Path.GetFileNameWithoutExtension(lsaPath);

        Assert.That(fileName, Is.EqualTo(settings));
        Lightmapping.Clear();
        // The disk cache needs clearing between runs because we are only changing the API and not necessarily the settings.
        // Changing the API use to bake the probe is assumed to not affect the result so the reflection probe is fetched from the disk cache.
        // To detect that everything works as intended the cached reflection probe needs to be cleared.
        Lightmapping.ClearDiskCache();
        Debug.Log("Baking " + fileName);
        bool result = true;

        switch (bakeAPI)
        {
        case BakeAPI.Bake:
            result = Lightmapping.Bake();
            break;

        case BakeAPI.BakeAll:
        {
            var probe = Object.FindObjectOfType <ReflectionProbe>();
            Assert.That(probe, !Is.EqualTo(null), "Couldn't find ReflectionProbe");
            Debug.Log("Found reflection probe: " + probe.name);

            var oldEnabledValue = probe.enabled;
            probe.enabled = false;
            result        = Lightmapping.Bake();
            probe.enabled = oldEnabledValue;
            result       &= Lightmapping.BakeAllReflectionProbesSnapshots();
        }
        break;

        case BakeAPI.BakeSingle:
        {
            var probe = Object.FindObjectOfType <ReflectionProbe>();
            Assert.That(probe, !Is.EqualTo(null), "Couldn't find ReflectionProbe");
            Debug.Log("Found reflection probe: " + probe.name);

            var oldEnabledValue = probe.enabled;
            probe.enabled = false;
            result        = Lightmapping.Bake();
            probe.enabled = oldEnabledValue;
            result       &= Lightmapping.BakeReflectionProbeSnapshot(probe);
        }
        break;
        }
        Assert.That(result, Is.True);

        // Get Test settings.
        var graphicsTestSettingsCustom = Object.FindObjectOfType <UniversalGraphicsTestSettings>();

        Assert.That(graphicsTestSettingsCustom, !Is.EqualTo(null), "Couldn't find GraphicsTestSettingsCustom");

        // Load reference image.
        var referenceImagePath = System.IO.Path.Combine("Assets/ReferenceImages", string.Format("{0}/{1}/{2}/{3}/{4}",
                                                                                                UseGraphicsTestCasesAttribute.ColorSpace,
                                                                                                UseGraphicsTestCasesAttribute.Platform,
                                                                                                UseGraphicsTestCasesAttribute.GraphicsDevice,
                                                                                                UseGraphicsTestCasesAttribute.LoadedXRDevice,
                                                                                                "RefProbeAPI_" + settings + "-" + bakeAPI.ToString() + "_.png"));

        Debug.Log("referenceImagePath " + referenceImagePath);
        var referenceImage = AssetDatabase.LoadAssetAtPath <Texture2D>(referenceImagePath);

        // Compare screenshots.
        GraphicsTestCase testCase = new GraphicsTestCase(settings, referenceImage);
        var cameras = GameObject.FindGameObjectsWithTag("MainCamera").Select(x => x.GetComponent <Camera>());

        ImageAssert.AreEqual(testCase.ReferenceImage, cameras.Where(x => x != null), graphicsTestSettingsCustom.ImageComparisonSettings);
        UnityEditor.TestTools.Graphics.ResultsUtility.ExtractImagesFromTestProperties(TestContext.CurrentContext.Test);
    }
Esempio n. 8
0
 static void clearAll()
 {
     Lightmapping.Clear();
     Lightmapping.ClearDiskCache();
     Lightmapping.ClearLightingDataAsset();
 }
Esempio n. 9
0
 public static void ClearBakeData()
 {
     Lightmapping.ClearLightingDataAsset();
     Lightmapping.ClearDiskCache();
     Lightmapping.Clear();
 }