Exemplo n.º 1
0
        /// <summary>
        /// 生成烘焙数据
        /// </summary>
        public static void BakeGroupAsset(MapGroupAsset groupAsset)
        {
            //TODO:设置实时光照配置
            //保护现场
            SceneSetup[] sceneSetup = EditorSceneManager.GetSceneManagerSetup();

            //Setting
            for (int i = 0; i < 3; i++)
            {
                Scene s = EditorSceneManager.OpenScene(GetScenePath(groupAsset, i), OpenSceneMode.Single);
                {
                    Lightmapping.bakedGI    = false;
                    Lightmapping.realtimeGI = true;
                    LightmapEditorSettings.realtimeResolution = 4;
                }
                EditorSceneManager.SaveScene(s);
            }

            //恢复现场
            EditorSceneManager.RestoreSceneManagerSetup(sceneSetup);

            //Bake
            string[] paths = { GetScenePath(groupAsset, 0), GetScenePath(groupAsset, 1), GetScenePath(groupAsset, 2) };
            Lightmapping.BakeMultipleScenes(paths); //这个API是异步的!

            groupAsset.baked = true;
        }
Exemplo n.º 2
0
        private void OnGUI()
        {
            if (this.scenes == null)
            {
                this.RefreshSceneList();
            }

            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Scenes To Build Lighting");

            foreach (string key in this.scenes.Keys.OrderBy(x => x))
            {
                this.scenes[key] = this.DrawCheckbox(key, this.scenes[key]);
            }

            using (new EditorGUILayout.HorizontalScope())
            {
                if (GUILayout.Button("Build Lighting"))
                {
                    var scenes = this.scenes.Select(x => x.Key).Where(x => this.scenes[x]).ToArray();
                    Lightmapping.BakeMultipleScenes(scenes);
                }
            }

            using (new EditorGUILayout.HorizontalScope())
            {
                if (GUILayout.Button("Refresh Scene List"))
                {
                    this.RefreshSceneList();
                }
            }
        }
Exemplo n.º 3
0
 static void BakeMultipleScenes()
 {
     //指定烘焙场景
     Lightmapping.BakeMultipleScenes(new string[] {
         "Assets/Scene.unity",
         "Assets/Scene 1.unity",
         "Assets/Scene 2.unity",
     });
 }
Exemplo n.º 4
0
        protected void BakeAllScenes()
        {
            // close all open scenes
            CloseOpenScenes();

            SetBakeToManual();
            // force save
            EditorSceneManager.SaveScene(GetSceneManagerScene());
            // start baking everything
            Lightmapping.BakeMultipleScenes(ManagedScenePaths().ToArray());
        }
Exemplo n.º 5
0
    static void BakeLevels()
    {
        EnvironmentChange envChange = GameObject.FindObjectOfType <EnvironmentChange> ();

        if (envChange && envChange.levels != null)
        {
            int numLevels = envChange.levels.Length;

            for (int levelIndex = 0; levelIndex < numLevels; ++levelIndex)
            {
                EditorUtility.DisplayProgressBar("Baking Lighting", "Baking " + envChange.levels[levelIndex], (float)levelIndex / (float)numLevels);
                string[] levels = new string[1];
                levels[0] = "Assets/AudioSpaces/Scenes/" + envChange.levels[levelIndex] + ".unity";
                Lightmapping.BakeMultipleScenes(levels);
            }
            EditorUtility.ClearProgressBar();
        }
    }
Exemplo n.º 6
0
    //-------------------------------------------------------------------------------------------------------------------------
    // 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();
        }
    }
Exemplo n.º 7
0
 public static void BatchBake()
 {
     String[] levels = { "Assets/Scenes/master.unity", "Assets/Scenes/Prototype01_lighting.unity" };
     Lightmapping.BakeMultipleScenes(levels);
 }
Exemplo n.º 8
0
    protected override void OnGUI()
    {
        base.OnGUI();

        List <SECTR_Sector> sortedSectors = new List <SECTR_Sector>(SECTR_Sector.All);

        sortedSectors.Sort(delegate(SECTR_Sector a, SECTR_Sector b) { return(a.name.CompareTo(b.name)); });
        int  numSectors      = sortedSectors.Count;
        bool sceneHasSectors = numSectors > 0;

        EditorGUILayout.BeginVertical();
        DrawHeader("SECTORS", ref sectorSearch, 100, true);
        Rect r = EditorGUILayout.BeginVertical();

        r.y           -= lineHeight;
        scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
        bool wasEnabled = GUI.enabled;

        GUI.enabled = false;
        GUI.Button(r, sceneHasSectors ? "" : "Current Scene Has No Sectors");
        GUI.enabled = wasEnabled;
        bool         allExported       = true;
        bool         allImported       = true;
        bool         someImported      = false;
        SECTR_Sector newSelectedSector = Selection.activeGameObject ?  Selection.activeGameObject.GetComponent <SECTR_Sector>() : null;;
        bool         mouseDown         = Event.current.type == EventType.MouseDown && Event.current.button == 0;

        if (mouseDown)
        {
            newSelectedSector = null;
        }

        for (int sectorIndex = 0; sectorIndex < numSectors; ++sectorIndex)
        {
            SECTR_Sector sector = sortedSectors[sectorIndex];
            if (sector.name.ToLower().Contains(sectorSearch.ToLower()))
            {
                bool selected = sector == selectedSector;
                Rect clipRect = EditorGUILayout.BeginHorizontal();
                if (selected)
                {
                    Rect selectionRect = clipRect;
                    selectionRect.y      += 1;
                    selectionRect.height -= 1;
                    GUI.Box(selectionRect, "", selectionBoxStyle);
                }
                if (sector.Frozen)
                {
                    allImported = false;
                }
                else
                {
                    if (sector.GetComponent <SECTR_Chunk>())
                    {
                        someImported = true;
                    }
                    allExported = false;
                }

                elementStyle.normal.textColor = selected ? Color.white : UnselectedItemColor;
                elementStyle.alignment        = TextAnchor.MiddleCenter;
                EditorGUILayout.LabelField(sector.name, elementStyle);

                EditorGUILayout.EndHorizontal();

                if (sector.gameObject.isStatic)
                {
                    float       buttonWidth     = 50;
                    SECTR_Chunk chunk           = sector.GetComponent <SECTR_Chunk>();
                    bool        alreadyExported = chunk && System.IO.File.Exists(SECTR_Asset.UnityToOSPath(chunk.NodeName));
                    if (sector.Frozen)
                    {
                        // Import
                        if (alreadyExported &&
                            GUI.Button(new Rect(0, clipRect.yMin, buttonWidth, clipRect.height), new GUIContent("Import", "Imports this Sector into the scene.")))
                        {
                            SECTR_StreamExport.ImportFromChunk(sector);
                            break;
                        }
                    }
                    else
                    {
                        // Revert
                        if (alreadyExported &&
                            GUI.Button(new Rect(0, clipRect.yMin, buttonWidth, clipRect.height), new GUIContent("Revert", "Discards changes to this Sector.")))
                        {
                            SECTR_StreamExport.DeleteExportedSector(sector);
                            chunk.enabled = true;
                            break;
                        }
                        // Export
                        if (GUI.Button(new Rect(clipRect.xMax - buttonWidth, clipRect.yMin, buttonWidth, clipRect.height), new GUIContent("Export", "Exports this Sector into a Chunk scene.")))
                        {
                            SECTR_StreamExport.ExportToChunk(sector);
                            break;
                        }
                    }
                }

                if (mouseDown && clipRect.Contains(Event.current.mousePosition))
                {
                    newSelectedSector = sector;
                }
            }
        }
        if (newSelectedSector != selectedSector)
        {
            selectedSector             = newSelectedSector;
            Selection.activeGameObject = selectedSector ? selectedSector.gameObject : null;
            if (SceneView.lastActiveSceneView)
            {
                SceneView.lastActiveSceneView.FrameSelected();
            }
            Repaint();
        }
        EditorGUILayout.EndScrollView();
        EditorGUILayout.EndVertical();

        string nullSearch = null;

        GUI.enabled = true;
        DrawHeader("EXPORT AND IMPORT", ref nullSearch, 0, true);
        wasEnabled = GUI.enabled;
        bool editMode = !EditorApplication.isPlaying && !EditorApplication.isPaused;

        GUI.enabled = sceneHasSectors && !allExported && wasEnabled && editMode;
        if (GUILayout.Button(new GUIContent("Export All Sectors", "Exports all static Sectors into Chunk scenes and prepares them for streaming.")))
        {
            SECTR_StreamExport.ExportSceneChunksUI();
            Repaint();
        }
        GUI.enabled = sceneHasSectors && !allImported && wasEnabled && editMode;
        if (GUILayout.Button(new GUIContent("Import All Sectors", "Imports all exported Chunks back into the scene.")))
        {
            SECTR_StreamExport.ImportSceneChunksUI();
            Repaint();
        }
        GUI.enabled = sceneHasSectors && !allExported && someImported && wasEnabled && editMode;
        if (GUILayout.Button(new GUIContent("Revert All Sectors", "Reverts all exported Chunks to their exported state.")))
        {
            SECTR_StreamExport.RevertSceneChunksUI();
            Repaint();
        }

        GUI.enabled = true;
        DrawHeader("LIGHTMAPPING", ref nullSearch, 0, true);
#if UNITY_5_LATE
        GUI.enabled = sceneHasSectors && selectedSector && allExported && wasEnabled && editMode;
        if (GUILayout.Button(new GUIContent("Lightmap Selected Sector", "Lightmaps selected Sector in isolation.")))
        {
            if (EditorUtility.DisplayDialog("Confirm Lightmap Bake", "Are you sure you want to bake lightmaps for " + selectedSector.name +
                                            "? Its lighting will not be affected by any other Sectors.", "Yes", "No"))
            {
                string[] paths = new string[2];
                paths[0] = EditorApplication.currentScene;
                paths[1] = selectedSector.GetComponent <SECTR_Chunk>().NodeName;
                Lightmapping.BakeMultipleScenes(paths);
            }
        }

        GUI.enabled = sceneHasSectors && allExported && wasEnabled && editMode;
        if (GUILayout.Button(new GUIContent("Lightmap All Sectors", "Lightmaps all exported Chunks.")))
        {
            if (EditorUtility.DisplayDialog("Confirm Lightmap Bake", "Are you sure you want to bake lightmaps for all subscenes? This may take quite a while.", "Yes", "No"))
            {
                string[] paths = new string[numSectors + 1];
                paths[0] = EditorApplication.currentScene;
                for (int sectorIndex = 0; sectorIndex < numSectors; ++sectorIndex)
                {
                    paths[sectorIndex + 1] = sortedSectors[sectorIndex].GetComponent <SECTR_Chunk>().NodeName;
                }
                Lightmapping.BakeMultipleScenes(paths);
            }
        }
#endif
        GUI.enabled = true;
        DrawHeader("EXTRA", ref nullSearch, 0, true);
        GUI.enabled = sceneHasSectors;
        if (GUILayout.Button(new GUIContent("Export Sector Graph Visualization", "Writes out a .dot file of the Sector/Portal graph, which can be visualized in GraphViz.")))
        {
            SECTR_StreamExport.WriteGraphDot();
        }
        GUI.enabled = wasEnabled;
        EditorGUILayout.EndVertical();
    }
        public static void CreateRenderTestScenes(this SampleSet sampleSet)
        {
#if GLTFAST_RENDER_TEST
            var allScenes     = new List <EditorBuildSettingsScene>();
            var allScenePaths = new List <string>();
            // Texture2D dummyReference = null;
            var setName = sampleSet.name;

            var renderPipeline = RenderPipelineUtils.DetectRenderPipeline();

            foreach (var item in sampleSet.GetItems())
            {
                var testScene = EditorSceneManager.OpenScene("Assets/Scenes/TestScene.unity");

                var settingsGameObject   = new GameObject("GraphicsTestSettings");
                var graphicsTestSettings = settingsGameObject.AddComponent <UniversalGraphicsTestSettings>();
                graphicsTestSettings.WaitFrames = renderPipeline == RenderPipeline.HighDefinition ? 2 : 0;

                var go        = new GameObject(item.name);
                var gltfAsset = go.AddComponent <GltfBoundsAsset>();

                if (string.IsNullOrEmpty(sampleSet.streamingAssetsPath))
                {
                    gltfAsset.url = Path.Combine(sampleSet.baseLocalPath, item.path);
                }
                else
                {
                    gltfAsset.url            = Path.Combine(sampleSet.streamingAssetsPath, item.path);
                    gltfAsset.streamingAsset = true;
                }
                gltfAsset.loadOnStartup     = false;
                gltfAsset.createBoxCollider = false;

                var sceneDirectory = CertifyDirectory(item.directoryParts, string.Format("Assets/Scenes/{0}", setName));
                var scenePath      = Path.Combine(sceneDirectory, item.name + ".unity");

                EditorSceneManager.SaveScene(testScene, scenePath);
                allScenes.Add(new EditorBuildSettingsScene(scenePath, true));
                allScenePaths.Add(scenePath);

                // CertifyDirectory(new[] { "ReferenceImages", "Linear", "OSXEditor", "Metal", "None" }, "Assets");
                // var referenceImagePath =
                //     Path.Combine(Application.dataPath, "ReferenceImages/Linear/OSXEditor/Metal/None", item.name + ".png");
                //
                // if (!File.Exists(referenceImagePath)) {
                //     Debug.LogFormat("Create dummy reference at path {0}", referenceImagePath);
                //     dummyReference = dummyReference!=null
                //         ? dummyReference
                //         : new Texture2D(
                //         graphicsTestSettings.ImageComparisonSettings.TargetWidth,
                //         graphicsTestSettings.ImageComparisonSettings.TargetHeight
                //     );
                //     File.WriteAllBytes(referenceImagePath, dummyReference.EncodeToPNG());
                // }
            }
            AssetDatabase.Refresh();
            EditorBuildSettings.scenes = allScenes.ToArray();

            Lightmapping.BakeMultipleScenes(allScenePaths.ToArray());
#else
            Debug.LogWarning("Please install the Graphics Test Framework for render tests to work.");
#endif
        }
Exemplo n.º 10
0
 public static void BakeAllScenes()
 {
     Lightmapping.BakeMultipleScenes(EditorBuildSettings.scenes.Select(scene => scene.path).ToArray());
 }