diff --git a/Editor/ExportSettingsEditor.cs b/Editor/ExportSettingsEditor.cs index 4d76e1d..06c49cb 100644 --- a/Editor/ExportSettingsEditor.cs +++ b/Editor/ExportSettingsEditor.cs @@ -86,7 +86,7 @@ public override void OnInspectorGUI() EditorUtility.RevealInFinder(script.path); } - if (!string.IsNullOrEmpty(script.path) && !script.path.EndsWith("Data")) + if (!string.IsNullOrEmpty(script.path) && !script.path.EndsWith("Data") && !script.path.EndsWith("Data/") && !script.path.EndsWith("Data\\")) { EditorGUILayout.HelpBox("The path doesn't end with Data. Are you sure you've picked a correct path to a Data folder?", MessageType.Warning); } diff --git a/Editor/TextureExporter.cs b/Editor/TextureExporter.cs index 4928b24..b3e6722 100644 --- a/Editor/TextureExporter.cs +++ b/Editor/TextureExporter.cs @@ -35,7 +35,7 @@ private void ExportDefaultMap(UnityEngine.Texture asset, TextureImporter texture { new TextureProcessor().ProcessAndSaveTexture(asset, "Hidden/UnityToRebelFork/Copy", Settings.ResolveResourceFileName(EvaluateResourcePath(asset)), - textureImporter?.GetAutomaticFormat("Standalone") != TextureImporterFormat.DXT1, new Dictionary + hasAlpha: textureImporter?.GetAutomaticFormat("Standalone") != TextureImporterFormat.DXT1, shaderArgs: new Dictionary { {"_GammaInput",( PlayerSettings.colorSpace == UnityEngine.ColorSpace.Linear)?0.0f:1.0f}, {"_GammaOutput",1.0f}, @@ -48,7 +48,7 @@ private void ExportNormalMap(UnityEngine.Texture asset) Settings.PackNormals ? "Hidden/UnityToRebelFork/DecodeNormalMapPackedNormal" : "Hidden/UnityToRebelFork/DecodeNormalMap", - Settings.ResolveResourceFileName(EvaluateResourcePath(asset))); + Settings.ResolveResourceFileName(EvaluateResourcePath(asset)), compress: Settings.PackNormals); } } } diff --git a/Editor/TextureProcessor.cs b/Editor/TextureProcessor.cs index d52d9ec..94b1fa2 100644 --- a/Editor/TextureProcessor.cs +++ b/Editor/TextureProcessor.cs @@ -14,16 +14,16 @@ namespace UnityToRebelFork.Editor public class TextureProcessor { public void ProcessAndSaveTexture(UnityEngine.Texture sourceTexture, string shaderName, string fullOutputPath, - bool hasAlpha = true, Dictionary shaderArgs = null) + bool hasAlpha = true, bool compress = true, Dictionary shaderArgs = null) { - ProcessAndSaveTexture(sourceTexture, UnityEngine.Shader.Find(shaderName), fullOutputPath, hasAlpha, shaderArgs); + ProcessAndSaveTexture(sourceTexture, UnityEngine.Shader.Find(shaderName), fullOutputPath, hasAlpha, compress, shaderArgs); } public void ProcessTexture(UnityEngine.Texture sourceTexture, string shaderName, Action callback) { ProcessTexture(sourceTexture, UnityEngine.Shader.Find(shaderName), callback); } public void ProcessAndSaveTexture(UnityEngine.Texture sourceTexture, UnityEngine.Shader shader, string fullOutputPath, - bool hasAlpha = true, Dictionary shaderArgs = null) + bool hasAlpha = true, bool compress = true, Dictionary shaderArgs = null) { UnityEngine.Material material = null; @@ -40,7 +40,7 @@ public void ProcessAndSaveTexture(UnityEngine.Texture sourceTexture, UnityEngine } } } - ProcessAndSaveTexture(sourceTexture, material, fullOutputPath, hasAlpha); + ProcessAndSaveTexture(sourceTexture, material, fullOutputPath, hasAlpha: hasAlpha, compress: compress); } finally { @@ -64,10 +64,10 @@ public void ProcessTexture(UnityEngine.Texture sourceTexture, UnityEngine.Shader } public void ProcessAndSaveTexture(UnityEngine.Texture sourceTexture, UnityEngine.Material material, string fullOutputPath, - bool hasAlpha = true) + bool hasAlpha = true, bool compress = true) { ProcessAndSaveTexture(sourceTexture, sourceTexture.width, sourceTexture.height, material, fullOutputPath, - hasAlpha); + hasAlpha: hasAlpha, compress: compress); } public void ProcessTexture(UnityEngine.Texture sourceTexture, UnityEngine.Material material, Action callback) @@ -164,13 +164,13 @@ private RenderTextureFormat PickRenderTextureFormat(UnityEngine.Texture sourceTe } public void ProcessAndSaveTexture(UnityEngine.Texture sourceTexture, int width, int height, UnityEngine.Material material, - string fullOutputPath, bool hasAlpha = true) + string fullOutputPath, bool hasAlpha = true, bool compress = true) { ProcessTexture(sourceTexture, width, height, material, - texture => SaveTexture(texture, fullOutputPath, hasAlpha)); + texture => SaveTexture(texture, fullOutputPath, hasAlpha:hasAlpha, compress:compress)); } - public void SaveTexture(UnityEngine.Texture2D texture, string fullOutputPath, bool hasAlpha = true) + public void SaveTexture(UnityEngine.Texture2D texture, string fullOutputPath, bool hasAlpha = true, bool compress = true) { if (string.IsNullOrWhiteSpace(fullOutputPath)) return; @@ -197,7 +197,7 @@ public void SaveTexture(UnityEngine.Texture2D texture, string fullOutputPath, bo WriteAllBytes(fullOutputPath, exr); break; case ".dds": - DDS.SaveAsRgbaDds(texture, fullOutputPath, hasAlpha); + DDS.SaveAsRgbaDds(texture, fullOutputPath, hasAlpha: hasAlpha, compress: compress); break; default: throw new NotImplementedException("Not implemented texture file type " + ext); @@ -212,15 +212,16 @@ private void WriteAllBytes(string fullOutputPath, byte[] buffer) } } } + public class DDS { - public static void SaveAsRgbaDds(UnityEngine.Texture2D texture, string fileName, bool hasAlpha = true, bool dither = false) + public static void SaveAsRgbaDds(UnityEngine.Texture2D texture, string fileName, bool hasAlpha = true, bool compress = true, bool dither = false) { using (var fileStream = System.IO.File.Open(fileName, FileMode.Create, FileAccess.Write, FileShare.Read)) { using (var binaryWriter = new BinaryWriter(fileStream)) { - var compress = (0 == (texture.width % 4)) && (0 == (texture.height % 4)); + compress = compress && (0 == (texture.width % 4)) && (0 == (texture.height % 4)); if (compress) { WriteCompressedHeader(binaryWriter, texture.width, texture.height, texture.mipmapCount, false,