From 82efcbb6d0ebeaa941de79ad37fe4602cd4dcb5e Mon Sep 17 00:00:00 2001 From: max Date: Sun, 31 Mar 2019 18:09:53 +0200 Subject: [PATCH] Duplicate Quad, Settings, Hotkeys. Added the option to duplicate the selected quad. Added settings for focus, duplication, hotkeys. Added hotkeys, can be enabled in the settings file. --- .../Icons/duplicateQuadIcon.png | Bin 0 -> 2991 bytes .../Data/MA_TextureAtlasserProSettings.cs | 25 +++++++ .../Utils/MA_TextureAtlasserProIcons.cs | 2 + .../Utils/MA_TextureAtlasserProUtils.cs | 69 +++++++++++++++++- .../Views/MA_TextureAtlasserProMenuView.cs | 9 ++- .../Views/MA_TextureAtlasserProWorkView.cs | 25 +++++++ .../Windows/MA_TextureAtlasserProWindow.cs | 4 +- .../Settings/Settings.txt | 1 + 8 files changed, 129 insertions(+), 6 deletions(-) create mode 100644 MA_ToolBox/MA_TextureAtlasserPro/Icons/duplicateQuadIcon.png create mode 100644 MA_ToolBox/MA_TextureAtlasserPro/Scripts/Data/MA_TextureAtlasserProSettings.cs create mode 100644 MA_ToolBox/MA_TextureAtlasserPro/Settings/Settings.txt diff --git a/MA_ToolBox/MA_TextureAtlasserPro/Icons/duplicateQuadIcon.png b/MA_ToolBox/MA_TextureAtlasserPro/Icons/duplicateQuadIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..1216f5361a8fe3c7da86ea0678d0239157b6692d GIT binary patch literal 2991 zcmb_e3vd%v6x}M{@==gN2gd2TSVUm6zx;M>iX|y+gW;c27o_F58 z_nmw5R_4#k8I?RS8N;wqdAXhf^o^U(up#KJS5^IlVZ(XF=QsS`xq_qxEkM>pXo&{H z$c|wdGoxW3l|cg+VTlrQ5$E1*BydG`5escz+8cJmQYE)40t>6=`J}2ciI<6)naLSZ z0TBeD0q|&04e3JEMZ|ao^xK@K2s{Qc%3Orsn~%G-2*hm`n}sGalktp*91sdTvpW}~ zk&7rbjIcma6%`eh3eKWMN+^csd5UH!mL(B_)GI>{_FvPlu=@IYOPC}B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extureAtlasserPro/Scripts/Data/MA_TextureAtlasserProSettings.cs b/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Data/MA_TextureAtlasserProSettings.cs new file mode 100644 index 0000000..abb100b --- /dev/null +++ b/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Data/MA_TextureAtlasserProSettings.cs @@ -0,0 +1,25 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEditor; +using MA_Editor; + +namespace MA_TextureAtlasserPro +{ + [System.Serializable] + public class MA_TextureAtlasserProSettings : ScriptableObject + { + [Header("Selection")] + public bool autoFocus = true; + + [Header("Duplication:")] + public bool copySelectedQuadData = false; + public string duplicatedQuadNamePrefix = "new "; + + [Header("Hotkeys:")] + public bool useHotkeys = false; + public KeyCode addQuadHotKey = KeyCode.Q; + public KeyCode removeQuadHotKey = KeyCode.R; + public KeyCode duplicateHotKey = KeyCode.D; + } +} \ No newline at end of file diff --git a/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Utils/MA_TextureAtlasserProIcons.cs b/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Utils/MA_TextureAtlasserProIcons.cs index 7d3df4e..f68f868 100644 --- a/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Utils/MA_TextureAtlasserProIcons.cs +++ b/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Utils/MA_TextureAtlasserProIcons.cs @@ -12,6 +12,7 @@ namespace MA_TextureAtlasserPro public static GUIContent exportAtlasIcon; public static GUIContent createQuadIcon; public static GUIContent removeQuadIcon; + public static GUIContent duplicateQuadIcon; public static GUIContent showTexturesOnIcon; public static GUIContent showTexturesOffIcon; public static GUIContent dragHandleIcon; @@ -24,6 +25,7 @@ namespace MA_TextureAtlasserPro exportAtlasIcon = new GUIContent("", (Texture)EditorGUIUtility.Load(LOADICONPATH + "exportAtlasIcon" + ".png")); createQuadIcon = new GUIContent("", (Texture)EditorGUIUtility.Load(LOADICONPATH + "createQuadIcon" + ".png")); removeQuadIcon = new GUIContent("", (Texture)EditorGUIUtility.Load(LOADICONPATH + "removeQuadIcon" + ".png")); + duplicateQuadIcon = new GUIContent("", (Texture)EditorGUIUtility.Load(LOADICONPATH + "duplicateQuadIcon" + ".png")); showTexturesOnIcon = new GUIContent("", (Texture)EditorGUIUtility.Load(LOADICONPATH + "showTexturesOnIcon" + ".png")); showTexturesOffIcon = new GUIContent("", (Texture)EditorGUIUtility.Load(LOADICONPATH + "showTexturesOffIcon" + ".png")); dragHandleIcon = new GUIContent("", (Texture)EditorGUIUtility.Load(LOADICONPATH + "dragHandleIcon" + ".png")); diff --git a/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Utils/MA_TextureAtlasserProUtils.cs b/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Utils/MA_TextureAtlasserProUtils.cs index 858e102..7541639 100644 --- a/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Utils/MA_TextureAtlasserProUtils.cs +++ b/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Utils/MA_TextureAtlasserProUtils.cs @@ -9,12 +9,43 @@ namespace MA_TextureAtlasserPro { public static class MA_TextureAtlasserProUtils { + public const string SETTINGSASSETPATH = "Assets/MA_ToolBox/MA_TextureAtlasserPro/Settings/"; 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 static MA_TextureAtlasserProSettings CreateSettings() + { + MA_TextureAtlasserProSettings _settings = (MA_TextureAtlasserProSettings)ScriptableObject.CreateInstance(); + + if(_settings != null) + { + AssetDatabase.CreateAsset(_settings, SETTINGSASSETPATH + "MA_TextureAtlasserProSettings.asset"); + AssetDatabase.SaveAssets(); + AssetDatabase.Refresh(); + + return _settings; + } + else + { + return null; + } + } + + public static MA_TextureAtlasserProSettings LoadSettings() + { + MA_TextureAtlasserProSettings _settings = AssetDatabase.LoadAssetAtPath(SETTINGSASSETPATH + "MA_TextureAtlasserProSettings.asset", typeof(MA_TextureAtlasserProSettings)) as MA_TextureAtlasserProSettings; + + if (_settings == null) + { + _settings = CreateSettings(); + } + + return _settings; + } + public static MA_TextureAtlasserProAtlas CreateTextureAtlas(string name, Vector2 size) { MA_TextureAtlasserProAtlas _atlas = (MA_TextureAtlasserProAtlas)ScriptableObject.CreateInstance(); @@ -113,7 +144,7 @@ namespace MA_TextureAtlasserPro } } - public static void CreateTextureQuad(MA_TextureAtlasserProAtlas atlas, string name, Rect rect) + public static void CreateTextureQuad(MA_TextureAtlasserProAtlas atlas, string name, Rect rect, bool focus = true) { if(atlas != null) { @@ -140,6 +171,11 @@ namespace MA_TextureAtlasserPro AssetDatabase.AddObjectToAsset(_quad, atlas); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); + + if(focus) + { + atlas.selectedTextureQuad = atlas.textureQuads[atlas.textureQuads.Count - 1]; + } } else { @@ -152,14 +188,41 @@ namespace MA_TextureAtlasserPro } } - public static void RemoveTextureQuad(MA_TextureAtlasserProAtlas atlas) + public static void RemoveTextureQuad(MA_TextureAtlasserProAtlas atlas, bool focus = true) { if(atlas != null && atlas.selectedTextureQuad != null) { - atlas.textureQuads.Remove(atlas.selectedTextureQuad); + int _index = atlas.textureQuads.IndexOf(atlas.selectedTextureQuad); + + atlas.textureQuads.RemoveAt(_index); GameObject.DestroyImmediate(atlas.selectedTextureQuad, true); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); + + if (focus && atlas.textureQuads.Count > 0) + { + _index = Mathf.Clamp(_index, 0, atlas.textureQuads.Count - 1); + atlas.selectedTextureQuad = atlas.textureQuads[_index]; + } + } + } + + public static void DuplicateTextureQuad(MA_TextureAtlasserProAtlas atlas, bool focus = true, bool copyData = false, string namePrefix = "new ") + { + if(atlas != null && atlas.selectedTextureQuad != null) + { + CreateTextureQuad(atlas, namePrefix + atlas.selectedTextureQuad.name, atlas.selectedTextureQuad.rect); + + if(copyData) + { + atlas.textureQuads[atlas.textureQuads.Count - 1].meshes = atlas.selectedTextureQuad.meshes; + atlas.textureQuads[atlas.textureQuads.Count - 1].textureGroups = atlas.selectedTextureQuad.textureGroups; + } + + if(focus) + { + atlas.selectedTextureQuad = atlas.textureQuads[atlas.textureQuads.Count - 1]; + } } } diff --git a/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Views/MA_TextureAtlasserProMenuView.cs b/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Views/MA_TextureAtlasserProMenuView.cs index 77be0a9..d3a5898 100644 --- a/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Views/MA_TextureAtlasserProMenuView.cs +++ b/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Views/MA_TextureAtlasserProMenuView.cs @@ -52,12 +52,17 @@ namespace MA_TextureAtlasserPro GUILayout.Space(MA_TextureAtlasserProUtils.VIEWOFFSET); 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)); + MA_TextureAtlasserProUtils.CreateTextureQuad(curWindow.textureAtlas, "new Quad", new Rect(0, 0, 128, 128), curWindow.settings.autoFocus); } if(curWindow.textureAtlas.selectedTextureQuad != null && GUILayout.Button(MA_TextureAtlasserProIcons.removeQuadIcon, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true))) { if(curWindow.textureAtlas.selectedTextureQuad != null) - MA_TextureAtlasserProUtils.RemoveTextureQuad(curWindow.textureAtlas); + MA_TextureAtlasserProUtils.RemoveTextureQuad(curWindow.textureAtlas, curWindow.settings.autoFocus); + } + if (curWindow.textureAtlas.selectedTextureQuad != null && GUILayout.Button(MA_TextureAtlasserProIcons.duplicateQuadIcon, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true))) + { + if (curWindow.textureAtlas.selectedTextureQuad != null) + MA_TextureAtlasserProUtils.DuplicateTextureQuad(curWindow.textureAtlas, curWindow.settings.autoFocus, curWindow.settings.copySelectedQuadData, curWindow.settings.duplicatedQuadNamePrefix); } } diff --git a/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Views/MA_TextureAtlasserProWorkView.cs b/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Views/MA_TextureAtlasserProWorkView.cs index f92a8b0..0d73d96 100644 --- a/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Views/MA_TextureAtlasserProWorkView.cs +++ b/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Views/MA_TextureAtlasserProWorkView.cs @@ -89,6 +89,31 @@ namespace MA_TextureAtlasserPro e.Use(); } + + //Hotkeys. + if (curWindow.settings.useHotkeys) + { + if (e.type == EventType.KeyDown && e.keyCode == curWindow.settings.addQuadHotKey) + { + MA_TextureAtlasserProUtils.CreateTextureQuad(curWindow.textureAtlas, "new Quad", new Rect(0, 0, 128, 128), curWindow.settings.autoFocus); + e.Use(); + } + + if (curWindow.textureAtlas.selectedTextureQuad != null) + { + if (e.type == EventType.KeyDown && e.keyCode == curWindow.settings.removeQuadHotKey) + { + MA_TextureAtlasserProUtils.RemoveTextureQuad(curWindow.textureAtlas, curWindow.settings.autoFocus); + e.Use(); + } + + if (e.type == EventType.KeyDown && e.keyCode == curWindow.settings.duplicateHotKey) + { + MA_TextureAtlasserProUtils.DuplicateTextureQuad(curWindow.textureAtlas, curWindow.settings.autoFocus); + e.Use(); + } + } + } } private Vector2 ConvertScreenCoordsToZoomCoords(Vector2 screenCoords) diff --git a/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Windows/MA_TextureAtlasserProWindow.cs b/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Windows/MA_TextureAtlasserProWindow.cs index 9fc42f4..7fe7c31 100644 --- a/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Windows/MA_TextureAtlasserProWindow.cs +++ b/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Windows/MA_TextureAtlasserProWindow.cs @@ -8,6 +8,7 @@ namespace MA_TextureAtlasserPro public class MA_TextureAtlasserProWindow : EditorWindow { public static MA_TextureAtlasserProWindow thisWindow; + public MA_TextureAtlasserProSettings settings; public MA_TextureAtlasserProAtlas textureAtlas; public MA_TextureAtlasserProWorkView workView; @@ -56,6 +57,7 @@ namespace MA_TextureAtlasserPro GetCurrentWindow(); } + thisWindow.settings = MA_TextureAtlasserProUtils.LoadSettings(); thisWindow.workView = new MA_TextureAtlasserProWorkView(thisWindow, "workView"); thisWindow.menuView = new MA_TextureAtlasserProMenuView(thisWindow, "menuView"); thisWindow.inspectorView = new MA_TextureAtlasserProInspectorView(thisWindow, "inspectorView"); @@ -86,7 +88,7 @@ namespace MA_TextureAtlasserPro } //Check views - if(workView == null || menuView == null || inspectorView == null || debugView == null) + if(settings == null || workView == null || menuView == null || inspectorView == null || debugView == null) { CreateViews(); return; diff --git a/MA_ToolBox/MA_TextureAtlasserPro/Settings/Settings.txt b/MA_ToolBox/MA_TextureAtlasserPro/Settings/Settings.txt new file mode 100644 index 0000000..f10ecb7 --- /dev/null +++ b/MA_ToolBox/MA_TextureAtlasserPro/Settings/Settings.txt @@ -0,0 +1 @@ +Settigns are supposed to be here. \ No newline at end of file