コード例 #1
0
        static SceneLightmap SaveSceneLightmap(int lightmap_index, string name)
        {
            int i = lightmap_index;

            SceneLightmap slm = new SceneLightmap {
                lightMapIndex = lightmap_index
            };

            // Create folder if it doesn't exist

            Directory.CreateDirectory(Window.folder);

            // Update paths definitions

            var dsc = Path.AltDirectorySeparatorChar;

            string copyFrom, saveTo,
                   filename = folder_scene + "Lightmap-" + i,
                   newFile  = Window.folder + dsc + name + dsc + name;

            // Save color texture

            if (LightmapSettings.lightmaps[i].lightmapColor != null)
            {
                copyFrom = $"{filename}_comp_light.exr";
                saveTo   = $"{newFile}_light-{ i }.asset";

                slm.texColor = EditorUtils.SaveLightmapAsset(copyFrom, saveTo);
            }

            // Save directional texture

            var lightmapDir = LightmapSettings.lightmaps[i].lightmapDir;

            if (lightmapDir != null)
            {
                copyFrom = $"{filename}_comp_dir.png";
                saveTo   = $"{newFile}_dir-{ i }.asset";

                slm.texDir = lightmapDir = EditorUtils.SaveLightmapAsset(copyFrom, saveTo);
            }

            if (lightmapDir == null)
            {
                Debug.LogWarning($"[PrefabBaker] Direction-lightmap { i } was not saved");
            }

            // Save shadow texture

            if (LightmapSettings.lightmaps[i].shadowMask != null)
            {
                copyFrom = $"{filename}_comp_shadowmask.png";
                saveTo   = $"{newFile}_shadow-{ i }.asset";

                slm.texShadow = EditorUtils.SaveLightmapAsset(copyFrom, saveTo);
            }

            return(slm);
        }
コード例 #2
0
        static SceneLightmap GetOrSaveSceneLightmapToAsset(int lightmap_index, string name)
        {
            // Return existing lightmap if matching texture is already in list

            var index = GetSceneLightMapIndex(lightmap_index);

            if (index > -1)
            {
                return(SceneLightmapList[index]);
            }

            // Store scene light map in target folder and register to list

            SceneLightmap slm = SaveSceneLightmap(lightmap_index, name);

            SceneLightmapList.Add(slm);

            return(slm);
        }