├── ProjectSettings ├── ProjectVersion.txt ├── TagManager.asset ├── AudioManager.asset ├── InputManager.asset ├── NavMeshAreas.asset ├── TimeManager.asset ├── DynamicsManager.asset ├── EditorSettings.asset ├── NetworkManager.asset ├── ProjectSettings.asset ├── QualitySettings.asset ├── GraphicsSettings.asset ├── Physics2DSettings.asset ├── ClusterInputManager.asset ├── EditorBuildSettings.asset └── UnityConnectSettings.asset ├── README.md ├── Assets ├── mat.mat ├── test.unity ├── test │ ├── LightingData.asset │ ├── Lightmap-0_comp_dir_0.exr │ ├── Lightmap-0_comp_dir_1.exr │ ├── Lightmap-0_comp_light.exr │ ├── Lightmap-0_comp_light_0.exr │ ├── Lightmap-0_comp_light_1.exr │ ├── LightingData.asset.meta │ ├── Lightmap-0_comp_dir_0.exr.meta │ ├── Lightmap-0_comp_dir_1.exr.meta │ ├── Lightmap-0_comp_light.exr.meta │ ├── Lightmap-0_comp_light_0.exr.meta │ └── Lightmap-0_comp_light_1.exr.meta ├── test.unity.meta ├── test.meta ├── Editor.meta ├── script.meta ├── mat.mat.meta ├── script │ ├── U3dExtend.cs.meta │ ├── LightMapDataCtrl.cs.meta │ ├── U3dExtend.cs │ └── LightMapDataCtrl.cs └── Editor │ ├── EditorCoroutine.cs.meta │ ├── SceneEditorTool.cs.meta │ ├── EditorCoroutine.cs │ └── SceneEditorTool.cs └── .gitignore /ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 5.6.6f2 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UnityCullMaskBake 2 | Unity Bake LightMap with light cullmask 3 | -------------------------------------------------------------------------------- /Assets/mat.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gordonbest/UnityCullMaskBake/HEAD/Assets/mat.mat -------------------------------------------------------------------------------- /Assets/test.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gordonbest/UnityCullMaskBake/HEAD/Assets/test.unity -------------------------------------------------------------------------------- /Assets/test/LightingData.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gordonbest/UnityCullMaskBake/HEAD/Assets/test/LightingData.asset -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gordonbest/UnityCullMaskBake/HEAD/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gordonbest/UnityCullMaskBake/HEAD/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gordonbest/UnityCullMaskBake/HEAD/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gordonbest/UnityCullMaskBake/HEAD/ProjectSettings/NavMeshAreas.asset -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gordonbest/UnityCullMaskBake/HEAD/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /Assets/test/Lightmap-0_comp_dir_0.exr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gordonbest/UnityCullMaskBake/HEAD/Assets/test/Lightmap-0_comp_dir_0.exr -------------------------------------------------------------------------------- /Assets/test/Lightmap-0_comp_dir_1.exr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gordonbest/UnityCullMaskBake/HEAD/Assets/test/Lightmap-0_comp_dir_1.exr -------------------------------------------------------------------------------- /Assets/test/Lightmap-0_comp_light.exr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gordonbest/UnityCullMaskBake/HEAD/Assets/test/Lightmap-0_comp_light.exr -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gordonbest/UnityCullMaskBake/HEAD/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gordonbest/UnityCullMaskBake/HEAD/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gordonbest/UnityCullMaskBake/HEAD/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gordonbest/UnityCullMaskBake/HEAD/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gordonbest/UnityCullMaskBake/HEAD/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /Assets/test/Lightmap-0_comp_light_0.exr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gordonbest/UnityCullMaskBake/HEAD/Assets/test/Lightmap-0_comp_light_0.exr -------------------------------------------------------------------------------- /Assets/test/Lightmap-0_comp_light_1.exr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gordonbest/UnityCullMaskBake/HEAD/Assets/test/Lightmap-0_comp_light_1.exr -------------------------------------------------------------------------------- /ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gordonbest/UnityCullMaskBake/HEAD/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gordonbest/UnityCullMaskBake/HEAD/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ClusterInputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gordonbest/UnityCullMaskBake/HEAD/ProjectSettings/ClusterInputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gordonbest/UnityCullMaskBake/HEAD/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/UnityConnectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gordonbest/UnityCullMaskBake/HEAD/ProjectSettings/UnityConnectSettings.asset -------------------------------------------------------------------------------- /Assets/test.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e04ad7dafc654d741985829527f4abf7 3 | timeCreated: 1564725511 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/test.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c4f9ccc17701ab44faa2cc193ea907ee 3 | folderAsset: yes 4 | timeCreated: 1564725779 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b4ceee8c3cc632648aba78f42e700a5e 3 | folderAsset: yes 4 | timeCreated: 1564725822 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/script.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5fa77de86bdf8774d882c1afa5610f13 3 | folderAsset: yes 4 | timeCreated: 1564725814 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/mat.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 20ef2acd47426274490dee79a980d2d3 3 | timeCreated: 1564725562 4 | licenseType: Pro 5 | NativeFormatImporter: 6 | mainObjectFileID: 2100000 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/test/LightingData.asset.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 279d8c45d95682a48bdf3bbe3eedee77 3 | timeCreated: 1564728134 4 | licenseType: Pro 5 | NativeFormatImporter: 6 | mainObjectFileID: 25800000 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/script/U3dExtend.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 75620054cafe84346b33457ba7579f1a 3 | timeCreated: 1564726087 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Editor/EditorCoroutine.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: dcc8af4394442504eb87dfbf694f48f5 3 | timeCreated: 1564726286 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Editor/SceneEditorTool.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 711ad3be5e11efa46b6ca2f7cb71cd74 3 | timeCreated: 1564725912 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/script/LightMapDataCtrl.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 71fd4bcc1bf70dd449afb9505fc64c3d 3 | timeCreated: 1564725851 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | [Ll]ibrary/ 2 | [Tt]emp/ 3 | [Oo]bj/ 4 | [Bb]uild/ 5 | [Bb]uilds/ 6 | Assets/AssetStoreTools* 7 | 8 | # Visual Studio cache directory 9 | .vs/ 10 | 11 | # Autogenerated VS/MD/Consulo solution and project files 12 | ExportedObj/ 13 | .consulo/ 14 | *.csproj 15 | *.unityproj 16 | *.sln 17 | *.suo 18 | *.tmp 19 | *.user 20 | *.userprefs 21 | *.pidb 22 | *.booproj 23 | *.svd 24 | *.pdb 25 | *.opendb 26 | 27 | # Unity3D generated meta files 28 | *.pidb.meta 29 | *.pdb.meta 30 | 31 | # Unity3D Generated File On Crash Reports 32 | sysinfo.txt 33 | 34 | # Builds 35 | *.apk 36 | *.unitypackage 37 | /.localhistory 38 | /.vs 39 | -------------------------------------------------------------------------------- /Assets/Editor/EditorCoroutine.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using UnityEditor; 5 | using UnityEngine; 6 | using Object = UnityEngine.Object; 7 | public class EditorCoroutine 8 | { 9 | public static EditorCoroutine start(IEnumerator _routine) 10 | { 11 | EditorCoroutine coroutine = new EditorCoroutine(_routine); 12 | coroutine.start(); 13 | return coroutine; 14 | } 15 | 16 | readonly IEnumerator routine; 17 | EditorCoroutine(IEnumerator _routine) 18 | { 19 | routine = _routine; 20 | } 21 | 22 | void start() 23 | { 24 | EditorApplication.update += update; 25 | } 26 | public void stop() 27 | { 28 | EditorApplication.update -= update; 29 | } 30 | 31 | void update() 32 | { 33 | if (!routine.MoveNext()) 34 | { 35 | stop(); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /Assets/script/U3dExtend.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using UnityEngine; 5 | using UnityEngine.UI; 6 | 7 | namespace Game 8 | { 9 | public static class U3DExtend 10 | { 11 | public static Component TryGetOrAddComponent(this GameObject self, Type type ) 12 | { 13 | if (type.IsSubclassOf(typeof(Component))) 14 | { 15 | Component c = self.GetComponent(type); 16 | if (c == null) 17 | { 18 | return self.AddComponent(type); 19 | } 20 | else 21 | { 22 | return c; 23 | } 24 | } 25 | else 26 | { 27 | return null; 28 | } 29 | } 30 | 31 | public static T FetchComponent(this GameObject self) 32 | where T:Component 33 | { 34 | return (T)self.TryGetOrAddComponent(typeof(T)); 35 | } 36 | 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Assets/test/Lightmap-0_comp_dir_0.exr.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4197625caca522a469d8d0e18f448852 3 | timeCreated: 1564726969 4 | licenseType: Pro 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 4 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 1 11 | sRGBTexture: 0 12 | linearTexture: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 6 25 | cubemapConvolution: 0 26 | seamlessCubemap: 0 27 | textureFormat: 1 28 | maxTextureSize: 2048 29 | textureSettings: 30 | filterMode: 1 31 | aniso: 3 32 | mipBias: 0 33 | wrapMode: 1 34 | nPOTScale: 1 35 | lightmap: 0 36 | compressionQuality: 50 37 | spriteMode: 0 38 | spriteExtrude: 1 39 | spriteMeshType: 1 40 | alignment: 0 41 | spritePivot: {x: 0.5, y: 0.5} 42 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 43 | spritePixelsToUnits: 100 44 | alphaUsage: 1 45 | alphaIsTransparency: 0 46 | spriteTessellationDetail: -1 47 | textureType: 0 48 | textureShape: 1 49 | maxTextureSizeSet: 0 50 | compressionQualitySet: 0 51 | textureFormatSet: 0 52 | platformSettings: 53 | - buildTarget: DefaultTexturePlatform 54 | maxTextureSize: 2048 55 | textureFormat: -1 56 | textureCompression: 1 57 | compressionQuality: 50 58 | crunchedCompression: 0 59 | allowsAlphaSplitting: 0 60 | overridden: 0 61 | spriteSheet: 62 | serializedVersion: 2 63 | sprites: [] 64 | outline: [] 65 | spritePackingTag: 66 | userData: 67 | assetBundleName: 68 | assetBundleVariant: 69 | -------------------------------------------------------------------------------- /Assets/test/Lightmap-0_comp_dir_1.exr.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fae200bd24db8b048888b2f1d1849c3d 3 | timeCreated: 1564726971 4 | licenseType: Pro 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 4 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 1 11 | sRGBTexture: 0 12 | linearTexture: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 6 25 | cubemapConvolution: 0 26 | seamlessCubemap: 0 27 | textureFormat: 1 28 | maxTextureSize: 2048 29 | textureSettings: 30 | filterMode: 1 31 | aniso: 3 32 | mipBias: 0 33 | wrapMode: 1 34 | nPOTScale: 1 35 | lightmap: 0 36 | compressionQuality: 50 37 | spriteMode: 0 38 | spriteExtrude: 1 39 | spriteMeshType: 1 40 | alignment: 0 41 | spritePivot: {x: 0.5, y: 0.5} 42 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 43 | spritePixelsToUnits: 100 44 | alphaUsage: 1 45 | alphaIsTransparency: 0 46 | spriteTessellationDetail: -1 47 | textureType: 0 48 | textureShape: 1 49 | maxTextureSizeSet: 0 50 | compressionQualitySet: 0 51 | textureFormatSet: 0 52 | platformSettings: 53 | - buildTarget: DefaultTexturePlatform 54 | maxTextureSize: 2048 55 | textureFormat: -1 56 | textureCompression: 1 57 | compressionQuality: 50 58 | crunchedCompression: 0 59 | allowsAlphaSplitting: 0 60 | overridden: 0 61 | spriteSheet: 62 | serializedVersion: 2 63 | sprites: [] 64 | outline: [] 65 | spritePackingTag: 66 | userData: 67 | assetBundleName: 68 | assetBundleVariant: 69 | -------------------------------------------------------------------------------- /Assets/test/Lightmap-0_comp_light.exr.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e6123b9c924f8fa4fb9a587f84a41232 3 | timeCreated: 1564728134 4 | licenseType: Pro 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 4 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 1 11 | sRGBTexture: 1 12 | linearTexture: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 6 25 | cubemapConvolution: 0 26 | seamlessCubemap: 0 27 | textureFormat: 1 28 | maxTextureSize: 2048 29 | textureSettings: 30 | filterMode: 1 31 | aniso: 3 32 | mipBias: 0 33 | wrapMode: 1 34 | nPOTScale: 1 35 | lightmap: 0 36 | compressionQuality: 50 37 | spriteMode: 0 38 | spriteExtrude: 1 39 | spriteMeshType: 1 40 | alignment: 0 41 | spritePivot: {x: 0.5, y: 0.5} 42 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 43 | spritePixelsToUnits: 100 44 | alphaUsage: 0 45 | alphaIsTransparency: 0 46 | spriteTessellationDetail: -1 47 | textureType: 6 48 | textureShape: 1 49 | maxTextureSizeSet: 0 50 | compressionQualitySet: 0 51 | textureFormatSet: 0 52 | platformSettings: 53 | - buildTarget: DefaultTexturePlatform 54 | maxTextureSize: 2048 55 | textureFormat: -1 56 | textureCompression: 1 57 | compressionQuality: 50 58 | crunchedCompression: 0 59 | allowsAlphaSplitting: 0 60 | overridden: 0 61 | spriteSheet: 62 | serializedVersion: 2 63 | sprites: [] 64 | outline: [] 65 | spritePackingTag: 66 | userData: 67 | assetBundleName: 68 | assetBundleVariant: 69 | -------------------------------------------------------------------------------- /Assets/test/Lightmap-0_comp_light_0.exr.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b032d311035016242af4398d6d3cdcff 3 | timeCreated: 1564727759 4 | licenseType: Pro 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 4 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 1 11 | sRGBTexture: 1 12 | linearTexture: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 6 25 | cubemapConvolution: 0 26 | seamlessCubemap: 0 27 | textureFormat: 1 28 | maxTextureSize: 2048 29 | textureSettings: 30 | filterMode: 1 31 | aniso: 3 32 | mipBias: 0 33 | wrapMode: 1 34 | nPOTScale: 1 35 | lightmap: 0 36 | compressionQuality: 50 37 | spriteMode: 0 38 | spriteExtrude: 1 39 | spriteMeshType: 1 40 | alignment: 0 41 | spritePivot: {x: 0.5, y: 0.5} 42 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 43 | spritePixelsToUnits: 100 44 | alphaUsage: 0 45 | alphaIsTransparency: 0 46 | spriteTessellationDetail: -1 47 | textureType: 6 48 | textureShape: 1 49 | maxTextureSizeSet: 0 50 | compressionQualitySet: 0 51 | textureFormatSet: 0 52 | platformSettings: 53 | - buildTarget: DefaultTexturePlatform 54 | maxTextureSize: 2048 55 | textureFormat: -1 56 | textureCompression: 1 57 | compressionQuality: 50 58 | crunchedCompression: 0 59 | allowsAlphaSplitting: 0 60 | overridden: 0 61 | spriteSheet: 62 | serializedVersion: 2 63 | sprites: [] 64 | outline: [] 65 | spritePackingTag: 66 | userData: 67 | assetBundleName: 68 | assetBundleVariant: 69 | -------------------------------------------------------------------------------- /Assets/test/Lightmap-0_comp_light_1.exr.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1b63a06d6bccf634d8f4a7cba4fee080 3 | timeCreated: 1564727760 4 | licenseType: Pro 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 4 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 1 11 | sRGBTexture: 1 12 | linearTexture: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 6 25 | cubemapConvolution: 0 26 | seamlessCubemap: 0 27 | textureFormat: 1 28 | maxTextureSize: 2048 29 | textureSettings: 30 | filterMode: 1 31 | aniso: 3 32 | mipBias: 0 33 | wrapMode: 1 34 | nPOTScale: 1 35 | lightmap: 0 36 | compressionQuality: 50 37 | spriteMode: 0 38 | spriteExtrude: 1 39 | spriteMeshType: 1 40 | alignment: 0 41 | spritePivot: {x: 0.5, y: 0.5} 42 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 43 | spritePixelsToUnits: 100 44 | alphaUsage: 0 45 | alphaIsTransparency: 0 46 | spriteTessellationDetail: -1 47 | textureType: 6 48 | textureShape: 1 49 | maxTextureSizeSet: 0 50 | compressionQualitySet: 0 51 | textureFormatSet: 0 52 | platformSettings: 53 | - buildTarget: DefaultTexturePlatform 54 | maxTextureSize: 2048 55 | textureFormat: -1 56 | textureCompression: 1 57 | compressionQuality: 50 58 | crunchedCompression: 0 59 | allowsAlphaSplitting: 0 60 | overridden: 0 61 | spriteSheet: 62 | serializedVersion: 2 63 | sprites: [] 64 | outline: [] 65 | spritePackingTag: 66 | userData: 67 | assetBundleName: 68 | assetBundleVariant: 69 | -------------------------------------------------------------------------------- /Assets/script/LightMapDataCtrl.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | 6 | [Serializable] 7 | public class LightMapDataCtrl : MonoBehaviour 8 | { 9 | [SerializeField] 10 | public int lightmapIndex; 11 | [SerializeField] 12 | private Vector4 lightmapScaleOffset; 13 | 14 | public void resetLightMapData() 15 | { 16 | Renderer render = gameObject.GetComponent(); 17 | if (render) 18 | { 19 | render.lightmapIndex = lightmapIndex; 20 | render.lightmapScaleOffset = lightmapScaleOffset; 21 | } 22 | } 23 | 24 | public void SaveLightMapData() 25 | { 26 | Renderer render = gameObject.GetComponent(); 27 | if (render) 28 | { 29 | lightmapIndex = render.lightmapIndex; 30 | lightmapScaleOffset = render.lightmapScaleOffset; 31 | } 32 | } 33 | } 34 | 35 | [Serializable] 36 | public class LightMapDataSet : MonoBehaviour 37 | { 38 | [Serializable] 39 | public class Set 40 | { 41 | public Texture2D color; 42 | public Texture2D dir; 43 | public Texture2D mask; 44 | 45 | public Set(LightmapData data) 46 | { 47 | color = data.lightmapColor; 48 | dir = data.lightmapDir; 49 | mask = data.shadowMask; 50 | } 51 | 52 | public LightmapData toData() 53 | { 54 | LightmapData data = new LightmapData(); 55 | data.lightmapColor = color; 56 | data.lightmapDir = dir; 57 | data.shadowMask = mask; 58 | return data; 59 | } 60 | } 61 | 62 | [SerializeField] 63 | private Set[] sets; 64 | [SerializeField] 65 | public LightMapDataCtrl[] ctrls; 66 | void Start() 67 | { 68 | reset(); 69 | } 70 | public void reset() 71 | { 72 | if (sets != null && sets.Length > 0) 73 | { 74 | LightmapData[] datas = new LightmapData[sets.Length]; 75 | for (int i = 0; i < sets.Length; i++) 76 | { 77 | datas[i] = sets[i].toData(); 78 | } 79 | LightmapSettings.lightmaps = datas; 80 | 81 | for (int i = 0; i < ctrls.Length; i++) 82 | { 83 | ctrls[i].resetLightMapData(); 84 | } 85 | } 86 | } 87 | 88 | public void Save(LightMapDataCtrl[] allCtrls) 89 | { 90 | ctrls = allCtrls; 91 | LightmapData[] datas = LightmapSettings.lightmaps; 92 | if (datas != null) 93 | { 94 | sets = new Set[datas.Length]; 95 | for (int i = 0; i < datas.Length; i++) 96 | { 97 | sets[i] = new Set(datas[i]); 98 | } 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /Assets/Editor/SceneEditorTool.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using Game; 7 | using UnityEditor; 8 | using UnityEditor.SceneManagement; 9 | 10 | 11 | [InitializeOnLoad] 12 | public class ToggleLightMapSet 13 | { 14 | static ToggleLightMapSet() 15 | { 16 | EditorApplication.playmodeStateChanged += LogPlayModeState; 17 | } 18 | 19 | private static void LogPlayModeState() 20 | { 21 | if (EditorApplication.isPlaying == false && EditorApplication.isCompiling == false) 22 | { 23 | LightMapDataSet set = Object.FindObjectOfType(); 24 | if (set != null) 25 | { 26 | //when application stoped, unity will use lightmapasset reset lightmap info ,that will change what we need 27 | //so we reset lightmap info by custom set 28 | set.reset(); 29 | } 30 | } 31 | } 32 | } 33 | 34 | public class SceneEditorTool 35 | { 36 | static List LightMapTextures = new List(); 37 | static WaitForSeconds _bakeWait = new WaitForSeconds(5); 38 | 39 | [MenuItem("Tool/Cull Bake")] 40 | static void Bake() 41 | { 42 | EditorCoroutine.start(DoMultiBake()); 43 | 44 | } 45 | 46 | 47 | 48 | private static IEnumerator DoMultiBake() 49 | { 50 | LightMapTextures.Clear(); 51 | 52 | //part logic from https://answers.unity.com/questions/61158/beast-lightmap-ignores-light-culling-mask-andor-la.html 53 | // Get all lights which are active in the scene 54 | Light[] lights = (from light in (Object.FindObjectsOfType(typeof(Light)) as Light[]) 55 | where (light.enabled == true && light.gameObject.activeInHierarchy == true) 56 | select light).ToArray(); 57 | 58 | // Get all the game objects which are active in the scene 59 | GameObject[] gameObjects = (from go in (Object.FindObjectsOfType(typeof(GameObject)) as GameObject[]) 60 | where (go.activeInHierarchy == true && 61 | (GameObjectUtility.GetStaticEditorFlags(go) & StaticEditorFlags.LightmapStatic) > 0 && 62 | (go.GetComponent() != null)) 63 | select go).ToArray(); 64 | 65 | ILookup gameObjectGroups = gameObjects.ToLookup(go => (1 << go.layer)); 66 | 67 | 68 | 69 | yield return null; 70 | 71 | //disable all light and objs 72 | SetActive(lights, false); 73 | SetActive(gameObjects, false); 74 | 75 | 76 | yield return _bakeWait; 77 | 78 | foreach (IGrouping gameObjectGroup in gameObjectGroups) 79 | { 80 | int layerForGroup = gameObjectGroup.Key; 81 | 82 | GameObject[] gameObjectsForLayer = gameObjectGroup.ToArray(); 83 | Light[] lightsForLayer = (from light in lights where (light.cullingMask == layerForGroup) select light).ToArray(); 84 | 85 | if (lightsForLayer.Length > 0) 86 | { 87 | SetActive(lightsForLayer, true); 88 | SetActive(gameObjectsForLayer, true); 89 | 90 | yield return _bakeWait; 91 | UnityEditor.Lightmapping.Bake(); 92 | 93 | 94 | 95 | int indexOffset = LightMapTextures.Count; 96 | for (int i = 0; i < LightmapSettings.lightmaps.Length; i++) 97 | { 98 | LightmapData lightData = LightmapSettings.lightmaps[i]; 99 | 100 | //resave lightmap texture 101 | lightData.lightmapColor = reSaveLightTexture(lightData.lightmapColor, i + indexOffset); 102 | lightData.lightmapDir = reSaveLightTexture(lightData.lightmapDir, i + indexOffset); 103 | lightData.shadowMask = reSaveLightTexture(lightData.shadowMask, i + indexOffset); 104 | 105 | LightMapTextures.Add(lightData); 106 | } 107 | 108 | LightmapSettings.lightmaps = new LightmapData[0]; 109 | for (int i = 0; i < gameObjectsForLayer.Length; i++) 110 | { 111 | LightMapDataCtrl ctrl = gameObjectsForLayer[i].FetchComponent(); 112 | ctrl.SaveLightMapData(); 113 | ctrl.lightmapIndex += indexOffset; // changeIndexInfo 114 | } 115 | 116 | yield return _bakeWait; 117 | // Disable the objects 118 | 119 | SetActive(lightsForLayer, false); 120 | SetActive(gameObjectsForLayer, false); 121 | } 122 | } 123 | yield return _bakeWait; 124 | 125 | // here to bake all light, but with out objs 126 | //to make light as baked mode 127 | SetActive(lights, true); 128 | SetActive(gameObjects, false); 129 | yield return _bakeWait; 130 | UnityEditor.Lightmapping.Bake(); 131 | yield return _bakeWait; 132 | 133 | 134 | //set lightmap back 135 | LightmapSettings.lightmaps = LightMapTextures.ToArray(); 136 | 137 | SetActive(gameObjects, true); 138 | 139 | 140 | yield return _bakeWait; 141 | GameObject mapRoot = GameObject.Find("Scene");//need a mesh root 142 | if (mapRoot != null) 143 | { 144 | //Serialize custorm data to LightMapDataSet 145 | LightMapDataCtrl[] ctrls = new LightMapDataCtrl[gameObjects.Length]; 146 | for (int i = 0; i < gameObjects.Length; i++) 147 | { 148 | ctrls[i] = gameObjects[i].FetchComponent(); 149 | } 150 | LightMapDataSet set = mapRoot.FetchComponent(); 151 | set.Save(ctrls); 152 | set.reset(); 153 | 154 | EditorSceneManager.MarkAllScenesDirty(); 155 | } 156 | AssetDatabase.SaveAssets(); 157 | AssetDatabase.Refresh(); 158 | } 159 | 160 | private static Texture2D reSaveLightTexture(Texture2D texture, int index) 161 | { 162 | if (texture == null) 163 | { 164 | return null; 165 | } 166 | string assetName = AssetDatabase.GetAssetPath(texture); 167 | string newPath = Path.Combine(Path.GetDirectoryName(assetName), Path.GetFileNameWithoutExtension(assetName) +"_"+index+ ".exr"); 168 | AssetDatabase.CopyAsset(assetName, newPath); 169 | 170 | Texture2D result = AssetDatabase.LoadAssetAtPath(newPath); 171 | return result; 172 | } 173 | 174 | static void SetActive(Light[] lights, bool active) 175 | { 176 | foreach (Light light in lights) 177 | { 178 | light.gameObject.SetActive(active); 179 | } 180 | 181 | } 182 | 183 | static void SetActive(GameObject[] objs, bool active) 184 | { 185 | foreach (GameObject obj in objs) 186 | { 187 | obj.SetActive(active); 188 | } 189 | } 190 | } 191 | --------------------------------------------------------------------------------