mirror of
https://github.com/maxartz15/MA_TextureAtlasser.git
synced 2025-07-07 08:46:07 +02:00
Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
7f17793af0 | |||
09f7c488b9 | |||
1251736f5b | |||
78e4fb0ad1 | |||
7990f987dc | |||
82efcbb6d0 | |||
7f5e22b3c1 | |||
c91c1cb7ee |
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018 Max
|
||||
Copyright (c) 2018 Max Kruf
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
BIN
MA_ToolBox/MA_TextureAtlasserPro/Icons/duplicateQuadIcon.png
Normal file
BIN
MA_ToolBox/MA_TextureAtlasserPro/Icons/duplicateQuadIcon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.9 KiB |
@ -1,3 +1,4 @@
|
||||
#if UNITY_EDITOR
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@ -101,3 +102,4 @@ namespace MA_TextureAtlasserPro
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -1,3 +1,4 @@
|
||||
#if UNITY_EDITOR
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@ -164,3 +165,4 @@ namespace MA_TextureAtlasserPro
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -0,0 +1,27 @@
|
||||
#if UNITY_EDITOR
|
||||
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 = false;
|
||||
|
||||
[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;
|
||||
}
|
||||
}
|
||||
#endif
|
@ -1,4 +1,5 @@
|
||||
using System.Collections;
|
||||
#if UNITY_EDITOR
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
@ -17,3 +18,4 @@ namespace MA_TextureAtlasserPro
|
||||
public string name;
|
||||
}
|
||||
}
|
||||
#endif
|
@ -1,3 +1,4 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
@ -12,6 +13,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 +26,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"));
|
||||
@ -31,3 +34,4 @@ namespace MA_TextureAtlasserPro
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -1,3 +1,4 @@
|
||||
#if UNITY_EDITOR
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@ -9,12 +10,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<MA_TextureAtlasserProSettings>();
|
||||
|
||||
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<MA_TextureAtlasserProAtlas>();
|
||||
@ -113,7 +145,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 +172,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 +189,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, false);
|
||||
|
||||
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];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -299,7 +363,7 @@ namespace MA_TextureAtlasserPro
|
||||
//Create new texture part
|
||||
Texture2D newTexturePart = (Texture2D)MA_Texture.MA_TextureUtils.ConvertToReadableTexture(q.textureGroups[i].texture);
|
||||
//Scale it
|
||||
newTexturePart = newTexturePart.MA_Scale2D((int)q.guiRect.width, (int)q.guiRect.height);
|
||||
newTexturePart = newTexturePart.MA_Scale32D((int)q.guiRect.width, (int)q.guiRect.height);
|
||||
//Add it
|
||||
newTexture = newTexture.MA_Combine2D(newTexturePart, (int)q.guiRect.x, (int)q.guiRect.y);
|
||||
}
|
||||
@ -307,11 +371,79 @@ namespace MA_TextureAtlasserPro
|
||||
|
||||
//Save it
|
||||
newTexture.MA_Save2D("MA_" + newTexture.name, savePath);
|
||||
|
||||
TextureImporter textureImporter = (TextureImporter)AssetImporter.GetAtPath(savePath + "MA_" + newTexture.name + ".png");
|
||||
textureImporter.textureType = TextureImporterType.Default;
|
||||
textureImporter.SaveAndReimport();
|
||||
}
|
||||
|
||||
//Refresh
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
public static void ExportAtlasSpritesPNG(MA_TextureAtlasserProAtlas atlas, bool sliceSprites = true, string savePath = EXPORTASSETPATH)
|
||||
{
|
||||
if (atlas != null && atlas.textureQuads != null && atlas.textureGroupRegistration != null)
|
||||
{
|
||||
ExportAtlasTexturesPNG(atlas, savePath);
|
||||
|
||||
//Foreach texture group
|
||||
for (int i = 0; i < atlas.textureGroupRegistration.Count; i++)
|
||||
{
|
||||
//Convert
|
||||
string textureName = "MA_" + atlas.name + "_" + atlas.textureGroupRegistration[i].name + ".png";
|
||||
TextureImporter textureImporter = (TextureImporter)AssetImporter.GetAtPath(savePath + textureName);
|
||||
textureImporter.textureType = TextureImporterType.Sprite;
|
||||
textureImporter.alphaIsTransparency = true;
|
||||
|
||||
//Slice sprites.
|
||||
if (sliceSprites)
|
||||
{
|
||||
textureImporter.spriteImportMode = SpriteImportMode.None; //Reset it to update?
|
||||
textureImporter.spriteImportMode = SpriteImportMode.Multiple;
|
||||
List<SpriteMetaData> spriteMetaData = new List<SpriteMetaData>();
|
||||
|
||||
foreach (MA_TextureAtlasserProQuad q in atlas.textureQuads)
|
||||
{
|
||||
if (q.textureGroups != null && q.textureGroups[i].texture != null)
|
||||
{
|
||||
//Create new SpriteMetaData.
|
||||
SpriteMetaData smd = new SpriteMetaData();
|
||||
|
||||
smd.name = q.name;
|
||||
smd.rect = new Rect(q.guiRect.x, atlas.textureAtlasSize.y - q.guiRect.y - q.guiRect.height, q.guiRect.width, q.guiRect.height);
|
||||
|
||||
spriteMetaData.Add(smd);
|
||||
}
|
||||
}
|
||||
|
||||
textureImporter.spritesheet = spriteMetaData.ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
textureImporter.spriteImportMode = SpriteImportMode.Single;
|
||||
}
|
||||
|
||||
|
||||
textureImporter.SaveAndReimport();
|
||||
}
|
||||
|
||||
//Refresh
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsPowerOfTwo(int value)
|
||||
{
|
||||
//While x is even and > 1
|
||||
while (((value % 2) == 0) && value > 1)
|
||||
{
|
||||
value /= 2;
|
||||
}
|
||||
|
||||
return (value == 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -1,3 +1,4 @@
|
||||
#if UNITY_EDITOR
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@ -76,3 +77,4 @@ namespace MA_TextureAtlasserPro
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -1,3 +1,4 @@
|
||||
#if UNITY_EDITOR
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@ -12,6 +13,8 @@ namespace MA_TextureAtlasserPro
|
||||
|
||||
private bool isEditing = false;
|
||||
|
||||
private GUIStyle labelStyle = new GUIStyle(GUI.skin.label);
|
||||
|
||||
public MA_TextureAtlasserProInspectorView(MA_TextureAtlasserProWindow currentEditorWindow, string title) : base(currentEditorWindow, title)
|
||||
{
|
||||
|
||||
@ -114,8 +117,17 @@ namespace MA_TextureAtlasserPro
|
||||
}
|
||||
|
||||
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());
|
||||
GUILayout.Label("w " + curWindow.textureAtlas.selectedTextureQuad.guiRect.width.ToString() + ", h " + curWindow.textureAtlas.selectedTextureQuad.guiRect.height.ToString(), labelStyle);
|
||||
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.EndArea();
|
||||
@ -132,3 +144,4 @@ namespace MA_TextureAtlasserPro
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -1,3 +1,4 @@
|
||||
#if UNITY_EDITOR
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@ -52,12 +53,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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,3 +80,4 @@ namespace MA_TextureAtlasserPro
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -1,4 +1,5 @@
|
||||
using System.Collections;
|
||||
#if UNITY_EDITOR
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
@ -53,3 +54,4 @@ namespace MA_TextureAtlasserPro
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -1,4 +1,5 @@
|
||||
using System.Collections;
|
||||
#if UNITY_EDITOR
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using MA_Editor;
|
||||
@ -89,6 +90,34 @@ namespace MA_TextureAtlasserPro
|
||||
|
||||
e.Use();
|
||||
}
|
||||
|
||||
//Hotkeys.
|
||||
if (curWindow.settings.useHotkeys)
|
||||
{
|
||||
if(curWindow.textureAtlas != null)
|
||||
{
|
||||
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, curWindow.settings.copySelectedQuadData, curWindow.settings.duplicatedQuadNamePrefix);
|
||||
e.Use();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Vector2 ConvertScreenCoordsToZoomCoords(Vector2 screenCoords)
|
||||
@ -120,3 +149,4 @@ namespace MA_TextureAtlasserPro
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -1,4 +1,5 @@
|
||||
using System.Collections;
|
||||
#if UNITY_EDITOR
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
@ -168,3 +169,4 @@ namespace MA_TextureAtlasserPro
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -1,4 +1,5 @@
|
||||
using System.Collections;
|
||||
#if UNITY_EDITOR
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
@ -13,15 +14,20 @@ namespace MA_TextureAtlasserPro
|
||||
public static MA_TextureAtlasserProWindow curWindow;
|
||||
|
||||
//Data
|
||||
private static bool isLoaded = false; //Make sure we wait a frame at the start to setup and don't draw.
|
||||
private static bool isLoaded = false; //Make sure we wait a frame at the start to setup and don't draw.
|
||||
|
||||
private bool exportObjDefault = false;
|
||||
private bool exportPngDefault = false;
|
||||
private bool exportSprite = false;
|
||||
private bool exportSliceSprite = false;
|
||||
|
||||
[MenuItem("MA_ToolKit/MA_TextureAtlasserPro/Export Atlas")]
|
||||
private static void Init()
|
||||
{
|
||||
GetCurrentWindow();
|
||||
|
||||
thisWindow.minSize = new Vector2(500,160);
|
||||
thisWindow.maxSize = new Vector2(500,160);
|
||||
thisWindow.minSize = new Vector2(420, 200);
|
||||
thisWindow.maxSize = new Vector2(420, 200);
|
||||
|
||||
thisWindow.titleContent.text = "MA_ExportTextureAtlas";
|
||||
|
||||
@ -34,8 +40,8 @@ namespace MA_TextureAtlasserPro
|
||||
|
||||
GetCurrentWindow();
|
||||
|
||||
thisWindow.minSize = new Vector2(500,160);
|
||||
thisWindow.maxSize = new Vector2(500,160);
|
||||
thisWindow.minSize = new Vector2(420, 200);
|
||||
thisWindow.maxSize = new Vector2(420, 200);
|
||||
|
||||
thisWindow.titleContent.text = "MA_ExportTextureAtlas";
|
||||
|
||||
@ -93,18 +99,68 @@ namespace MA_TextureAtlasserPro
|
||||
|
||||
if(curWindow != null && curWindow.textureAtlas != null)
|
||||
{
|
||||
//Export options
|
||||
GUILayout.Box("Note: No custom export options right now.. :<", EditorStyles.helpBox);
|
||||
|
||||
//Export
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.BeginVertical();
|
||||
GUILayout.BeginHorizontal(EditorStyles.helpBox);
|
||||
|
||||
GUILayout.Label("Meshes: OBJ | Textures: PNG");
|
||||
if(GUILayout.Button("Export Atlas", GUILayout.ExpandWidth(true), GUILayout.Height(37)))
|
||||
if (GUILayout.Button("3D", GUILayout.ExpandWidth(false)))
|
||||
{
|
||||
MA_TextureAtlasserProUtils.ExportAtlas(curWindow.textureAtlas);
|
||||
exportObjDefault = true;
|
||||
exportPngDefault = true;
|
||||
exportSprite = false;
|
||||
exportSliceSprite = false;
|
||||
}
|
||||
|
||||
if (GUILayout.Button("2D", GUILayout.ExpandWidth(false)))
|
||||
{
|
||||
exportObjDefault = false;
|
||||
exportPngDefault = true;
|
||||
exportSprite = true;
|
||||
exportSliceSprite = true;
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.Label("Meshes:");
|
||||
exportObjDefault = GUILayout.Toggle(exportObjDefault, "OBJ default.");
|
||||
|
||||
GUILayout.Label("Textures:");
|
||||
GUILayout.BeginHorizontal();
|
||||
exportPngDefault = GUILayout.Toggle(exportPngDefault, "PNG default.");
|
||||
if(exportPngDefault)
|
||||
{
|
||||
exportSprite = GUILayout.Toggle(exportSprite, "Sprite.");
|
||||
if (exportSprite)
|
||||
{
|
||||
exportSliceSprite = GUILayout.Toggle(exportSliceSprite, "Slice sprites.");
|
||||
}
|
||||
}
|
||||
GUILayout.FlexibleSpace();
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.BeginHorizontal(EditorStyles.helpBox);
|
||||
|
||||
if (GUILayout.Button("Export", GUILayout.ExpandWidth(true), GUILayout.Height(37)))
|
||||
{
|
||||
if(exportObjDefault)
|
||||
{
|
||||
MA_TextureAtlasserProUtils.ExportAtlasMeshesObj(curWindow.textureAtlas);
|
||||
}
|
||||
|
||||
if(exportPngDefault)
|
||||
{
|
||||
if(exportSprite)
|
||||
{
|
||||
MA_TextureAtlasserProUtils.ExportAtlasSpritesPNG(curWindow.textureAtlas, exportSliceSprite);
|
||||
}
|
||||
else
|
||||
{
|
||||
MA_TextureAtlasserProUtils.ExportAtlasTexturesPNG(curWindow.textureAtlas);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
else if(curWindow == null)
|
||||
@ -133,3 +189,4 @@ namespace MA_TextureAtlasserPro
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -1,4 +1,5 @@
|
||||
using System.Collections;
|
||||
#if UNITY_EDITOR
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
@ -8,6 +9,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 +58,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 +89,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;
|
||||
@ -117,3 +120,4 @@ namespace MA_TextureAtlasserPro
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
1
MA_ToolBox/MA_TextureAtlasserPro/Settings/Settings.txt
Normal file
1
MA_ToolBox/MA_TextureAtlasserPro/Settings/Settings.txt
Normal file
@ -0,0 +1 @@
|
||||
Settigns are supposed to be here.
|
@ -1,6 +1,6 @@
|
||||
//Maxartz15
|
||||
//Version 1.0
|
||||
//https://github.com/maxartz15/MA_EditorUtils
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@ -59,3 +59,4 @@ namespace MA_Editor.Grid
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -1,6 +1,9 @@
|
||||
//Maxartz15
|
||||
//Version 1.0
|
||||
//https://github.com/maxartz15/MA_EditorUtils
|
||||
|
||||
//References:
|
||||
//http://martinecker.com/martincodes/unity-editor-window-zooming/
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using MA_Editor;
|
||||
|
||||
@ -68,3 +71,4 @@ namespace MA_Editor.RectUtils
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -1,6 +1,9 @@
|
||||
//Maxartz15
|
||||
//Version 1.0
|
||||
//https://github.com/maxartz15/MA_EditorUtils
|
||||
|
||||
//References:
|
||||
//http://martinecker.com/martincodes/unity-editor-window-zooming/
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using MA_Editor;
|
||||
using MA_Editor.RectUtils;
|
||||
@ -37,3 +40,4 @@ namespace MA_Editor.GUILayoutZoom
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -1,6 +1,9 @@
|
||||
//Maxartz15
|
||||
//Version 1.0
|
||||
//https://github.com/maxartz15/MA_MeshUtils
|
||||
|
||||
//References:
|
||||
//http://wiki.unity3d.com/index.php?title=ObjExporter
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
@ -89,15 +92,15 @@ namespace MA_Mesh
|
||||
{
|
||||
if(flipY)
|
||||
{
|
||||
Debug.Log("01" + uvs[i].x);
|
||||
//Debug.Log("01" + uvs[i].x);
|
||||
uvs[i] = new Vector2((uvs[i].x / atlasSize.x * textureRect.width) + (1 / atlasSize.x * textureRect.x), (uvs[i].y / atlasSize.y * textureRect.height) + (1 / atlasSize.y * (atlasSize.y - textureRect.height - textureRect.y)));
|
||||
Debug.Log("02" + uvs[i].x);
|
||||
//Debug.Log("02" + uvs[i].x);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("01" + uvs[i].x);
|
||||
//Debug.Log("01" + uvs[i].x);
|
||||
uvs[i] = new Vector2((uvs[i].x / atlasSize.x * textureRect.width) + (1 / atlasSize.x * textureRect.x), (uvs[i].y / atlasSize.y * textureRect.height) + (1 / atlasSize.y * textureRect.y));
|
||||
Debug.Log("02" + uvs[i].x);
|
||||
//Debug.Log("02" + uvs[i].x);
|
||||
}
|
||||
}
|
||||
|
||||
@ -185,3 +188,4 @@ namespace MA_Mesh
|
||||
public string textureName;
|
||||
}
|
||||
}
|
||||
#endif
|
@ -1,27 +1,22 @@
|
||||
//Maxartz15
|
||||
//Version 1.0
|
||||
//Part of MA_TextureUtils
|
||||
//https://github.com/maxartz15/MA_TextureUtils
|
||||
//https://github.com/maxartz15/MA_TextureUtils
|
||||
|
||||
//References:
|
||||
//http://www.gamasutra.com/blogs/JoshSutphin/20131007/201829/Adding_to_Unitys_BuiltIn_Classes_Using_Extension_Methods.php
|
||||
//https://forum.unity3d.com/threads/contribution-texture2d-blur-in-c.185694/
|
||||
//http://orbcreation.com/orbcreation/page.orb?1180
|
||||
//https://support.unity3d.com/hc/en-us/articles/206486626-How-can-I-get-pixels-from-unreadable-textures-
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
//http://www.gamasutra.com/blogs/JoshSutphin/20131007/201829/Adding_to_Unitys_BuiltIn_Classes_Using_Extension_Methods.php
|
||||
//https://forum.unity3d.com/threads/contribution-texture2d-blur-in-c.185694/
|
||||
//http://orbcreation.com/orbcreation/page.orb?1180
|
||||
//https://support.unity3d.com/hc/en-us/articles/206486626-How-can-I-get-pixels-from-unreadable-textures-
|
||||
|
||||
namespace MA_Texture
|
||||
{
|
||||
public static class MA_TextureUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// Some base converters and texture settings setters.
|
||||
/// </summary>
|
||||
|
||||
public static Texture ConvertToReadableTexture(Texture texture)
|
||||
{
|
||||
if (texture == null)
|
||||
@ -160,6 +155,30 @@ namespace MA_Texture
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
public static Texture2D MA_Scale32D(this Texture2D texture, int width, int height)
|
||||
{
|
||||
float ratioWidth = (float)width / texture.width;
|
||||
float ratioHeight = (float)height / texture.height;
|
||||
|
||||
Texture2D newTexture = new Texture2D(width, height);
|
||||
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
int posX = Mathf.FloorToInt(x / ratioWidth);
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
int posY = Mathf.FloorToInt(y / ratioHeight);
|
||||
Color pixel = texture.GetPixel(posX, posY);
|
||||
newTexture.SetPixel(x, y, new Color(pixel.r, pixel.g, pixel.b, pixel.a));
|
||||
}
|
||||
}
|
||||
|
||||
newTexture.name = texture.name;
|
||||
|
||||
newTexture.Apply();
|
||||
return newTexture;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region combine
|
||||
@ -201,3 +220,4 @@ namespace MA_Texture
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
#endif
|
18
README.md
18
README.md
@ -1,9 +1,21 @@
|
||||
# MA_TextureAtlasser
|
||||
Texture atlas creator for Unity
|
||||
|
||||
You can combine textures and/or remap the UV’s for the 3D models.
|
||||
By having full control over the size and position of the textures that are being placed in the atlas you will never stand for surprises when exporting. This will cost some more time than auto-generating your texture atlases but you know whats going on and which models/textures are getting priority.
|
||||
[]()
|
||||
|
||||
https://youtu.be/PBRKlopkZP0
|
||||
You can combine textures and/or remap the UV’s for the 3D models.
|
||||
By having full control over the size and position of the textures that are being placed in the atlas you will never stand for surprises when exporting. This will cost some more time than auto-generating your texture atlases but you know whats going on and which models/textures are getting priority. The tool can also be used to make 2D sprite sheets.
|
||||
|
||||
- Combine textures/sprites.
|
||||
- Automatically adjusts the UV's of the assigned meshes to match the new texture atlas.
|
||||
- Exports meshes as OBJ.
|
||||
- Exports texture atlas as PNG.
|
||||
- Exports texture atlas as a (sliced) sprite sheet.
|
||||
|
||||
[Example video](https://youtu.be/PBRKlopkZP0)
|
||||
|
||||
Download the UnityPackage here: https://github.com/maxartz15/MA_TextureAtlasser/releases
|
||||
|
||||
[]()
|
||||
|
||||
For more information: https://maxartz15.com/ma_textureatlas/
|
Reference in New Issue
Block a user