From 279edb1e0eec4b18edee4d2a01feca2c6162ef24 Mon Sep 17 00:00:00 2001 From: max Date: Sat, 23 Nov 2019 21:59:01 +0100 Subject: [PATCH] Update/bugfix texture export, folder creation, minor changes. Bugfix texture export: where textures regarding of their settings would be exported as sprites. Update texture export: original textures will now be copied to get the pixel values with the correct import settings applied to prevent strange-looking normal maps and color changes. Folder creation: the required folders will now be created by the tool, no need anymore to save empty folders. Minor changes: Renamed some variables, testing a new layout error fix, started working on material export. --- .../MA_TextureAtlasserPro/Atlasses.meta | 9 - .../Atlasses/Atlasses.txt | 1 - .../Atlasses/Atlasses.txt.meta | 8 - .../MA_TextureAtlasserPro/Exports.meta | 9 - .../MA_TextureAtlasserPro/Exports/Exports.txt | 1 - .../Exports/Exports.txt.meta | 7 - .../MA_TextureAtlasserProExportSettings.cs | 9 + .../Utils/MA_TextureAtlasserProUtils.cs | 168 ++++++++++++++---- .../MA_TextureAtlasserProInspectorView.cs | 69 ++++--- .../Views/MA_TextureAtlasserProMenuView.cs | 4 +- ...MA_TextureAtlasserProCreateExportWindow.cs | 2 +- .../MA_TextureAtlasserProCreateWindow.cs | 2 +- .../MA_TextureAtlasserProExportWindow.cs | 3 +- .../Windows/MA_TextureAtlasserProWindow.cs | 6 +- .../MA_TextureAtlasserPro/Settings.meta | 8 - .../Settings/ExportSettings.meta | 8 - .../ExportSettings/ExportSettings.txt | 1 - .../ExportSettings/ExportSettings.txt.meta | 7 - .../MA_DefaultExportSettings.asset | 25 --- .../MA_DefaultExportSettings.asset.meta | 8 - .../MA_DefaultSpriteExportSettings.asset | 25 --- .../MA_DefaultSpriteExportSettings.asset.meta | 8 - .../MA_TextureAtlasserProSettings.asset | 24 --- .../MA_TextureAtlasserProSettings.asset.meta | 8 - .../Settings/Settings.txt | 1 - .../Settings/Settings.txt.meta | 8 - 26 files changed, 196 insertions(+), 233 deletions(-) delete mode 100644 Assets/MA_ToolBox/MA_TextureAtlasserPro/Atlasses.meta delete mode 100644 Assets/MA_ToolBox/MA_TextureAtlasserPro/Atlasses/Atlasses.txt delete mode 100644 Assets/MA_ToolBox/MA_TextureAtlasserPro/Atlasses/Atlasses.txt.meta delete mode 100644 Assets/MA_ToolBox/MA_TextureAtlasserPro/Exports.meta delete mode 100644 Assets/MA_ToolBox/MA_TextureAtlasserPro/Exports/Exports.txt delete mode 100644 Assets/MA_ToolBox/MA_TextureAtlasserPro/Exports/Exports.txt.meta delete mode 100644 Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings.meta delete mode 100644 Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/ExportSettings.meta delete mode 100644 Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/ExportSettings/ExportSettings.txt delete mode 100644 Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/ExportSettings/ExportSettings.txt.meta delete mode 100644 Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/ExportSettings/MA_DefaultExportSettings.asset delete mode 100644 Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/ExportSettings/MA_DefaultExportSettings.asset.meta delete mode 100644 Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/ExportSettings/MA_DefaultSpriteExportSettings.asset delete mode 100644 Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/ExportSettings/MA_DefaultSpriteExportSettings.asset.meta delete mode 100644 Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/MA_TextureAtlasserProSettings.asset delete mode 100644 Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/MA_TextureAtlasserProSettings.asset.meta delete mode 100644 Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/Settings.txt delete mode 100644 Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/Settings.txt.meta diff --git a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Atlasses.meta b/Assets/MA_ToolBox/MA_TextureAtlasserPro/Atlasses.meta deleted file mode 100644 index 4fb6a81..0000000 --- a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Atlasses.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: 02a5a3da7e4e5dc4fb18fcef745fc000 -folderAsset: yes -timeCreated: 1519504430 -licenseType: Free -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Atlasses/Atlasses.txt b/Assets/MA_ToolBox/MA_TextureAtlasserPro/Atlasses/Atlasses.txt deleted file mode 100644 index 5ea6cf4..0000000 --- a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Atlasses/Atlasses.txt +++ /dev/null @@ -1 +0,0 @@ -The created atlasses wil go here. \ No newline at end of file diff --git a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Atlasses/Atlasses.txt.meta b/Assets/MA_ToolBox/MA_TextureAtlasserPro/Atlasses/Atlasses.txt.meta deleted file mode 100644 index 97fb36b..0000000 --- a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Atlasses/Atlasses.txt.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 720d130b97942404a8521a9f534e01a3 -timeCreated: 1522673504 -licenseType: Free -TextScriptImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Exports.meta b/Assets/MA_ToolBox/MA_TextureAtlasserPro/Exports.meta deleted file mode 100644 index 174875f..0000000 --- a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Exports.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: d57dd3d8bdc81434eb81f89cfbbd4dce -folderAsset: yes -timeCreated: 1519503997 -licenseType: Free -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Exports/Exports.txt b/Assets/MA_ToolBox/MA_TextureAtlasserPro/Exports/Exports.txt deleted file mode 100644 index a613270..0000000 --- a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Exports/Exports.txt +++ /dev/null @@ -1 +0,0 @@ -The exported assets will be saved in this folder. \ No newline at end of file diff --git a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Exports/Exports.txt.meta b/Assets/MA_ToolBox/MA_TextureAtlasserPro/Exports/Exports.txt.meta deleted file mode 100644 index dde2b7a..0000000 --- a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Exports/Exports.txt.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 6fbeeec15b89634488a9e823027e41e5 -TextScriptImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Data/MA_TextureAtlasserProExportSettings.cs b/Assets/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Data/MA_TextureAtlasserProExportSettings.cs index fabdd81..8bc01e3 100644 --- a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Data/MA_TextureAtlasserProExportSettings.cs +++ b/Assets/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Data/MA_TextureAtlasserProExportSettings.cs @@ -12,6 +12,7 @@ namespace MA_TextureAtlasserPro public ModelExportSettings modelExportSettings = new ModelExportSettings(); public TextureExportSettings textureExportSettings = new TextureExportSettings(); + public MaterialExportSettings materialExportSettings = new MaterialExportSettings(); } [System.Serializable] @@ -60,4 +61,12 @@ namespace MA_TextureAtlasserPro Sprite, SpriteSliced } + + [System.Serializable] + public class MaterialExportSettings + { + [Header("Material settings:")] + public string shader = "Standard"; + public string[] shaderPropertyNames = { "_MainTex", "_MetallicGlossMap", "_BumpMap" }; + } } \ No newline at end of file diff --git a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Utils/MA_TextureAtlasserProUtils.cs b/Assets/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Utils/MA_TextureAtlasserProUtils.cs index d9b5b70..b39519e 100644 --- a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Utils/MA_TextureAtlasserProUtils.cs +++ b/Assets/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Utils/MA_TextureAtlasserProUtils.cs @@ -12,13 +12,15 @@ namespace MA_TextureAtlasserPro public static class MA_TextureAtlasserProUtils { - public const string SETTINGSASSETPATH = "Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/"; - public const string EXPORTSETTINGSASSETPATH = "Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/ExportSettings/"; - public const string SAVEASSETPATH = "Assets/MA_ToolBox/MA_TextureAtlasserPro/Atlasses/"; - public const string LOADASSETPATH = "Assets/MA_ToolBox/MA_TextureAtlasserPro/Atlasses/"; - public const string EXPORTASSETPATH = "Assets/MA_ToolBox/MA_TextureAtlasserPro/Exports/"; - public const float VIEWOFFSET = 20; - public const string DEFAULTTEXTUREGROUPNAME = "Albedo"; + public const string TEXTURE_ATLASSER_PATH = "Assets/MA_ToolBox/MA_TextureAtlasserPro/"; + public const string SETTINGS_ASSET_PATH = "Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/"; + public const string SAVE_ASSET_PATH = "Assets/MA_ToolBox/MA_TextureAtlasserPro/Atlasses/"; + public const string LOAD_ASSET_PATH = "Assets/MA_ToolBox/MA_TextureAtlasserPro/Atlasses/"; + public const string EXPORT_ASSET_PATH = "Assets/MA_ToolBox/MA_TextureAtlasserPro/Exports/"; + public const string TEMP_ASSET_PATH = "Assets/MA_ToolBox/MA_TextureAtlasserPro/Temp/"; + + public const string DEFAULT_TEXTURE_GROUP_NAME = "Albedo"; + public const float VIEW_OFFSET = 20; public static MA_TextureAtlasserProSettings CreateSettings() { @@ -26,7 +28,8 @@ namespace MA_TextureAtlasserPro if(_settings != null) { - AssetDatabase.CreateAsset(_settings, SETTINGSASSETPATH + "MA_TextureAtlasserProSettings.asset"); + CreateFolder(SETTINGS_ASSET_PATH); + AssetDatabase.CreateAsset(_settings, SETTINGS_ASSET_PATH + "MA_TextureAtlasserProSettings.asset"); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); @@ -40,7 +43,7 @@ namespace MA_TextureAtlasserPro public static MA_TextureAtlasserProSettings LoadSettings() { - MA_TextureAtlasserProSettings _settings = AssetDatabase.LoadAssetAtPath(SETTINGSASSETPATH + "MA_TextureAtlasserProSettings.asset", typeof(MA_TextureAtlasserProSettings)) as MA_TextureAtlasserProSettings; + MA_TextureAtlasserProSettings _settings = AssetDatabase.LoadAssetAtPath(SETTINGS_ASSET_PATH + "MA_TextureAtlasserProSettings.asset", typeof(MA_TextureAtlasserProSettings)) as MA_TextureAtlasserProSettings; if (_settings == null) { @@ -57,7 +60,8 @@ namespace MA_TextureAtlasserPro if (_settings != null) { - AssetDatabase.CreateAsset(_settings, EXPORTSETTINGSASSETPATH + name + ".asset"); + CreateFolder(EXPORT_ASSET_PATH); + AssetDatabase.CreateAsset(_settings, SETTINGS_ASSET_PATH + name + ".asset"); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); @@ -72,7 +76,7 @@ namespace MA_TextureAtlasserPro public static MA_TextureAtlasserProExportSettings LoadExportSettings() { string name = "MA_DefaultExportSettings"; - MA_TextureAtlasserProExportSettings _settings = AssetDatabase.LoadAssetAtPath(EXPORTSETTINGSASSETPATH + name + ".asset", typeof(MA_TextureAtlasserProExportSettings)) as MA_TextureAtlasserProExportSettings; + MA_TextureAtlasserProExportSettings _settings = AssetDatabase.LoadAssetAtPath(SETTINGS_ASSET_PATH + name + ".asset", typeof(MA_TextureAtlasserProExportSettings)) as MA_TextureAtlasserProExportSettings; if (_settings == null) { @@ -91,7 +95,8 @@ namespace MA_TextureAtlasserPro _atlas.CreateAtlas(name, size); MA_CheckTextureAtlas(_atlas); - AssetDatabase.CreateAsset(_atlas, SAVEASSETPATH + name + ".asset"); + CreateFolder(SAVE_ASSET_PATH); + AssetDatabase.CreateAsset(_atlas, SAVE_ASSET_PATH + name + ".asset"); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); @@ -106,7 +111,7 @@ namespace MA_TextureAtlasserPro public static MA_TextureAtlasserProAtlas LoadTextureAtlas() { MA_TextureAtlasserProAtlas _atlas = null; - string absPath = EditorUtility.OpenFilePanel("Select Texture Atlas", LOADASSETPATH, ""); + string absPath = EditorUtility.OpenFilePanel("Select Texture Atlas", LOAD_ASSET_PATH, ""); if(absPath.StartsWith(Application.dataPath)) { @@ -141,7 +146,7 @@ namespace MA_TextureAtlasserPro MA_TextureGroupRegistration groupRegistration = new MA_TextureGroupRegistration { - name = DEFAULTTEXTUREGROUPNAME + name = DEFAULT_TEXTURE_GROUP_NAME }; atlas.textureGroupRegistration.Add(groupRegistration); @@ -350,8 +355,39 @@ namespace MA_TextureAtlasserPro return (value == 1); } + public static void CreateFolder(string folderPath) + { + if (folderPath.LastIndexOf('/') == folderPath.Length - 1) + { + folderPath = folderPath.Remove(folderPath.LastIndexOf('/')); + } + + if (!AssetDatabase.IsValidFolder(folderPath)) + { + string parentPath = folderPath.Substring(0, folderPath.LastIndexOf('/')); + string folderName = folderPath.Substring(folderPath.LastIndexOf('/') + 1); + + AssetDatabase.CreateFolder(parentPath, folderName); + AssetDatabase.Refresh(); + } + } + + public static void DeleteFolder(string folderPath) + { + if (folderPath.LastIndexOf('/') == folderPath.Length - 1) + { + folderPath = folderPath.Remove(folderPath.LastIndexOf('/')); + } + + if (AssetDatabase.IsValidFolder(folderPath)) + { + AssetDatabase.DeleteAsset(folderPath); + AssetDatabase.Refresh(); + } + } + #region Export - public static void ExportAtlasModels(MA_TextureAtlasserProAtlas atlas, ModelExportSettings modelExportSettings, string savePath = EXPORTASSETPATH) + public static void ExportAtlasModels(MA_TextureAtlasserProAtlas atlas, ModelExportSettings modelExportSettings, string savePath = EXPORT_ASSET_PATH) { switch(modelExportSettings.modelFormat) { @@ -365,7 +401,7 @@ namespace MA_TextureAtlasserPro } } - private static void ExportAtlasObj(MA_TextureAtlasserProAtlas atlas, ModelExportSettings modelExportSettings, string savePath = EXPORTASSETPATH) + private static void ExportAtlasObj(MA_TextureAtlasserProAtlas atlas, ModelExportSettings modelExportSettings, string savePath = EXPORT_ASSET_PATH) { if (atlas == null || atlas.textureQuads == null) return; @@ -424,7 +460,7 @@ namespace MA_TextureAtlasserPro } } - public static void ExportAtlasTextures(MA_TextureAtlasserProAtlas atlas, TextureExportSettings textureExportSettings, string savePath = EXPORTASSETPATH) + public static void ExportAtlasTextures(MA_TextureAtlasserProAtlas atlas, TextureExportSettings textureExportSettings, string savePath = EXPORT_ASSET_PATH, string tempPath = TEXTURE_ATLASSER_PATH) { switch (textureExportSettings.textureFormat) { @@ -438,7 +474,7 @@ namespace MA_TextureAtlasserPro } } - private static void ExportAtlasPNG(MA_TextureAtlasserProAtlas atlas, TextureExportSettings textureExportSettings, string savePath = EXPORTASSETPATH) + private static void ExportAtlasPNG(MA_TextureAtlasserProAtlas atlas, TextureExportSettings textureExportSettings, string savePath = EXPORT_ASSET_PATH, string tempPath = TEMP_ASSET_PATH) { if (atlas == null || atlas.textureQuads == null || atlas.textureGroupRegistration == null) return; @@ -456,36 +492,80 @@ namespace MA_TextureAtlasserPro { if (q.textureGroups != null && q.textureGroups[i].texture != null) { - //Create new texture part - Texture2D newTexturePart = (Texture2D)MA_TextureUtils.ConvertToReadableTexture(q.textureGroups[i].texture); - //Scale it - newTexturePart = newTexturePart.MA_Scale2D((int)q.guiRect.width, (int)q.guiRect.height, textureExportSettings.textureScaleMode); - //Add it + //Make temp copy + string orginalTexturePath = AssetDatabase.GetAssetPath(q.textureGroups[i].texture); + string orginalTextureExtension = System.IO.Path.GetExtension(orginalTexturePath); + + //Create temp folder + CreateFolder(tempPath); + + string tempTexturePath = tempPath + q.textureGroups[i].texture.name + orginalTextureExtension; + AssetDatabase.CopyAsset(orginalTexturePath, tempTexturePath); + + //Set temp copy to default settings + TextureImporter tempTextureImporter = (TextureImporter)AssetImporter.GetAtPath(tempTexturePath); + tempTextureImporter.textureType = TextureImporterType.Default; + tempTextureImporter.sRGBTexture = false; + tempTextureImporter.alphaIsTransparency = false; + tempTextureImporter.maxTextureSize = (int)Mathf.Max(atlas.textureAtlasSize.x, atlas.textureAtlasSize.y); + tempTextureImporter.textureCompression = TextureImporterCompression.Uncompressed; + tempTextureImporter.SaveAndReimport(); + + //Load temp copy + Texture tempCopy = AssetDatabase.LoadAssetAtPath(tempTextureImporter.assetPath); + + //Create new texture part + Texture2D newTexturePart = (Texture2D)MA_TextureUtils.ConvertToReadableTexture(tempCopy); + + //Scale it + newTexturePart = newTexturePart.MA_Scale2D((int)q.guiRect.width, (int)q.guiRect.height, textureExportSettings.textureScaleMode); + + //Add it newTexture = newTexture.MA_Combine2D(newTexturePart, (int)q.guiRect.x, (int)q.guiRect.y); - } + + //Delete temp copy + AssetDatabase.DeleteAsset(tempTextureImporter.assetPath); + } } + //Delete temp folder + DeleteFolder(tempPath); + //Save it newTexture.MA_Save2D(newTexture.name, savePath); - TextureImporter textureImporter = (TextureImporter)AssetImporter.GetAtPath(savePath + newTexture.name + ".png"); - textureImporter.textureType = TextureImporterType.Default; - textureImporter.SaveAndReimport(); + //Set settings. + switch (textureExportSettings.textureType) + { + case TextureType.Default: + { + TextureImporter textureImporter = (TextureImporter)AssetImporter.GetAtPath(savePath + newTexture.name + '.' + textureExportSettings.textureFormat.ToString()); + textureImporter.textureType = TextureImporterType.Default; + textureImporter.SaveAndReimport(); + } + break; + case TextureType.Sprite: + SetAtlasSpriteSettings(atlas, textureExportSettings, savePath); + break; + case TextureType.SpriteSliced: + SetAtlasSpriteSettings(atlas, textureExportSettings, savePath); + break; + default: + break; + } } - SetAtlasPNGSpriteSettings(atlas, textureExportSettings, savePath); - //Refresh AssetDatabase.Refresh(); } - private static void SetAtlasPNGSpriteSettings(MA_TextureAtlasserProAtlas atlas, TextureExportSettings textureExportSettings, string savePath = EXPORTASSETPATH) + private static void SetAtlasSpriteSettings(MA_TextureAtlasserProAtlas atlas, TextureExportSettings textureExportSettings, string savePath = EXPORT_ASSET_PATH) { //Foreach texture group for (int i = 0; i < atlas.textureGroupRegistration.Count; i++) { //Convert - string textureName = atlas.name + "_" + atlas.textureGroupRegistration[i].name + ".png"; + string textureName = atlas.name + "_" + atlas.textureGroupRegistration[i].name + '.' + textureExportSettings.textureFormat.ToString(); TextureImporter textureImporter = (TextureImporter)AssetImporter.GetAtPath(savePath + textureName); textureImporter.textureType = TextureImporterType.Sprite; textureImporter.alphaIsTransparency = true; @@ -522,7 +602,29 @@ namespace MA_TextureAtlasserPro textureImporter.SaveAndReimport(); } } - #endregion - } + + public static void ExportAtlasMaterial(MA_TextureAtlasserProAtlas atlas, MaterialExportSettings materialExportSettings, Texture[] textures, string savePath = EXPORT_ASSET_PATH) + { + if (atlas == null || atlas.textureQuads == null || atlas.textureGroupRegistration == null || textures == null) + return; + + Shader shader = Shader.Find(materialExportSettings.shader); + if (shader) + { + Material material = new Material(shader); + material.name = atlas.name; + + for (int i = 0; i < (int)Mathf.Max(materialExportSettings.shaderPropertyNames.Length - 1, textures.Length - 1); i++) + { + material.SetTexture(materialExportSettings.shaderPropertyNames[i], textures[i]); + } + + //Save material + AssetDatabase.CreateAsset(material, EXPORT_ASSET_PATH + material.name); + AssetDatabase.Refresh(); + } + } + #endregion + } } #endif \ No newline at end of file diff --git a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Views/MA_TextureAtlasserProInspectorView.cs b/Assets/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Views/MA_TextureAtlasserProInspectorView.cs index 8156894..ee4f368 100644 --- a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Views/MA_TextureAtlasserProInspectorView.cs +++ b/Assets/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Views/MA_TextureAtlasserProInspectorView.cs @@ -11,11 +11,13 @@ namespace MA_TextureAtlasserPro { private MA_TextureAtlasserProQuad lastSelectedQuad; - private bool isEditing = false; + private bool isEditing = false; private GUIStyle labelStyle = new GUIStyle(GUI.skin.label); - public MA_TextureAtlasserProInspectorView(MA_TextureAtlasserProWindow currentEditorWindow, string title) : base(currentEditorWindow, title) + bool useAddMeshButton = false; + + public MA_TextureAtlasserProInspectorView(MA_TextureAtlasserProWindow currentEditorWindow, string title) : base(currentEditorWindow, title) { } @@ -30,8 +32,21 @@ namespace MA_TextureAtlasserPro //Draw inspector if(curWindow.textureAtlas != null && curWindow.textureAtlas.selectedTextureQuad != null) { - //Deselect GUI elements when we are focusing on a new quad - if(lastSelectedQuad != curWindow.textureAtlas.selectedTextureQuad) + //Change layout during layout event to prevent gui errors + if (e.type == EventType.Layout) + { + if (curWindow.textureAtlas.selectedTextureQuad.meshes != null && curWindow.textureAtlas.selectedTextureQuad.meshes.Count == 0) + { + useAddMeshButton = true; + } + else + { + useAddMeshButton = false; + } + } + + //Deselect GUI elements when we are focusing on a new quad + if (lastSelectedQuad != curWindow.textureAtlas.selectedTextureQuad) { lastSelectedQuad = curWindow.textureAtlas.selectedTextureQuad; GUI.FocusControl(null); @@ -43,7 +58,7 @@ namespace MA_TextureAtlasserPro GUILayout.Label("Quad Name"); curWindow.textureAtlas.selectedTextureQuad.name = EditorGUILayout.TextField(curWindow.textureAtlas.selectedTextureQuad.name); - GUILayout.Space(MA_TextureAtlasserProUtils.VIEWOFFSET / 2); + GUILayout.Space(MA_TextureAtlasserProUtils.VIEW_OFFSET / 2); //Textures GUILayout.BeginHorizontal(); @@ -83,19 +98,20 @@ namespace MA_TextureAtlasserPro GUILayout.EndHorizontal(); } - GUILayout.Space(MA_TextureAtlasserProUtils.VIEWOFFSET / 2); + GUILayout.Space(MA_TextureAtlasserProUtils.VIEW_OFFSET / 2); //Meshes GUILayout.Label("Meshes"); - if(curWindow.textureAtlas.selectedTextureQuad.meshes != null) + if (useAddMeshButton) + { + if (GUILayout.Button("+", EditorStyles.miniButton, GUILayout.ExpandWidth(true))) + { + curWindow.textureAtlas.selectedTextureQuad.meshes.Add(null); + } + } + + if (curWindow.textureAtlas.selectedTextureQuad.meshes != null) { - if(curWindow.textureAtlas.selectedTextureQuad.meshes.Count == 0) - { - if(GUILayout.Button("+", EditorStyles.miniButton, GUILayout.ExpandWidth(true))) - { - curWindow.textureAtlas.selectedTextureQuad.meshes.Add(null); - } - } for (int i = 0; i < curWindow.textureAtlas.selectedTextureQuad.meshes.Count; i++) { GUILayout.BeginHorizontal(); @@ -116,20 +132,21 @@ namespace MA_TextureAtlasserPro curWindow.textureAtlas.selectedTextureQuad.meshes = new List(); } - GUILayout.FlexibleSpace(); - if(!MA_TextureAtlasserProUtils.IsPowerOfTwo((int)curWindow.textureAtlas.selectedTextureQuad.guiRect.width) || !MA_TextureAtlasserProUtils.IsPowerOfTwo((int)curWindow.textureAtlas.selectedTextureQuad.guiRect.height)) - { - labelStyle.normal.textColor = Color.red; - } - else - { - labelStyle.normal.textColor = Color.black; - } - GUILayout.Label("x " + curWindow.textureAtlas.selectedTextureQuad.guiRect.x.ToString() + ", y " + curWindow.textureAtlas.selectedTextureQuad.guiRect.y.ToString()); - GUILayout.Label("w " + curWindow.textureAtlas.selectedTextureQuad.guiRect.width.ToString() + ", h " + curWindow.textureAtlas.selectedTextureQuad.guiRect.height.ToString(), labelStyle); + GUILayout.FlexibleSpace(); + if (!MA_TextureAtlasserProUtils.IsPowerOfTwo((int)curWindow.textureAtlas.selectedTextureQuad.guiRect.width) || !MA_TextureAtlasserProUtils.IsPowerOfTwo((int)curWindow.textureAtlas.selectedTextureQuad.guiRect.height)) + { + labelStyle.normal.textColor = Color.red; + } + else + { + labelStyle.normal.textColor = Color.black; + } - GUILayout.EndVertical(); + GUILayout.Label("x " + curWindow.textureAtlas.selectedTextureQuad.guiRect.x.ToString() + ", y " + curWindow.textureAtlas.selectedTextureQuad.guiRect.y.ToString()); + GUILayout.Label("w " + curWindow.textureAtlas.selectedTextureQuad.guiRect.width.ToString() + ", h " + curWindow.textureAtlas.selectedTextureQuad.guiRect.height.ToString(), labelStyle); + + GUILayout.EndVertical(); GUILayout.EndArea(); } } diff --git a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Views/MA_TextureAtlasserProMenuView.cs b/Assets/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Views/MA_TextureAtlasserProMenuView.cs index efbd0ea..4020f32 100644 --- a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Views/MA_TextureAtlasserProMenuView.cs +++ b/Assets/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Views/MA_TextureAtlasserProMenuView.cs @@ -41,7 +41,7 @@ namespace MA_TextureAtlasserPro MA_TextureAtlasserProExportWindow.InitEditorWindow(curWindow); //MA_TextureAtlasserProUtils.ExportAtlas(curWindow.textureAtlas); } - GUILayout.Space(MA_TextureAtlasserProUtils.VIEWOFFSET); + GUILayout.Space(MA_TextureAtlasserProUtils.VIEW_OFFSET); if(curWindow.textureAtlas.showTextures && GUILayout.Button(MA_TextureAtlasserProIcons.showTexturesOnIcon, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true))) { curWindow.textureAtlas.showTextures = false; @@ -50,7 +50,7 @@ namespace MA_TextureAtlasserPro { curWindow.textureAtlas.showTextures = true; } - GUILayout.Space(MA_TextureAtlasserProUtils.VIEWOFFSET); + GUILayout.Space(MA_TextureAtlasserProUtils.VIEW_OFFSET); if(GUILayout.Button(MA_TextureAtlasserProIcons.createQuadIcon, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true))) { MA_TextureAtlasserProUtils.CreateTextureQuad(curWindow.textureAtlas, "new Quad", new Rect(0, 0, 128, 128), curWindow.settings.autoFocus); diff --git a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Windows/MA_TextureAtlasserProCreateExportWindow.cs b/Assets/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Windows/MA_TextureAtlasserProCreateExportWindow.cs index 684a1ce..0d84a5c 100644 --- a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Windows/MA_TextureAtlasserProCreateExportWindow.cs +++ b/Assets/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Windows/MA_TextureAtlasserProCreateExportWindow.cs @@ -47,7 +47,7 @@ namespace MA_TextureAtlasserPro void OnGUI() { - GUILayout.BeginArea(new Rect(MA_TextureAtlasserProUtils.VIEWOFFSET, MA_TextureAtlasserProUtils.VIEWOFFSET, position.width - (MA_TextureAtlasserProUtils.VIEWOFFSET * 2), position.height - (MA_TextureAtlasserProUtils.VIEWOFFSET * 2))); + GUILayout.BeginArea(new Rect(MA_TextureAtlasserProUtils.VIEW_OFFSET, MA_TextureAtlasserProUtils.VIEW_OFFSET, position.width - (MA_TextureAtlasserProUtils.VIEW_OFFSET * 2), position.height - (MA_TextureAtlasserProUtils.VIEW_OFFSET * 2))); GUILayout.BeginVertical(); //Input options diff --git a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Windows/MA_TextureAtlasserProCreateWindow.cs b/Assets/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Windows/MA_TextureAtlasserProCreateWindow.cs index 31dfdc2..21eba0d 100644 --- a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Windows/MA_TextureAtlasserProCreateWindow.cs +++ b/Assets/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Windows/MA_TextureAtlasserProCreateWindow.cs @@ -95,7 +95,7 @@ namespace MA_TextureAtlasserPro if(isLoaded) { - GUILayout.BeginArea(new Rect(MA_TextureAtlasserProUtils.VIEWOFFSET, MA_TextureAtlasserProUtils.VIEWOFFSET, position.width - (MA_TextureAtlasserProUtils.VIEWOFFSET * 2), position.height - (MA_TextureAtlasserProUtils.VIEWOFFSET * 2))); + GUILayout.BeginArea(new Rect(MA_TextureAtlasserProUtils.VIEW_OFFSET, MA_TextureAtlasserProUtils.VIEW_OFFSET, position.width - (MA_TextureAtlasserProUtils.VIEW_OFFSET * 2), position.height - (MA_TextureAtlasserProUtils.VIEW_OFFSET * 2))); GUILayout.BeginVertical(); //Input options diff --git a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Windows/MA_TextureAtlasserProExportWindow.cs b/Assets/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Windows/MA_TextureAtlasserProExportWindow.cs index 5abd614..ef9b456 100644 --- a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Windows/MA_TextureAtlasserProExportWindow.cs +++ b/Assets/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Windows/MA_TextureAtlasserProExportWindow.cs @@ -88,7 +88,7 @@ namespace MA_TextureAtlasserPro if(isLoaded) { - GUILayout.BeginArea(new Rect(MA_TextureAtlasserProUtils.VIEWOFFSET, MA_TextureAtlasserProUtils.VIEWOFFSET, position.width - (MA_TextureAtlasserProUtils.VIEWOFFSET * 2), position.height - (MA_TextureAtlasserProUtils.VIEWOFFSET * 2))); + GUILayout.BeginArea(new Rect(MA_TextureAtlasserProUtils.VIEW_OFFSET, MA_TextureAtlasserProUtils.VIEW_OFFSET, position.width - (MA_TextureAtlasserProUtils.VIEW_OFFSET * 2), position.height - (MA_TextureAtlasserProUtils.VIEW_OFFSET * 2))); GUILayout.BeginVertical(); @@ -156,6 +156,7 @@ namespace MA_TextureAtlasserPro { MA_TextureAtlasserProUtils.ExportAtlasModels(curWindow.textureAtlas, curWindow.textureAtlas.exportSettings.modelExportSettings); MA_TextureAtlasserProUtils.ExportAtlasTextures(curWindow.textureAtlas, curWindow.textureAtlas.exportSettings.textureExportSettings); + //MA_TextureAtlasserProUtils.ExportAtlasMaterial(curWindow.textureAtlas, curWindow.textureAtlas.exportSettings.materialExportSettings); } GUI.enabled = wasEnabled; diff --git a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Windows/MA_TextureAtlasserProWindow.cs b/Assets/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Windows/MA_TextureAtlasserProWindow.cs index 1c4da9c..c5f9997 100644 --- a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Windows/MA_TextureAtlasserProWindow.cs +++ b/Assets/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Windows/MA_TextureAtlasserProWindow.cs @@ -100,9 +100,9 @@ namespace MA_TextureAtlasserPro //Calculate view rects Rect workViewRect = new Rect(position.width - position.width, position.height - position.height, position.width, position.height); - Rect debugViewRect = new Rect(position.width - MA_TextureAtlasserProUtils.VIEWOFFSET - 164, position.height - MA_TextureAtlasserProUtils.VIEWOFFSET - 22, 164, 22); - Rect menuViewRect = new Rect(MA_TextureAtlasserProUtils.VIEWOFFSET, MA_TextureAtlasserProUtils.VIEWOFFSET, position.width - (MA_TextureAtlasserProUtils.VIEWOFFSET * 2), 44); - Rect inspectorViewRect = new Rect(MA_TextureAtlasserProUtils.VIEWOFFSET, menuViewRect.y + menuViewRect.height + MA_TextureAtlasserProUtils.VIEWOFFSET, 164, position.height - menuViewRect.height - (MA_TextureAtlasserProUtils.VIEWOFFSET * 3)); + Rect debugViewRect = new Rect(position.width - MA_TextureAtlasserProUtils.VIEW_OFFSET - 164, position.height - MA_TextureAtlasserProUtils.VIEW_OFFSET - 22, 164, 22); + Rect menuViewRect = new Rect(MA_TextureAtlasserProUtils.VIEW_OFFSET, MA_TextureAtlasserProUtils.VIEW_OFFSET, position.width - (MA_TextureAtlasserProUtils.VIEW_OFFSET * 2), 44); + Rect inspectorViewRect = new Rect(MA_TextureAtlasserProUtils.VIEW_OFFSET, menuViewRect.y + menuViewRect.height + MA_TextureAtlasserProUtils.VIEW_OFFSET, 164, position.height - menuViewRect.height - (MA_TextureAtlasserProUtils.VIEW_OFFSET * 3)); //Draw views and windows in the right oder from back to front if(isLoaded) diff --git a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings.meta b/Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings.meta deleted file mode 100644 index 3430a2b..0000000 --- a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: f8bde1ccdaaf89e4fb4743ccfcff941d -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/ExportSettings.meta b/Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/ExportSettings.meta deleted file mode 100644 index a33d743..0000000 --- a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/ExportSettings.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 379a005a9f28e9948b62809c65bbcd1b -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/ExportSettings/ExportSettings.txt b/Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/ExportSettings/ExportSettings.txt deleted file mode 100644 index 5506929..0000000 --- a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/ExportSettings/ExportSettings.txt +++ /dev/null @@ -1 +0,0 @@ -Export settigns are supposed to be here. \ No newline at end of file diff --git a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/ExportSettings/ExportSettings.txt.meta b/Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/ExportSettings/ExportSettings.txt.meta deleted file mode 100644 index 7103599..0000000 --- a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/ExportSettings/ExportSettings.txt.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 797d231c0151c5146a0da1482b480f43 -TextScriptImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/ExportSettings/MA_DefaultExportSettings.asset b/Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/ExportSettings/MA_DefaultExportSettings.asset deleted file mode 100644 index 1bc10a4..0000000 --- a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/ExportSettings/MA_DefaultExportSettings.asset +++ /dev/null @@ -1,25 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!114 &11400000 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: f8eb652100ecb804dae35d0cca727164, type: 3} - m_Name: MA_DefaultExportSettings - m_EditorClassIdentifier: - canModify: 0 - modelExportSettings: - modelFormat: 1 - replaceModel: 0 - uvFlipY: 1 - uvChannel: 0 - uvWrap: 1 - textureExportSettings: - textureFormat: 1 - textureType: 0 - textureScaleMode: 0 diff --git a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/ExportSettings/MA_DefaultExportSettings.asset.meta b/Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/ExportSettings/MA_DefaultExportSettings.asset.meta deleted file mode 100644 index 4205792..0000000 --- a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/ExportSettings/MA_DefaultExportSettings.asset.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 3a4e7ee656413624ea3ac0ab666cc5f7 -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 11400000 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/ExportSettings/MA_DefaultSpriteExportSettings.asset b/Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/ExportSettings/MA_DefaultSpriteExportSettings.asset deleted file mode 100644 index d97dd25..0000000 --- a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/ExportSettings/MA_DefaultSpriteExportSettings.asset +++ /dev/null @@ -1,25 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!114 &11400000 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: f8eb652100ecb804dae35d0cca727164, type: 3} - m_Name: MA_DefaultSpriteExportSettings - m_EditorClassIdentifier: - canModify: 0 - modelExportSettings: - modelFormat: 0 - replaceModel: 0 - uvFlipY: 0 - uvChannel: 0 - uvWrap: 0 - textureExportSettings: - textureFormat: 1 - textureType: 2 - textureScaleMode: 0 diff --git a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/ExportSettings/MA_DefaultSpriteExportSettings.asset.meta b/Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/ExportSettings/MA_DefaultSpriteExportSettings.asset.meta deleted file mode 100644 index 3c779e3..0000000 --- a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/ExportSettings/MA_DefaultSpriteExportSettings.asset.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: f2a8020dc0b658447b53eec982e136f4 -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 11400000 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/MA_TextureAtlasserProSettings.asset b/Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/MA_TextureAtlasserProSettings.asset deleted file mode 100644 index f669762..0000000 --- a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/MA_TextureAtlasserProSettings.asset +++ /dev/null @@ -1,24 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!114 &11400000 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 73f5e66553c13034e9b894ef2cc31b66, type: 3} - m_Name: MA_TextureAtlasserProSettings - m_EditorClassIdentifier: - useHotkeys: 0 - modifierKey: 4 - addQuadHotKey: 113 - removeQuadHotKey: 114 - duplicateHotKey: 100 - zoomInHotKey: 61 - zoomOutHotKey: 45 - copySelectedQuadData: 1 - duplicatedQuadNamePrefix: 'new ' - autoFocus: 1 diff --git a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/MA_TextureAtlasserProSettings.asset.meta b/Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/MA_TextureAtlasserProSettings.asset.meta deleted file mode 100644 index 796342f..0000000 --- a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/MA_TextureAtlasserProSettings.asset.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 0be88ac94b5c5a44d96befde176454ac -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 11400000 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/Settings.txt b/Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/Settings.txt deleted file mode 100644 index f10ecb7..0000000 --- a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/Settings.txt +++ /dev/null @@ -1 +0,0 @@ -Settigns are supposed to be here. \ No newline at end of file diff --git a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/Settings.txt.meta b/Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/Settings.txt.meta deleted file mode 100644 index 9104899..0000000 --- a/Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/Settings.txt.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 1dff191e3795506498c3ba0ec68a9f29 -timeCreated: 1522673504 -licenseType: Free -TextScriptImporter: - userData: - assetBundleName: - assetBundleVariant: