mirror of
https://github.com/maxartz15/MA_TextureAtlasser.git
synced 2025-07-07 08:46:07 +02:00
Compare commits
17 Commits
Author | SHA1 | Date | |
---|---|---|---|
a728366035 | |||
e81a4ec119 | |||
26a0f68454 | |||
9f5240967a | |||
9a13ddb24e | |||
6ac386c1b5 | |||
e2abb77afe | |||
68b3ddaaa1 | |||
9d53f74c4b | |||
7f17793af0 | |||
09f7c488b9 | |||
1251736f5b | |||
78e4fb0ad1 | |||
7990f987dc | |||
82efcbb6d0 | |||
7f5e22b3c1 | |||
c91c1cb7ee |
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2018 Max
|
Copyright (c) 2018 Max Kruf
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
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;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@ -15,7 +16,7 @@ namespace MA_TextureAtlasserPro
|
|||||||
public MA_TextureAtlasserProQuad selectedTextureQuad;
|
public MA_TextureAtlasserProQuad selectedTextureQuad;
|
||||||
private Rect editorWorkRect;
|
private Rect editorWorkRect;
|
||||||
public bool showTextures = false;
|
public bool showTextures = false;
|
||||||
|
public MA_TextureAtlasserProExportSettings exportSettings;
|
||||||
|
|
||||||
//Data
|
//Data
|
||||||
public Vector2 textureAtlasSize;
|
public Vector2 textureAtlasSize;
|
||||||
@ -35,7 +36,8 @@ namespace MA_TextureAtlasserPro
|
|||||||
editorWorkRect = new Rect(Vector2.zero - zoomCoordsOrigin, textureAtlasSize);
|
editorWorkRect = new Rect(Vector2.zero - zoomCoordsOrigin, textureAtlasSize);
|
||||||
|
|
||||||
GUI.backgroundColor = new Color(0, 0, 0, 0.1f);
|
GUI.backgroundColor = new Color(0, 0, 0, 0.1f);
|
||||||
GUI.Box(editorWorkRect, this.name);
|
GUI.Box(editorWorkRect, "");
|
||||||
|
GUI.Box(new Rect(editorWorkRect.x, editorWorkRect.y - 25, editorWorkRect.width, 20), this.name);
|
||||||
GUI.backgroundColor = Color.white;
|
GUI.backgroundColor = Color.white;
|
||||||
|
|
||||||
MA_Editor.Grid.Grid.DrawZoomableGrid(editorWorkRect, 64, new Color(0, 0, 0, 0.1f), zoomCoordsOrigin);
|
MA_Editor.Grid.Grid.DrawZoomableGrid(editorWorkRect, 64, new Color(0, 0, 0, 0.1f), zoomCoordsOrigin);
|
||||||
@ -100,4 +102,5 @@ namespace MA_TextureAtlasserPro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
@ -0,0 +1,63 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using System.Collections;
|
||||||
|
using MA_Texture;
|
||||||
|
|
||||||
|
namespace MA_TextureAtlasserPro
|
||||||
|
{
|
||||||
|
[System.Serializable]
|
||||||
|
public class MA_TextureAtlasserProExportSettings : ScriptableObject
|
||||||
|
{
|
||||||
|
[HideInInspector]
|
||||||
|
public bool canModify = true;
|
||||||
|
|
||||||
|
public ModelExportSettings modelExportSettings = new ModelExportSettings();
|
||||||
|
public TextureExportSettings textureExportSettings = new TextureExportSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
[System.Serializable]
|
||||||
|
public class ModelExportSettings
|
||||||
|
{
|
||||||
|
[Header("Model settings:")]
|
||||||
|
public ModelFormat modelFormat = ModelFormat.Obj;
|
||||||
|
public bool replaceModel = false;
|
||||||
|
public bool uvFlipY = true;
|
||||||
|
public int uvChannel = 0;
|
||||||
|
public bool uvWrap = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
[System.Serializable]
|
||||||
|
public class TextureExportSettings
|
||||||
|
{
|
||||||
|
[Header("Texture settings:")]
|
||||||
|
public TextureFormat textureFormat = TextureFormat.Png;
|
||||||
|
public TextureType textureType = TextureType.Default;
|
||||||
|
public MA_TextureUtils.TextureScaleMode textureScaleMode = MA_TextureUtils.TextureScaleMode.Bilinear;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum ExportPreset
|
||||||
|
{
|
||||||
|
Custom,
|
||||||
|
Default,
|
||||||
|
Sprites,
|
||||||
|
ReplaceObjMeshes
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum ModelFormat
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
Obj
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum TextureFormat
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
Png
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum TextureType
|
||||||
|
{
|
||||||
|
Default,
|
||||||
|
Sprite,
|
||||||
|
SpriteSliced
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,4 @@
|
|||||||
|
#if UNITY_EDITOR
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@ -24,7 +25,6 @@ namespace MA_TextureAtlasserPro
|
|||||||
public Rect dragRectPos;
|
public Rect dragRectPos;
|
||||||
|
|
||||||
//Data
|
//Data
|
||||||
public Texture texture; //Replace this with texture groups
|
|
||||||
public List<MA_TextureGroup> textureGroups;
|
public List<MA_TextureGroup> textureGroups;
|
||||||
public List<Mesh> meshes;
|
public List<Mesh> meshes;
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ namespace MA_TextureAtlasserPro
|
|||||||
//Clamp and snap the guiRect
|
//Clamp and snap the guiRect
|
||||||
guiRect = new Rect(Mathf.RoundToInt(rect.x / 32) * 32, Mathf.RoundToInt(rect.y / 32) * 32, Mathf.RoundToInt(rect.width / 32) * 32, Mathf.RoundToInt(rect.height / 32) * 32);
|
guiRect = new Rect(Mathf.RoundToInt(rect.x / 32) * 32, Mathf.RoundToInt(rect.y / 32) * 32, Mathf.RoundToInt(rect.width / 32) * 32, Mathf.RoundToInt(rect.height / 32) * 32);
|
||||||
|
|
||||||
//Draw the sqaud background
|
//Draw the quad background
|
||||||
if(showTexture && textureGroups != null && textureGroups.Count > 0 && textureGroups[0].texture != null)
|
if(showTexture && textureGroups != null && textureGroups.Count > 0 && textureGroups[0].texture != null)
|
||||||
GUI.DrawTexture(new Rect(guiRect.x - zoomCoordsOrigin.x, guiRect.y - zoomCoordsOrigin.y, guiRect.width, guiRect.height), textureGroups[0].texture, ScaleMode.StretchToFill);
|
GUI.DrawTexture(new Rect(guiRect.x - zoomCoordsOrigin.x, guiRect.y - zoomCoordsOrigin.y, guiRect.width, guiRect.height), textureGroups[0].texture, ScaleMode.StretchToFill);
|
||||||
else
|
else
|
||||||
@ -52,7 +52,10 @@ namespace MA_TextureAtlasserPro
|
|||||||
|
|
||||||
GUILayout.BeginHorizontal();
|
GUILayout.BeginHorizontal();
|
||||||
GUILayout.FlexibleSpace();
|
GUILayout.FlexibleSpace();
|
||||||
GUILayout.Label(this.name);
|
var tempColor = GUI.backgroundColor;
|
||||||
|
GUI.backgroundColor = new Color(1, 1, 1, 0.7f);
|
||||||
|
GUILayout.Label(" " + this.name + " ", GUI.skin.box);
|
||||||
|
GUI.backgroundColor = tempColor;
|
||||||
GUILayout.FlexibleSpace();
|
GUILayout.FlexibleSpace();
|
||||||
GUILayout.EndHorizontal();
|
GUILayout.EndHorizontal();
|
||||||
|
|
||||||
@ -163,4 +166,5 @@ namespace MA_TextureAtlasserPro
|
|||||||
debugMode = isDebugging;
|
debugMode = isDebugging;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
@ -0,0 +1,40 @@
|
|||||||
|
#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("Hotkeys:")]
|
||||||
|
public bool useHotkeys = false;
|
||||||
|
public EventModifiers modifierKey = EventModifiers.Alt;
|
||||||
|
public KeyCode addQuadHotKey = KeyCode.Q;
|
||||||
|
public KeyCode removeQuadHotKey = KeyCode.R;
|
||||||
|
public KeyCode duplicateHotKey = KeyCode.D;
|
||||||
|
public KeyCode zoomInHotKey = KeyCode.Equals;
|
||||||
|
public KeyCode zoomOutHotKey = KeyCode.Minus;
|
||||||
|
|
||||||
|
[Header("Duplication:")]
|
||||||
|
public bool copySelectedQuadData = true;
|
||||||
|
public string duplicatedQuadNamePrefix = "new ";
|
||||||
|
|
||||||
|
[Header("Selection")]
|
||||||
|
public bool autoFocus = true;
|
||||||
|
|
||||||
|
public bool GetHotKey(Event e, KeyCode shortKey)
|
||||||
|
{
|
||||||
|
if (e.type == EventType.KeyDown && e.modifiers == modifierKey && e.keyCode == shortKey)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
@ -1,4 +1,5 @@
|
|||||||
using System.Collections;
|
#if UNITY_EDITOR
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
@ -17,3 +18,4 @@ namespace MA_TextureAtlasserPro
|
|||||||
public string name;
|
public string name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
@ -1,3 +1,4 @@
|
|||||||
|
#if UNITY_EDITOR
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
|
|
||||||
@ -12,6 +13,7 @@ namespace MA_TextureAtlasserPro
|
|||||||
public static GUIContent exportAtlasIcon;
|
public static GUIContent exportAtlasIcon;
|
||||||
public static GUIContent createQuadIcon;
|
public static GUIContent createQuadIcon;
|
||||||
public static GUIContent removeQuadIcon;
|
public static GUIContent removeQuadIcon;
|
||||||
|
public static GUIContent duplicateQuadIcon;
|
||||||
public static GUIContent showTexturesOnIcon;
|
public static GUIContent showTexturesOnIcon;
|
||||||
public static GUIContent showTexturesOffIcon;
|
public static GUIContent showTexturesOffIcon;
|
||||||
public static GUIContent dragHandleIcon;
|
public static GUIContent dragHandleIcon;
|
||||||
@ -24,10 +26,12 @@ namespace MA_TextureAtlasserPro
|
|||||||
exportAtlasIcon = new GUIContent("", (Texture)EditorGUIUtility.Load(LOADICONPATH + "exportAtlasIcon" + ".png"));
|
exportAtlasIcon = new GUIContent("", (Texture)EditorGUIUtility.Load(LOADICONPATH + "exportAtlasIcon" + ".png"));
|
||||||
createQuadIcon = new GUIContent("", (Texture)EditorGUIUtility.Load(LOADICONPATH + "createQuadIcon" + ".png"));
|
createQuadIcon = new GUIContent("", (Texture)EditorGUIUtility.Load(LOADICONPATH + "createQuadIcon" + ".png"));
|
||||||
removeQuadIcon = new GUIContent("", (Texture)EditorGUIUtility.Load(LOADICONPATH + "removeQuadIcon" + ".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"));
|
showTexturesOnIcon = new GUIContent("", (Texture)EditorGUIUtility.Load(LOADICONPATH + "showTexturesOnIcon" + ".png"));
|
||||||
showTexturesOffIcon = new GUIContent("", (Texture)EditorGUIUtility.Load(LOADICONPATH + "showTexturesOffIcon" + ".png"));
|
showTexturesOffIcon = new GUIContent("", (Texture)EditorGUIUtility.Load(LOADICONPATH + "showTexturesOffIcon" + ".png"));
|
||||||
dragHandleIcon = new GUIContent("", (Texture)EditorGUIUtility.Load(LOADICONPATH + "dragHandleIcon" + ".png"));
|
dragHandleIcon = new GUIContent("", (Texture)EditorGUIUtility.Load(LOADICONPATH + "dragHandleIcon" + ".png"));
|
||||||
editIcon = new GUIContent("", (Texture)EditorGUIUtility.Load(LOADICONPATH + "editIcon" + ".png"));
|
editIcon = new GUIContent("", (Texture)EditorGUIUtility.Load(LOADICONPATH + "editIcon" + ".png"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
@ -1,3 +1,4 @@
|
|||||||
|
#if UNITY_EDITOR
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@ -7,17 +8,83 @@ using MA_Texture;
|
|||||||
|
|
||||||
namespace MA_TextureAtlasserPro
|
namespace MA_TextureAtlasserPro
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
public static class MA_TextureAtlasserProUtils
|
public static class MA_TextureAtlasserProUtils
|
||||||
{
|
{
|
||||||
public const string SAVEASSETPATH = "Assets/MA_ToolBox/MA_TextureAtlasserPro/Atlasses/";
|
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 LOADASSETPATH = "Assets/MA_ToolBox/MA_TextureAtlasserPro/Atlasses/";
|
||||||
public const string EXPORTASSETPATH = "Assets/MA_ToolBox/MA_TextureAtlasserPro/Exports/";
|
public const string EXPORTASSETPATH = "Assets/MA_ToolBox/MA_TextureAtlasserPro/Exports/";
|
||||||
public const float VIEWOFFSET = 20;
|
public const float VIEWOFFSET = 20;
|
||||||
public const string DEFAULTTEXTUREGROUPNAME = "Albedo";
|
public const string DEFAULTTEXTUREGROUPNAME = "Albedo";
|
||||||
|
|
||||||
public static MA_TextureAtlasserProAtlas CreateTextureAtlas(string name, Vector2 size)
|
public static MA_TextureAtlasserProSettings CreateSettings()
|
||||||
{
|
{
|
||||||
MA_TextureAtlasserProAtlas _atlas = (MA_TextureAtlasserProAtlas)ScriptableObject.CreateInstance<MA_TextureAtlasserProAtlas>();
|
MA_TextureAtlasserProSettings _settings = 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_TextureAtlasserProExportSettings CreateExportSettings(string name, bool canModify = true)
|
||||||
|
{
|
||||||
|
MA_TextureAtlasserProExportSettings _settings = ScriptableObject.CreateInstance<MA_TextureAtlasserProExportSettings>();
|
||||||
|
_settings.canModify = canModify;
|
||||||
|
|
||||||
|
if (_settings != null)
|
||||||
|
{
|
||||||
|
AssetDatabase.CreateAsset(_settings, EXPORTSETTINGSASSETPATH + name + ".asset");
|
||||||
|
AssetDatabase.SaveAssets();
|
||||||
|
AssetDatabase.Refresh();
|
||||||
|
|
||||||
|
return _settings;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MA_TextureAtlasserProExportSettings LoadExportSettings()
|
||||||
|
{
|
||||||
|
string name = "MA_DefaultExportSettings";
|
||||||
|
MA_TextureAtlasserProExportSettings _settings = AssetDatabase.LoadAssetAtPath(EXPORTSETTINGSASSETPATH + name + ".asset", typeof(MA_TextureAtlasserProExportSettings)) as MA_TextureAtlasserProExportSettings;
|
||||||
|
|
||||||
|
if (_settings == null)
|
||||||
|
{
|
||||||
|
_settings = CreateExportSettings(name, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return _settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MA_TextureAtlasserProAtlas CreateTextureAtlas(string name, Vector2 size)
|
||||||
|
{
|
||||||
|
MA_TextureAtlasserProAtlas _atlas = ScriptableObject.CreateInstance<MA_TextureAtlasserProAtlas>();
|
||||||
|
|
||||||
if(_atlas != null)
|
if(_atlas != null)
|
||||||
{
|
{
|
||||||
@ -72,8 +139,10 @@ namespace MA_TextureAtlasserPro
|
|||||||
{
|
{
|
||||||
atlas.textureGroupRegistration = new List<MA_TextureGroupRegistration>();
|
atlas.textureGroupRegistration = new List<MA_TextureGroupRegistration>();
|
||||||
|
|
||||||
MA_TextureGroupRegistration groupRegistration = new MA_TextureGroupRegistration();
|
MA_TextureGroupRegistration groupRegistration = new MA_TextureGroupRegistration
|
||||||
groupRegistration.name = DEFAULTTEXTUREGROUPNAME;
|
{
|
||||||
|
name = DEFAULTTEXTUREGROUPNAME
|
||||||
|
};
|
||||||
|
|
||||||
atlas.textureGroupRegistration.Add(groupRegistration);
|
atlas.textureGroupRegistration.Add(groupRegistration);
|
||||||
}
|
}
|
||||||
@ -111,9 +180,14 @@ namespace MA_TextureAtlasserPro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(atlas.exportSettings == null)
|
||||||
|
{
|
||||||
|
atlas.exportSettings = LoadExportSettings();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void CreateTextureQuad(MA_TextureAtlasserProAtlas atlas, string name, Rect rect)
|
public static MA_TextureAtlasserProQuad CreateTextureQuad(MA_TextureAtlasserProAtlas atlas, string name, Rect rect, bool focus = true)
|
||||||
{
|
{
|
||||||
if(atlas != null)
|
if(atlas != null)
|
||||||
{
|
{
|
||||||
@ -124,7 +198,7 @@ namespace MA_TextureAtlasserPro
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Create new quad
|
//Create new quad
|
||||||
MA_TextureAtlasserProQuad _quad = (MA_TextureAtlasserProQuad)ScriptableObject.CreateInstance("MA_TextureAtlasserProQuad");
|
MA_TextureAtlasserProQuad _quad = ScriptableObject.CreateInstance<MA_TextureAtlasserProQuad>();
|
||||||
|
|
||||||
//Add quad to asset
|
//Add quad to asset
|
||||||
if(_quad != null)
|
if(_quad != null)
|
||||||
@ -135,11 +209,18 @@ namespace MA_TextureAtlasserPro
|
|||||||
|
|
||||||
SetTextureGroups(atlas, _quad);
|
SetTextureGroups(atlas, _quad);
|
||||||
|
|
||||||
atlas.textureQuads.Add((MA_TextureAtlasserProQuad)_quad);
|
atlas.textureQuads.Add(_quad);
|
||||||
|
|
||||||
AssetDatabase.AddObjectToAsset(_quad, atlas);
|
AssetDatabase.AddObjectToAsset(_quad, atlas);
|
||||||
AssetDatabase.SaveAssets();
|
AssetDatabase.SaveAssets();
|
||||||
AssetDatabase.Refresh();
|
AssetDatabase.Refresh();
|
||||||
|
|
||||||
|
if(focus)
|
||||||
|
{
|
||||||
|
atlas.selectedTextureQuad = atlas.textureQuads[atlas.textureQuads.Count - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
return _quad;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -150,14 +231,54 @@ namespace MA_TextureAtlasserPro
|
|||||||
{
|
{
|
||||||
Debug.LogError("CreateTextureQuad Failed: textureAtlas");
|
Debug.LogError("CreateTextureQuad Failed: textureAtlas");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RemoveTextureQuad(MA_TextureAtlasserProAtlas atlas)
|
public static void RemoveTextureQuad(MA_TextureAtlasserProAtlas atlas, bool focus = true)
|
||||||
{
|
{
|
||||||
if(atlas != null && atlas.selectedTextureQuad != null)
|
if(atlas != null && atlas.selectedTextureQuad != null)
|
||||||
{
|
{
|
||||||
atlas.textureQuads.Remove(atlas.selectedTextureQuad);
|
int _index = atlas.textureQuads.IndexOf(atlas.selectedTextureQuad);
|
||||||
GameObject.DestroyImmediate(atlas.selectedTextureQuad, true);
|
|
||||||
|
atlas.textureQuads.RemoveAt(_index);
|
||||||
|
Object.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)
|
||||||
|
{
|
||||||
|
MA_TextureAtlasserProQuad q = CreateTextureQuad(atlas, namePrefix + atlas.selectedTextureQuad.name, atlas.selectedTextureQuad.rect, false);
|
||||||
|
|
||||||
|
if (copyData)
|
||||||
|
{
|
||||||
|
q.meshes = new List<Mesh>();
|
||||||
|
for (int i = 0; i < atlas.selectedTextureQuad.meshes.Count; i++)
|
||||||
|
{
|
||||||
|
q.meshes.Add(atlas.selectedTextureQuad.meshes[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < atlas.selectedTextureQuad.textureGroups.Count; i++)
|
||||||
|
{
|
||||||
|
q.textureGroups[i].texture = atlas.selectedTextureQuad.textureGroups[i].texture;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(focus)
|
||||||
|
{
|
||||||
|
atlas.selectedTextureQuad = q;
|
||||||
|
}
|
||||||
|
|
||||||
AssetDatabase.SaveAssets();
|
AssetDatabase.SaveAssets();
|
||||||
AssetDatabase.Refresh();
|
AssetDatabase.Refresh();
|
||||||
}
|
}
|
||||||
@ -173,22 +294,28 @@ namespace MA_TextureAtlasserPro
|
|||||||
//Add texture groups
|
//Add texture groups
|
||||||
foreach (MA_TextureGroupRegistration tgr in atlas.textureGroupRegistration)
|
foreach (MA_TextureGroupRegistration tgr in atlas.textureGroupRegistration)
|
||||||
{
|
{
|
||||||
MA_TextureGroup textureGroup = new MA_TextureGroup();
|
MA_TextureGroup textureGroup = new MA_TextureGroup
|
||||||
textureGroup.name = tgr.name;
|
{
|
||||||
|
name = tgr.name
|
||||||
|
};
|
||||||
quad.textureGroups.Add(textureGroup);
|
quad.textureGroups.Add(textureGroup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void CreateTextureGroup(MA_TextureAtlasserProAtlas atlas, string name)
|
public static void CreateTextureGroup(MA_TextureAtlasserProAtlas atlas, string name)
|
||||||
{
|
{
|
||||||
MA_TextureGroupRegistration _textureGroupRegistration = new MA_TextureGroupRegistration();
|
MA_TextureGroupRegistration _textureGroupRegistration = new MA_TextureGroupRegistration
|
||||||
_textureGroupRegistration.name = name;
|
{
|
||||||
|
name = name
|
||||||
|
};
|
||||||
atlas.textureGroupRegistration.Add(_textureGroupRegistration);
|
atlas.textureGroupRegistration.Add(_textureGroupRegistration);
|
||||||
|
|
||||||
foreach (MA_TextureAtlasserProQuad q in atlas.textureQuads)
|
foreach (MA_TextureAtlasserProQuad q in atlas.textureQuads)
|
||||||
{
|
{
|
||||||
MA_TextureGroup _textureGroup = new MA_TextureGroup();
|
MA_TextureGroup _textureGroup = new MA_TextureGroup
|
||||||
_textureGroup.name = name;
|
{
|
||||||
|
name = name
|
||||||
|
};
|
||||||
q.textureGroups.Add(_textureGroup);
|
q.textureGroups.Add(_textureGroup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -212,106 +339,190 @@ namespace MA_TextureAtlasserPro
|
|||||||
curWindow.Close();
|
curWindow.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ExportAtlas(MA_TextureAtlasserProAtlas atlas, string savePath = EXPORTASSETPATH)
|
public static bool IsPowerOfTwo(int value)
|
||||||
{
|
{
|
||||||
if(atlas != null && atlas.textureQuads != null)
|
//While x is even and > 1
|
||||||
|
while (((value % 2) == 0) && value > 1)
|
||||||
{
|
{
|
||||||
ExportAtlasMeshesObj(atlas);
|
value /= 2;
|
||||||
ExportAtlasTexturesPNG(atlas);
|
|
||||||
|
|
||||||
AssetDatabase.Refresh();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return (value == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ExportAtlasMeshesObj(MA_TextureAtlasserProAtlas atlas, string savePath = EXPORTASSETPATH)
|
#region Export
|
||||||
|
public static void ExportAtlasModels(MA_TextureAtlasserProAtlas atlas, ModelExportSettings modelExportSettings, string savePath = EXPORTASSETPATH)
|
||||||
|
{
|
||||||
|
switch(modelExportSettings.modelFormat)
|
||||||
|
{
|
||||||
|
case ModelFormat.None:
|
||||||
|
break;
|
||||||
|
case ModelFormat.Obj:
|
||||||
|
ExportAtlasObj(atlas, modelExportSettings, savePath);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ExportAtlasObj(MA_TextureAtlasserProAtlas atlas, ModelExportSettings modelExportSettings, string savePath = EXPORTASSETPATH)
|
||||||
{
|
{
|
||||||
if(atlas != null && atlas.textureQuads != null)
|
if (atlas == null || atlas.textureQuads == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(modelExportSettings.replaceModel)
|
||||||
|
{
|
||||||
|
var quads = atlas.textureQuads;
|
||||||
|
|
||||||
|
for (var index = 0; index < quads.Count; index++)
|
||||||
|
{
|
||||||
|
var quad = quads[index];
|
||||||
|
if (quad.meshes == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var meshes = quad.meshes;
|
||||||
|
for (var meshIndex = 0; meshIndex < quad.meshes.Count; meshIndex++)
|
||||||
|
{
|
||||||
|
if (meshes[meshIndex] == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
MA_MeshUtils.MA_UVReMap(meshes[meshIndex], atlas.textureAtlasSize, quad.guiRect, modelExportSettings.uvChannel, modelExportSettings.uvFlipY, modelExportSettings.uvWrap);
|
||||||
|
EditorUtility.SetDirty(meshes[meshIndex]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AssetDatabase.SaveAssets();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (MA_TextureAtlasserProQuad quad in atlas.textureQuads)
|
||||||
|
{
|
||||||
|
//Export Mesh
|
||||||
|
if (quad.meshes != null)
|
||||||
|
{
|
||||||
|
for (int m = 0; m < quad.meshes.Count; m++)
|
||||||
|
{
|
||||||
|
if (quad.meshes[m] != null)
|
||||||
|
{
|
||||||
|
//Create new mesh
|
||||||
|
Mesh newMesh = new Mesh();
|
||||||
|
//Duplicate it from the current one
|
||||||
|
newMesh = MA_MeshUtils.MA_DuplicateMesh(quad.meshes[m]);
|
||||||
|
//Remap UV's
|
||||||
|
newMesh = MA_MeshUtils.MA_UVReMap(newMesh, atlas.textureAtlasSize, quad.guiRect, modelExportSettings.uvChannel, modelExportSettings.uvFlipY, modelExportSettings.uvWrap);
|
||||||
|
//Save it
|
||||||
|
string modelName = string.IsNullOrEmpty(quad.name) ? "" : quad.name + "-";
|
||||||
|
modelName += quad.meshes[m].name;
|
||||||
|
int n = m + 1;
|
||||||
|
modelName += "_" + n.ToString("#000");
|
||||||
|
|
||||||
|
MA_MeshUtils.MeshToFile(newMesh, modelName, savePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ExportAtlasTextures(MA_TextureAtlasserProAtlas atlas, TextureExportSettings textureExportSettings, string savePath = EXPORTASSETPATH)
|
||||||
|
{
|
||||||
|
switch (textureExportSettings.textureFormat)
|
||||||
|
{
|
||||||
|
case TextureFormat.None:
|
||||||
|
break;
|
||||||
|
case TextureFormat.Png:
|
||||||
|
ExportAtlasPNG(atlas, textureExportSettings, savePath);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ExportAtlasPNG(MA_TextureAtlasserProAtlas atlas, TextureExportSettings textureExportSettings, string savePath = EXPORTASSETPATH)
|
||||||
|
{
|
||||||
|
if (atlas == null || atlas.textureQuads == null || atlas.textureGroupRegistration == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
//Foreach texture group
|
||||||
|
for (int i = 0; i < atlas.textureGroupRegistration.Count; i++)
|
||||||
{
|
{
|
||||||
foreach (MA_TextureAtlasserProQuad ta in atlas.textureQuads)
|
//Create new Texture Atlas
|
||||||
|
Texture2D newTexture = new Texture2D((int)atlas.textureAtlasSize.x, (int)atlas.textureAtlasSize.y)
|
||||||
{
|
{
|
||||||
//Export Mesh
|
name = atlas.name + "_" + atlas.textureGroupRegistration[i].name
|
||||||
if(ta.meshes != null)
|
};
|
||||||
|
|
||||||
|
foreach (MA_TextureAtlasserProQuad q in atlas.textureQuads)
|
||||||
|
{
|
||||||
|
if (q.textureGroups != null && q.textureGroups[i].texture != null)
|
||||||
{
|
{
|
||||||
for (int m = 0; m < ta.meshes.Count; m++)
|
//Create new texture part
|
||||||
{
|
Texture2D newTexturePart = (Texture2D)MA_TextureUtils.ConvertToReadableTexture(q.textureGroups[i].texture);
|
||||||
if(ta.meshes[m] != null)
|
//Scale it
|
||||||
{
|
newTexturePart = newTexturePart.MA_Scale2D((int)q.guiRect.width, (int)q.guiRect.height, textureExportSettings.textureScaleMode);
|
||||||
//Create new mesh
|
//Add it
|
||||||
Mesh newMesh = new Mesh();
|
newTexture = newTexture.MA_Combine2D(newTexturePart, (int)q.guiRect.x, (int)q.guiRect.y);
|
||||||
//Duplicate it from the current one
|
|
||||||
newMesh = MA_MeshUtils.MA_DuplicateMesh(ta.meshes[m]);
|
|
||||||
//Remap uvs
|
|
||||||
newMesh = MA_MeshUtils.MA_UVReMap(newMesh, atlas.textureAtlasSize, ta.guiRect);
|
|
||||||
//Save it
|
|
||||||
MA_MeshUtils.MeshToFile(newMesh, "MA_" + ta.name, savePath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Save it
|
||||||
|
newTexture.MA_Save2D(newTexture.name, savePath);
|
||||||
|
|
||||||
|
TextureImporter textureImporter = (TextureImporter)AssetImporter.GetAtPath(savePath + newTexture.name + ".png");
|
||||||
|
textureImporter.textureType = TextureImporterType.Default;
|
||||||
|
textureImporter.SaveAndReimport();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SetAtlasPNGSpriteSettings(atlas, textureExportSettings, savePath);
|
||||||
|
|
||||||
|
//Refresh
|
||||||
|
AssetDatabase.Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
// public static void ExportAtlasTexturePNG(MA_TextureAtlasserProAtlas atlas, string savePath = EXPORTASSETPATH)
|
private static void SetAtlasPNGSpriteSettings(MA_TextureAtlasserProAtlas atlas, TextureExportSettings textureExportSettings, string savePath = EXPORTASSETPATH)
|
||||||
// {
|
|
||||||
// if(atlas != null && atlas.textureQuads != null)
|
|
||||||
// {
|
|
||||||
// //Create new Texture Atlas
|
|
||||||
// Texture2D newTexture = new Texture2D((int)atlas.textureAtlasSize.x, (int)atlas.textureAtlasSize.y);
|
|
||||||
// newTexture.name = atlas.name;
|
|
||||||
|
|
||||||
// foreach (MA_TextureAtlasserProQuad ta in atlas.textureQuads)
|
|
||||||
// {
|
|
||||||
// //Export Texture Atlas
|
|
||||||
// //TODO: Replace with texture groups (foreacht ...)
|
|
||||||
// if(ta.texture != null)
|
|
||||||
// {
|
|
||||||
// //Create new texture part
|
|
||||||
// Texture2D newTexturePart = (Texture2D)MA_Texture.MA_TextureUtils.ConvertToReadableTexture(ta.texture);
|
|
||||||
// //Scale it
|
|
||||||
// newTexturePart = newTexturePart.MA_Scale2D((int)ta.guiRect.width, (int)ta.guiRect.height);
|
|
||||||
// //Add it
|
|
||||||
// newTexture = newTexture.MA_Combine2D(newTexturePart, (int)ta.guiRect.x, (int)ta.guiRect.y);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// //Save it
|
|
||||||
// newTexture.MA_Save2D("MA_" + newTexture.name, savePath);
|
|
||||||
// //Refresh
|
|
||||||
// AssetDatabase.Refresh();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
public static void ExportAtlasTexturesPNG(MA_TextureAtlasserProAtlas atlas, string savePath = EXPORTASSETPATH)
|
|
||||||
{
|
{
|
||||||
if(atlas != null && atlas.textureQuads != null && atlas.textureGroupRegistration != null)
|
//Foreach texture group
|
||||||
|
for (int i = 0; i < atlas.textureGroupRegistration.Count; i++)
|
||||||
{
|
{
|
||||||
//Foreach texture group
|
//Convert
|
||||||
for (int i = 0; i < atlas.textureGroupRegistration.Count; i++)
|
string textureName = atlas.name + "_" + atlas.textureGroupRegistration[i].name + ".png";
|
||||||
|
TextureImporter textureImporter = (TextureImporter)AssetImporter.GetAtPath(savePath + textureName);
|
||||||
|
textureImporter.textureType = TextureImporterType.Sprite;
|
||||||
|
textureImporter.alphaIsTransparency = true;
|
||||||
|
|
||||||
|
//Slice sprites.
|
||||||
|
if (textureExportSettings.textureType == TextureType.SpriteSliced)
|
||||||
{
|
{
|
||||||
//Create new Texture Atlas
|
textureImporter.spriteImportMode = SpriteImportMode.None; //Reset it to update?
|
||||||
Texture2D newTexture = new Texture2D((int)atlas.textureAtlasSize.x, (int)atlas.textureAtlasSize.y);
|
textureImporter.spriteImportMode = SpriteImportMode.Multiple;
|
||||||
newTexture.name = atlas.name + "_" + atlas.textureGroupRegistration[i].name;
|
List<SpriteMetaData> spriteMetaData = new List<SpriteMetaData>();
|
||||||
|
|
||||||
foreach (MA_TextureAtlasserProQuad q in atlas.textureQuads)
|
foreach (MA_TextureAtlasserProQuad q in atlas.textureQuads)
|
||||||
{
|
{
|
||||||
if(q.textureGroups != null && q.textureGroups[i].texture != null)
|
if (q.textureGroups != null && q.textureGroups[i].texture != null)
|
||||||
{
|
{
|
||||||
//Create new texture part
|
//Create new SpriteMetaData.
|
||||||
Texture2D newTexturePart = (Texture2D)MA_Texture.MA_TextureUtils.ConvertToReadableTexture(q.textureGroups[i].texture);
|
SpriteMetaData smd = new SpriteMetaData
|
||||||
//Scale it
|
{
|
||||||
newTexturePart = newTexturePart.MA_Scale2D((int)q.guiRect.width, (int)q.guiRect.height);
|
name = q.name,
|
||||||
//Add it
|
rect = new Rect(q.guiRect.x, atlas.textureAtlasSize.y - q.guiRect.y - q.guiRect.height, q.guiRect.width, q.guiRect.height)
|
||||||
newTexture = newTexture.MA_Combine2D(newTexturePart, (int)q.guiRect.x, (int)q.guiRect.y);
|
};
|
||||||
|
|
||||||
|
spriteMetaData.Add(smd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Save it
|
textureImporter.spritesheet = spriteMetaData.ToArray();
|
||||||
newTexture.MA_Save2D("MA_" + newTexture.name, savePath);
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
textureImporter.spriteImportMode = SpriteImportMode.Single;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Refresh
|
textureImporter.SaveAndReimport();
|
||||||
AssetDatabase.Refresh();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
@ -1,3 +1,4 @@
|
|||||||
|
#if UNITY_EDITOR
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@ -32,7 +33,7 @@ namespace MA_TextureAtlasserPro
|
|||||||
curWindow.workView.ResetWindow();
|
curWindow.workView.ResetWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(curWindow.textureAtlas != null)
|
if (curWindow.textureAtlas != null)
|
||||||
{
|
{
|
||||||
GUILayout.FlexibleSpace();
|
GUILayout.FlexibleSpace();
|
||||||
//GUILayout.Label(curWindow.textureAtlas.textureAtlasSize.ToString());
|
//GUILayout.Label(curWindow.textureAtlas.textureAtlasSize.ToString());
|
||||||
@ -75,4 +76,5 @@ namespace MA_TextureAtlasserPro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
@ -1,3 +1,4 @@
|
|||||||
|
#if UNITY_EDITOR
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@ -12,6 +13,8 @@ namespace MA_TextureAtlasserPro
|
|||||||
|
|
||||||
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)
|
public MA_TextureAtlasserProInspectorView(MA_TextureAtlasserProWindow currentEditorWindow, string title) : base(currentEditorWindow, title)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -114,8 +117,17 @@ namespace MA_TextureAtlasserPro
|
|||||||
}
|
}
|
||||||
|
|
||||||
GUILayout.FlexibleSpace();
|
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("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.EndVertical();
|
||||||
GUILayout.EndArea();
|
GUILayout.EndArea();
|
||||||
@ -131,4 +143,5 @@ namespace MA_TextureAtlasserPro
|
|||||||
base.ProcessEvents(e, editorViewRect);
|
base.ProcessEvents(e, editorViewRect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
@ -1,3 +1,4 @@
|
|||||||
|
#if UNITY_EDITOR
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@ -52,12 +53,17 @@ namespace MA_TextureAtlasserPro
|
|||||||
GUILayout.Space(MA_TextureAtlasserProUtils.VIEWOFFSET);
|
GUILayout.Space(MA_TextureAtlasserProUtils.VIEWOFFSET);
|
||||||
if(GUILayout.Button(MA_TextureAtlasserProIcons.createQuadIcon, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
|
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 && GUILayout.Button(MA_TextureAtlasserProIcons.removeQuadIcon, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
|
||||||
{
|
{
|
||||||
if(curWindow.textureAtlas.selectedTextureQuad != null)
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,4 +79,5 @@ namespace MA_TextureAtlasserPro
|
|||||||
base.ProcessEvents(e, editorViewRect);
|
base.ProcessEvents(e, editorViewRect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
@ -1,4 +1,5 @@
|
|||||||
using System.Collections;
|
#if UNITY_EDITOR
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
@ -52,4 +53,5 @@ namespace MA_TextureAtlasserPro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
@ -1,4 +1,5 @@
|
|||||||
using System.Collections;
|
#if UNITY_EDITOR
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using MA_Editor;
|
using MA_Editor;
|
||||||
@ -18,7 +19,7 @@ namespace MA_TextureAtlasserPro
|
|||||||
private const float kZoomMax = 2.0f;
|
private const float kZoomMax = 2.0f;
|
||||||
private Rect zoomArea;
|
private Rect zoomArea;
|
||||||
private float zoom = 1.0f;
|
private float zoom = 1.0f;
|
||||||
public float Zoom { get { return zoom; } }
|
public float Zoom { get { return zoom; } set { zoom = Mathf.Clamp(value, kZoomMin, kZoomMax); } }
|
||||||
private Vector2 zoomCoordsOrigin = Vector2.zero;
|
private Vector2 zoomCoordsOrigin = Vector2.zero;
|
||||||
|
|
||||||
public override void UpdateView(Event e, Rect editorViewRect)
|
public override void UpdateView(Event e, Rect editorViewRect)
|
||||||
@ -89,6 +90,45 @@ namespace MA_TextureAtlasserPro
|
|||||||
|
|
||||||
e.Use();
|
e.Use();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Hotkeys.
|
||||||
|
if (curWindow.settings.useHotkeys)
|
||||||
|
{
|
||||||
|
if(curWindow.textureAtlas != null)
|
||||||
|
{
|
||||||
|
if (curWindow.settings.GetHotKey(e, curWindow.settings.addQuadHotKey))
|
||||||
|
{
|
||||||
|
MA_TextureAtlasserProUtils.CreateTextureQuad(curWindow.textureAtlas, "new Quad", new Rect(0, 0, 128, 128), curWindow.settings.autoFocus);
|
||||||
|
e.Use();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(curWindow.settings.GetHotKey(e, curWindow.settings.zoomInHotKey))
|
||||||
|
{
|
||||||
|
Zoom += 0.25f;
|
||||||
|
e.Use();
|
||||||
|
}
|
||||||
|
if(curWindow.settings.GetHotKey(e, curWindow.settings.zoomOutHotKey))
|
||||||
|
{
|
||||||
|
Zoom -= 0.25f;
|
||||||
|
e.Use();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (curWindow.textureAtlas.selectedTextureQuad != null)
|
||||||
|
{
|
||||||
|
if (curWindow.settings.GetHotKey(e, curWindow.settings.removeQuadHotKey))
|
||||||
|
{
|
||||||
|
MA_TextureAtlasserProUtils.RemoveTextureQuad(curWindow.textureAtlas, curWindow.settings.autoFocus);
|
||||||
|
e.Use();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (curWindow.settings.GetHotKey(e, curWindow.settings.duplicateHotKey))
|
||||||
|
{
|
||||||
|
MA_TextureAtlasserProUtils.DuplicateTextureQuad(curWindow.textureAtlas, curWindow.settings.autoFocus, curWindow.settings.copySelectedQuadData, curWindow.settings.duplicatedQuadNamePrefix);
|
||||||
|
e.Use();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Vector2 ConvertScreenCoordsToZoomCoords(Vector2 screenCoords)
|
private Vector2 ConvertScreenCoordsToZoomCoords(Vector2 screenCoords)
|
||||||
@ -119,4 +159,5 @@ namespace MA_TextureAtlasserPro
|
|||||||
zoomCoordsOrigin = new Vector2(-(curWindow.position.width / 2) + (curWindow.position.width / 3), -(curWindow.position.height / 2) + (curWindow.position.height / 3));
|
zoomCoordsOrigin = new Vector2(-(curWindow.position.width / 2) + (curWindow.position.width / 3), -(curWindow.position.height / 2) + (curWindow.position.height / 3));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
@ -0,0 +1,88 @@
|
|||||||
|
#if UNITY_EDITOR
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEditor;
|
||||||
|
using MA_Editor;
|
||||||
|
using MA_Texture;
|
||||||
|
|
||||||
|
namespace MA_TextureAtlasserPro
|
||||||
|
{
|
||||||
|
public class MA_TextureAtlasserProCreateExportWindow : EditorWindow
|
||||||
|
{
|
||||||
|
private const int windowHeight = 97;
|
||||||
|
private const int windowWidth = 320;
|
||||||
|
|
||||||
|
//Editor
|
||||||
|
private static MA_TextureAtlasserProCreateExportWindow thisWindow;
|
||||||
|
public static MA_TextureAtlasserProWindow curWindow;
|
||||||
|
|
||||||
|
//Data
|
||||||
|
string settingsName = "Settings name";
|
||||||
|
bool nameError = true;
|
||||||
|
|
||||||
|
[MenuItem("MA_ToolKit/MA_TextureAtlasserPro/New Export Settings")]
|
||||||
|
public static void Init()
|
||||||
|
{
|
||||||
|
InitWindow(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void InitWindow(MA_TextureAtlasserProWindow currentEditorWindow)
|
||||||
|
{
|
||||||
|
curWindow = currentEditorWindow;
|
||||||
|
|
||||||
|
GetCurrentWindow();
|
||||||
|
|
||||||
|
thisWindow.minSize = new Vector2(windowWidth, windowHeight);
|
||||||
|
thisWindow.maxSize = new Vector2(windowWidth, windowHeight);
|
||||||
|
thisWindow.titleContent.text = "MA_CreateExportSettings";
|
||||||
|
|
||||||
|
thisWindow.Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void GetCurrentWindow()
|
||||||
|
{
|
||||||
|
thisWindow = (MA_TextureAtlasserProCreateExportWindow)EditorWindow.GetWindow<MA_TextureAtlasserProCreateExportWindow>();
|
||||||
|
}
|
||||||
|
|
||||||
|
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.BeginVertical();
|
||||||
|
|
||||||
|
//Input options
|
||||||
|
settingsName = EditorGUILayout.TextField("Settings name", settingsName, GUILayout.ExpandWidth(true));
|
||||||
|
if (settingsName == "Settings name" || string.IsNullOrEmpty(settingsName))
|
||||||
|
{
|
||||||
|
nameError = true;
|
||||||
|
GUI.backgroundColor = Color.red;
|
||||||
|
GUILayout.Box("Error: Enter a valid settings name!", EditorStyles.helpBox);
|
||||||
|
GUI.backgroundColor = Color.white;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nameError = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Create
|
||||||
|
if (!nameError)
|
||||||
|
{
|
||||||
|
if (GUILayout.Button("Create!", GUILayout.ExpandWidth(true), GUILayout.Height(37)))
|
||||||
|
{
|
||||||
|
MA_TextureAtlasserProExportSettings exportSettings = MA_TextureAtlasserProUtils.CreateExportSettings(settingsName, true);
|
||||||
|
|
||||||
|
if (curWindow != null && curWindow.textureAtlas != null)
|
||||||
|
{
|
||||||
|
curWindow.textureAtlas.exportSettings = exportSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GUILayout.EndVertical();
|
||||||
|
GUILayout.EndArea();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
@ -1,4 +1,5 @@
|
|||||||
using System.Collections;
|
#if UNITY_EDITOR
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
@ -167,4 +168,5 @@ namespace MA_TextureAtlasserPro
|
|||||||
isLoaded = true;
|
isLoaded = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
@ -1,32 +1,35 @@
|
|||||||
using System.Collections;
|
#if UNITY_EDITOR
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using MA_Editor;
|
using MA_Editor;
|
||||||
|
using MA_Texture;
|
||||||
|
|
||||||
namespace MA_TextureAtlasserPro
|
namespace MA_TextureAtlasserPro
|
||||||
{
|
{
|
||||||
public class MA_TextureAtlasserProExportWindow : EditorWindow
|
public class MA_TextureAtlasserProExportWindow : EditorWindow
|
||||||
{
|
{
|
||||||
//Editor
|
private const int windowHeight = 300;
|
||||||
private static MA_TextureAtlasserProExportWindow thisWindow;
|
private const int windowWidth = 320;
|
||||||
public static MA_TextureAtlasserProWindow curWindow;
|
|
||||||
|
|
||||||
//Data
|
//Editor
|
||||||
private static bool isLoaded = false; //Make sure we wait a frame at the start to setup and don't draw.
|
private static MA_TextureAtlasserProExportWindow thisWindow;
|
||||||
|
public static MA_TextureAtlasserProWindow curWindow;
|
||||||
|
|
||||||
[MenuItem("MA_ToolKit/MA_TextureAtlasserPro/Export Atlas")]
|
//Data
|
||||||
|
private static bool isLoaded = false; //Make sure we wait a frame at the start to setup and don't draw.
|
||||||
|
|
||||||
|
[MenuItem("MA_ToolKit/MA_TextureAtlasserPro/Export Atlas")]
|
||||||
private static void Init()
|
private static void Init()
|
||||||
{
|
{
|
||||||
GetCurrentWindow();
|
GetCurrentWindow();
|
||||||
|
|
||||||
thisWindow.minSize = new Vector2(500,160);
|
thisWindow.minSize = new Vector2(windowWidth, windowHeight);
|
||||||
thisWindow.maxSize = new Vector2(500,160);
|
thisWindow.titleContent.text = "MA_ExportTextureAtlas";
|
||||||
|
|
||||||
thisWindow.titleContent.text = "MA_ExportTextureAtlas";
|
thisWindow.Show();
|
||||||
|
}
|
||||||
thisWindow.Show();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void InitEditorWindow(MA_TextureAtlasserProWindow currentEditorWindow)
|
public static void InitEditorWindow(MA_TextureAtlasserProWindow currentEditorWindow)
|
||||||
{
|
{
|
||||||
@ -34,9 +37,7 @@ namespace MA_TextureAtlasserPro
|
|||||||
|
|
||||||
GetCurrentWindow();
|
GetCurrentWindow();
|
||||||
|
|
||||||
thisWindow.minSize = new Vector2(500,160);
|
thisWindow.minSize = new Vector2(windowWidth, windowHeight);
|
||||||
thisWindow.maxSize = new Vector2(500,160);
|
|
||||||
|
|
||||||
thisWindow.titleContent.text = "MA_ExportTextureAtlas";
|
thisWindow.titleContent.text = "MA_ExportTextureAtlas";
|
||||||
|
|
||||||
thisWindow.Show();
|
thisWindow.Show();
|
||||||
@ -93,17 +94,16 @@ namespace MA_TextureAtlasserPro
|
|||||||
|
|
||||||
if(curWindow != null && curWindow.textureAtlas != null)
|
if(curWindow != null && curWindow.textureAtlas != null)
|
||||||
{
|
{
|
||||||
//Export options
|
|
||||||
GUILayout.Box("Note: No custom export options right now.. :<", EditorStyles.helpBox);
|
|
||||||
|
|
||||||
//Export
|
//Export
|
||||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
GUILayout.BeginVertical();
|
||||||
|
DrawExportMenu();
|
||||||
|
|
||||||
GUILayout.Label("Meshes: OBJ | Textures: PNG");
|
curWindow.textureAtlas.exportSettings = (MA_TextureAtlasserProExportSettings)EditorGUILayout.ObjectField(curWindow.textureAtlas.exportSettings, typeof(MA_TextureAtlasserProExportSettings), false);
|
||||||
if(GUILayout.Button("Export Atlas", GUILayout.ExpandWidth(true), GUILayout.Height(37)))
|
|
||||||
{
|
if(curWindow.textureAtlas.exportSettings != null)
|
||||||
MA_TextureAtlasserProUtils.ExportAtlas(curWindow.textureAtlas);
|
{
|
||||||
}
|
DrawExportAdvancedOptions();
|
||||||
|
}
|
||||||
|
|
||||||
GUILayout.EndVertical();
|
GUILayout.EndVertical();
|
||||||
}
|
}
|
||||||
@ -131,5 +131,69 @@ namespace MA_TextureAtlasserPro
|
|||||||
if(e.type == EventType.Repaint)
|
if(e.type == EventType.Repaint)
|
||||||
isLoaded = true;
|
isLoaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void DrawExportMenu()
|
||||||
|
{
|
||||||
|
GUILayout.BeginHorizontal(EditorStyles.helpBox, GUILayout.Height(44));
|
||||||
|
|
||||||
|
if (GUILayout.Button(MA_TextureAtlasserProIcons.createAtlasIcon, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
|
||||||
|
{
|
||||||
|
MA_TextureAtlasserProCreateExportWindow.InitWindow(curWindow);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wasEnabled = GUI.enabled;
|
||||||
|
|
||||||
|
if (curWindow.textureAtlas.exportSettings != null)
|
||||||
|
{
|
||||||
|
GUI.enabled = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GUI.enabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GUILayout.Button("Export", GUILayout.ExpandWidth(true), GUILayout.Height(37)))
|
||||||
|
{
|
||||||
|
MA_TextureAtlasserProUtils.ExportAtlasModels(curWindow.textureAtlas, curWindow.textureAtlas.exportSettings.modelExportSettings);
|
||||||
|
MA_TextureAtlasserProUtils.ExportAtlasTextures(curWindow.textureAtlas, curWindow.textureAtlas.exportSettings.textureExportSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
GUI.enabled = wasEnabled;
|
||||||
|
|
||||||
|
GUILayout.EndHorizontal();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawExportAdvancedOptions()
|
||||||
|
{
|
||||||
|
bool wasEnabled = GUI.enabled;
|
||||||
|
|
||||||
|
if (curWindow.textureAtlas.exportSettings.canModify)
|
||||||
|
{
|
||||||
|
GUI.enabled = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GUI.enabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
|
||||||
|
|
||||||
|
GUILayout.Label("Models:", EditorStyles.miniBoldLabel);
|
||||||
|
curWindow.textureAtlas.exportSettings.modelExportSettings.modelFormat = (ModelFormat)EditorGUILayout.EnumPopup("ModelFormat:", curWindow.textureAtlas.exportSettings.modelExportSettings.modelFormat);
|
||||||
|
curWindow.textureAtlas.exportSettings.modelExportSettings.replaceModel = EditorGUILayout.Toggle("ReplaceModels:", curWindow.textureAtlas.exportSettings.modelExportSettings.replaceModel);
|
||||||
|
curWindow.textureAtlas.exportSettings.modelExportSettings.uvFlipY = EditorGUILayout.Toggle("UV FlipY:", curWindow.textureAtlas.exportSettings.modelExportSettings.uvFlipY);
|
||||||
|
curWindow.textureAtlas.exportSettings.modelExportSettings.uvChannel = EditorGUILayout.IntField("UV Channel:", curWindow.textureAtlas.exportSettings.modelExportSettings.uvChannel);
|
||||||
|
curWindow.textureAtlas.exportSettings.modelExportSettings.uvWrap = EditorGUILayout.Toggle("UV Wrap:", curWindow.textureAtlas.exportSettings.modelExportSettings.uvWrap);
|
||||||
|
|
||||||
|
GUILayout.Label("Textures:", EditorStyles.miniBoldLabel);
|
||||||
|
curWindow.textureAtlas.exportSettings.textureExportSettings.textureFormat = (TextureFormat)EditorGUILayout.EnumPopup("TextureFormat:", curWindow.textureAtlas.exportSettings.textureExportSettings.textureFormat);
|
||||||
|
curWindow.textureAtlas.exportSettings.textureExportSettings.textureType = (TextureType)EditorGUILayout.EnumPopup("TextureType:", curWindow.textureAtlas.exportSettings.textureExportSettings.textureType);
|
||||||
|
curWindow.textureAtlas.exportSettings.textureExportSettings.textureScaleMode = (MA_TextureUtils.TextureScaleMode)EditorGUILayout.EnumPopup("TextureScaleMode:", curWindow.textureAtlas.exportSettings.textureExportSettings.textureScaleMode);
|
||||||
|
|
||||||
|
EditorGUILayout.EndVertical();
|
||||||
|
|
||||||
|
GUI.enabled = wasEnabled;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
@ -1,4 +1,5 @@
|
|||||||
using System.Collections;
|
#if UNITY_EDITOR
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
@ -8,6 +9,7 @@ namespace MA_TextureAtlasserPro
|
|||||||
public class MA_TextureAtlasserProWindow : EditorWindow
|
public class MA_TextureAtlasserProWindow : EditorWindow
|
||||||
{
|
{
|
||||||
public static MA_TextureAtlasserProWindow thisWindow;
|
public static MA_TextureAtlasserProWindow thisWindow;
|
||||||
|
public MA_TextureAtlasserProSettings settings;
|
||||||
public MA_TextureAtlasserProAtlas textureAtlas;
|
public MA_TextureAtlasserProAtlas textureAtlas;
|
||||||
|
|
||||||
public MA_TextureAtlasserProWorkView workView;
|
public MA_TextureAtlasserProWorkView workView;
|
||||||
@ -56,6 +58,7 @@ namespace MA_TextureAtlasserPro
|
|||||||
GetCurrentWindow();
|
GetCurrentWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
thisWindow.settings = MA_TextureAtlasserProUtils.LoadSettings();
|
||||||
thisWindow.workView = new MA_TextureAtlasserProWorkView(thisWindow, "workView");
|
thisWindow.workView = new MA_TextureAtlasserProWorkView(thisWindow, "workView");
|
||||||
thisWindow.menuView = new MA_TextureAtlasserProMenuView(thisWindow, "menuView");
|
thisWindow.menuView = new MA_TextureAtlasserProMenuView(thisWindow, "menuView");
|
||||||
thisWindow.inspectorView = new MA_TextureAtlasserProInspectorView(thisWindow, "inspectorView");
|
thisWindow.inspectorView = new MA_TextureAtlasserProInspectorView(thisWindow, "inspectorView");
|
||||||
@ -86,7 +89,7 @@ namespace MA_TextureAtlasserPro
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Check views
|
//Check views
|
||||||
if(workView == null || menuView == null || inspectorView == null || debugView == null)
|
if(settings == null || workView == null || menuView == null || inspectorView == null || debugView == null)
|
||||||
{
|
{
|
||||||
CreateViews();
|
CreateViews();
|
||||||
return;
|
return;
|
||||||
@ -116,4 +119,5 @@ namespace MA_TextureAtlasserPro
|
|||||||
isLoaded = true;
|
isLoaded = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
@ -0,0 +1 @@
|
|||||||
|
Export settigns are supposed to be here.
|
@ -0,0 +1,25 @@
|
|||||||
|
%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: 81466035f9fafc64db33b9e6114d774b, 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
|
@ -0,0 +1,25 @@
|
|||||||
|
%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: 81466035f9fafc64db33b9e6114d774b, type: 3}
|
||||||
|
m_Name: MA_DefaultSpriteExportSettings
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
canModify: 0
|
||||||
|
modelExportSettings:
|
||||||
|
modelFormat: 1
|
||||||
|
replaceModel: 0
|
||||||
|
uvFlipY: 1
|
||||||
|
uvChannel: 0
|
||||||
|
uvWrap: 1
|
||||||
|
textureExportSettings:
|
||||||
|
textureFormat: 1
|
||||||
|
textureType: 0
|
||||||
|
textureScaleMode: 0
|
@ -0,0 +1,24 @@
|
|||||||
|
%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: 1
|
||||||
|
modifierKey: 1
|
||||||
|
addQuadHotKey: 113
|
||||||
|
removeQuadHotKey: 114
|
||||||
|
duplicateHotKey: 100
|
||||||
|
zoomInHotKey: 61
|
||||||
|
zoomOutHotKey: 45
|
||||||
|
copySelectedQuadData: 1
|
||||||
|
duplicatedQuadNamePrefix: 'new '
|
||||||
|
autoFocus: 1
|
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
|
//https://github.com/maxartz15/MA_EditorUtils
|
||||||
//Version 1.0
|
|
||||||
|
|
||||||
|
#if UNITY_EDITOR
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@ -58,4 +58,5 @@ namespace MA_Editor.Grid
|
|||||||
Handles.EndGUI();
|
Handles.EndGUI();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
@ -1,6 +1,9 @@
|
|||||||
//Maxartz15
|
//https://github.com/maxartz15/MA_EditorUtils
|
||||||
//Version 1.0
|
|
||||||
|
|
||||||
|
//References:
|
||||||
|
//http://martinecker.com/martincodes/unity-editor-window-zooming/
|
||||||
|
|
||||||
|
#if UNITY_EDITOR
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using MA_Editor;
|
using MA_Editor;
|
||||||
|
|
||||||
@ -67,4 +70,5 @@ namespace MA_Editor.RectUtils
|
|||||||
return multipliedRect;
|
return multipliedRect;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
@ -1,6 +1,9 @@
|
|||||||
//Maxartz15
|
//https://github.com/maxartz15/MA_EditorUtils
|
||||||
//Version 1.0
|
|
||||||
|
|
||||||
|
//References:
|
||||||
|
//http://martinecker.com/martincodes/unity-editor-window-zooming/
|
||||||
|
|
||||||
|
#if UNITY_EDITOR
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using MA_Editor;
|
using MA_Editor;
|
||||||
using MA_Editor.RectUtils;
|
using MA_Editor.RectUtils;
|
||||||
@ -36,4 +39,5 @@ namespace MA_Editor.GUILayoutZoom
|
|||||||
GUI.BeginGroup(new Rect(0.0f, EditorWindowTabHeight, Screen.width, Screen.height));
|
GUI.BeginGroup(new Rect(0.0f, EditorWindowTabHeight, Screen.width, Screen.height));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
@ -1,11 +1,15 @@
|
|||||||
//Maxartz15
|
//https://github.com/maxartz15/MA_MeshUtils
|
||||||
//Version 1.0
|
|
||||||
|
|
||||||
|
//References:
|
||||||
|
//http://wiki.unity3d.com/index.php?title=ObjExporter
|
||||||
|
|
||||||
|
#if UNITY_EDITOR
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
|
|
||||||
@ -35,7 +39,13 @@ namespace MA_Mesh
|
|||||||
|
|
||||||
public static Mesh MA_DuplicateMesh(Mesh mesh)
|
public static Mesh MA_DuplicateMesh(Mesh mesh)
|
||||||
{
|
{
|
||||||
Mesh newMesh = new Mesh();
|
Mesh newMesh = new Mesh
|
||||||
|
{
|
||||||
|
name = mesh.name,
|
||||||
|
bounds = mesh.bounds,
|
||||||
|
colors = mesh.colors,
|
||||||
|
subMeshCount = mesh.subMeshCount
|
||||||
|
};
|
||||||
|
|
||||||
newMesh.SetVertices(new List<Vector3>(mesh.vertices));
|
newMesh.SetVertices(new List<Vector3>(mesh.vertices));
|
||||||
for (int i = 0; i < mesh.subMeshCount; i++)
|
for (int i = 0; i < mesh.subMeshCount; i++)
|
||||||
@ -78,27 +88,41 @@ namespace MA_Mesh
|
|||||||
return mesh;
|
return mesh;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Mesh MA_UVReMap(this Mesh mesh, Vector2 atlasSize, Rect textureRect, int uvChannel = 0, bool flipY = true)
|
public static Mesh MA_UVReMap(this Mesh mesh, Vector2 atlasSize, Rect textureRect, int uvChannel = 0, bool flipY = true, bool wrap = true)
|
||||||
{
|
{
|
||||||
List<Vector2> uvs = new List<Vector2>();
|
|
||||||
|
|
||||||
//Get UV's
|
//Get UV's
|
||||||
|
List<Vector2> uvs = new List<Vector2>();
|
||||||
mesh.GetUVs(uvChannel, uvs);
|
mesh.GetUVs(uvChannel, uvs);
|
||||||
|
|
||||||
|
//Min and max bounds in 0-1 space.
|
||||||
|
float xMin, xMax, yMin, yMax;
|
||||||
|
xMin = (1f / atlasSize.x * textureRect.width);
|
||||||
|
xMax = (1f / atlasSize.x * textureRect.x);
|
||||||
|
yMin = (1f / atlasSize.y * textureRect.height);
|
||||||
|
|
||||||
|
//Flip uv's if needed.
|
||||||
|
if (flipY)
|
||||||
|
{
|
||||||
|
yMax = (1f / atlasSize.y * (atlasSize.y - textureRect.height - textureRect.y));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
yMax = (1f / atlasSize.y * textureRect.y);
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < uvs.Count; i++)
|
for (int i = 0; i < uvs.Count; i++)
|
||||||
{
|
{
|
||||||
if(flipY)
|
float newX = uvs[i].x * xMin + xMax;
|
||||||
|
float newY = uvs[i].y * yMin + yMax;
|
||||||
|
|
||||||
|
//Wrap the verts outside of the uv space around back into the uv space.
|
||||||
|
if (wrap)
|
||||||
{
|
{
|
||||||
Debug.Log("01" + uvs[i].x);
|
newX = Wrap(newX, xMax, xMin + xMax);
|
||||||
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)));
|
newY = Wrap(newY, yMax, yMin + yMax);
|
||||||
Debug.Log("02" + uvs[i].x);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uvs[i] = new Vector2(newX, newY);
|
||||||
}
|
}
|
||||||
|
|
||||||
mesh.SetUVs(uvChannel, uvs);
|
mesh.SetUVs(uvChannel, uvs);
|
||||||
@ -106,6 +130,14 @@ namespace MA_Mesh
|
|||||||
return mesh;
|
return mesh;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static float Wrap(float val, float min, float max)
|
||||||
|
{
|
||||||
|
val -= (float)Math.Round((val - min) / (max - min)) * (max - min);
|
||||||
|
if (val < min)
|
||||||
|
val = val + max - min;
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
//Start http://wiki.unity3d.com/index.php?title=ObjExporter
|
//Start http://wiki.unity3d.com/index.php?title=ObjExporter
|
||||||
public static string MeshToString(Mesh mesh)
|
public static string MeshToString(Mesh mesh)
|
||||||
{
|
{
|
||||||
@ -113,7 +145,6 @@ namespace MA_Mesh
|
|||||||
int normalOffset = 0;
|
int normalOffset = 0;
|
||||||
int uvOffset = 0;
|
int uvOffset = 0;
|
||||||
|
|
||||||
|
|
||||||
Material material = new Material(Shader.Find("Standard"));
|
Material material = new Material(Shader.Find("Standard"));
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
@ -161,9 +192,9 @@ namespace MA_Mesh
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vertexOffset += mesh.vertices.Length;
|
//vertexOffset += mesh.vertices.Length;
|
||||||
normalOffset += mesh.normals.Length;
|
//normalOffset += mesh.normals.Length;
|
||||||
uvOffset += mesh.uv.Length;
|
//uvOffset += mesh.uv.Length;
|
||||||
|
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
@ -173,15 +204,15 @@ namespace MA_Mesh
|
|||||||
using (StreamWriter sw = new StreamWriter(savePath + filename + ".obj"))
|
using (StreamWriter sw = new StreamWriter(savePath + filename + ".obj"))
|
||||||
{
|
{
|
||||||
sw.Write(MeshToString(mesh));
|
sw.Write(MeshToString(mesh));
|
||||||
Debug.Log(savePath + filename);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//End
|
//End
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ObjMaterial
|
//struct ObjMaterial
|
||||||
{
|
//{
|
||||||
public string name;
|
// public string name;
|
||||||
public string textureName;
|
// public string textureName;
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
|
#endif
|
@ -1,27 +1,24 @@
|
|||||||
//Maxartz15
|
//https://github.com/maxartz15/MA_TextureUtils
|
||||||
//Version 1.0
|
|
||||||
//Part of 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-
|
||||||
|
//https://github.com/maxartz15/MA_TextureAtlasser/commit/9f5240967a51692fa2a17a6b3c8d124dd5dc60f9
|
||||||
|
|
||||||
|
#if UNITY_EDITOR
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System;
|
||||||
//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
|
namespace MA_Texture
|
||||||
{
|
{
|
||||||
public static class MA_TextureUtils
|
public static class MA_TextureUtils
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Some base converters and texture settings setters.
|
|
||||||
/// </summary>
|
|
||||||
|
|
||||||
public static Texture ConvertToReadableTexture(Texture texture)
|
public static Texture ConvertToReadableTexture(Texture texture)
|
||||||
{
|
{
|
||||||
if (texture == null)
|
if (texture == null)
|
||||||
@ -49,6 +46,7 @@ namespace MA_Texture
|
|||||||
// Copy the pixels from the RenderTexture to the new Texture
|
// Copy the pixels from the RenderTexture to the new Texture
|
||||||
myTexture2D.ReadPixels(new Rect(0, 0, tmp.width, tmp.height), 0, 0);
|
myTexture2D.ReadPixels(new Rect(0, 0, tmp.width, tmp.height), 0, 0);
|
||||||
myTexture2D.Apply();
|
myTexture2D.Apply();
|
||||||
|
myTexture2D.name = texture.name;
|
||||||
|
|
||||||
// Reset the active RenderTexture
|
// Reset the active RenderTexture
|
||||||
RenderTexture.active = previous;
|
RenderTexture.active = previous;
|
||||||
@ -73,8 +71,6 @@ namespace MA_Texture
|
|||||||
bw.Close();
|
bw.Close();
|
||||||
fs.Close();
|
fs.Close();
|
||||||
|
|
||||||
Debug.Log("Saved texture: " + texture.name);
|
|
||||||
|
|
||||||
AssetDatabase.Refresh();
|
AssetDatabase.Refresh();
|
||||||
|
|
||||||
return texture;
|
return texture;
|
||||||
@ -90,80 +86,110 @@ namespace MA_Texture
|
|||||||
|
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Scale
|
#region Scale
|
||||||
public static Texture2D MA_Scale2D(this Texture2D texture, int newWidth, int newHeight)
|
public enum TextureScaleMode
|
||||||
|
{
|
||||||
|
Bilinear,
|
||||||
|
Point
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Texture MA_Scale(this Texture texture, int width, int height, TextureScaleMode scaleMode)
|
||||||
{
|
{
|
||||||
Texture2D texture2D = new Texture2D(newWidth, newHeight);
|
Texture2D texture2D = (Texture2D)MA_TextureUtils.ConvertToReadableTexture(texture);
|
||||||
float ratioWidth = texture.width / newWidth;
|
|
||||||
float ratioHeight = texture.height / newHeight;
|
|
||||||
|
|
||||||
for (int x = 0; x < texture.width; x++)
|
texture2D.MA_Scale2D(width, height, scaleMode);
|
||||||
{
|
|
||||||
for (int y = 0; y < texture.height; y++)
|
|
||||||
{
|
|
||||||
Color pixel = texture.GetPixel(x, y);
|
|
||||||
int posX = Mathf.FloorToInt(x / ratioWidth);
|
|
||||||
int posY = Mathf.FloorToInt(y / ratioHeight);
|
|
||||||
texture2D.SetPixel(posX, posY, new Color(pixel.r, pixel.g, pixel.b, pixel.a));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
texture2D.Apply();
|
|
||||||
|
|
||||||
return texture2D;
|
texture = texture2D;
|
||||||
}
|
|
||||||
|
|
||||||
public static Texture MA_Scale(this Texture texture, int newWidth, int newHeight)
|
|
||||||
{
|
|
||||||
Texture2D texture2D = (Texture2D)MA_TextureUtils.ConvertToReadableTexture(texture);
|
|
||||||
|
|
||||||
texture2D.MA_Scale2D(newWidth, newHeight);
|
|
||||||
|
|
||||||
texture = texture2D;
|
|
||||||
|
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Texture2D MA_Scale22D(this Texture2D texture, float width, float height)
|
public static Texture2D MA_Scale2D(this Texture2D texture, int newWidth, int newHeight, TextureScaleMode scaleMode)
|
||||||
{
|
{
|
||||||
float ratioWidth = width / texture.width;
|
Color[] curColors = texture.GetPixels();
|
||||||
float ratioHeight = height / texture.height;
|
Color[] newColors = new Color[newWidth * newHeight];
|
||||||
|
|
||||||
int newWidth = Mathf.RoundToInt(texture.width * ratioWidth);
|
switch (scaleMode)
|
||||||
int newHeight = Mathf.RoundToInt(texture.height * ratioHeight);
|
{
|
||||||
|
case TextureScaleMode.Bilinear:
|
||||||
|
newColors = MA_BilinearScale(curColors, texture.width, texture.height, newWidth, newHeight);
|
||||||
|
break;
|
||||||
|
case TextureScaleMode.Point:
|
||||||
|
newColors = MA_PointScale(curColors, texture.width, texture.height, newWidth, newHeight);
|
||||||
|
break;
|
||||||
|
|
||||||
Texture2D newTexture = new Texture2D(newWidth, newHeight);
|
}
|
||||||
|
|
||||||
for (int x = 0; x < texture.width; x++)
|
texture.Resize(newWidth, newHeight);
|
||||||
{
|
texture.SetPixels(newColors);
|
||||||
for (int y = 0; y < texture.height; y++)
|
texture.Apply();
|
||||||
{
|
|
||||||
Color pixel = texture.GetPixel(x, y);
|
|
||||||
int posX = Mathf.RoundToInt(x * ratioWidth);
|
|
||||||
int posY = Mathf.RoundToInt(y * ratioHeight);
|
|
||||||
newTexture.SetPixel(posX, posY, new Color(pixel.r, pixel.g, pixel.b, pixel.a));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
newTexture.name = texture.name;
|
return texture;
|
||||||
|
}
|
||||||
|
|
||||||
newTexture.Apply();
|
private static Color[] MA_BilinearScale(Color[] curColors, int curWidth, int curHeight, int newWidth, int newHeight)
|
||||||
return newTexture;
|
{
|
||||||
}
|
Color[] newColors = new Color[newWidth * newHeight];
|
||||||
|
|
||||||
public static Texture MA_Scale2(this Texture texture, float newWidth, float newHeight)
|
float ratioX = 1.0f / ((float)newWidth / (curWidth - 1));
|
||||||
{
|
float ratioY = 1.0f / ((float)newHeight / (curHeight - 1));
|
||||||
Texture2D texture2D = (Texture2D)MA_TextureUtils.ConvertToReadableTexture(texture);
|
|
||||||
|
|
||||||
texture = texture2D.MA_Scale22D(newWidth, newHeight);
|
for (int y = 0; y < newHeight; y++)
|
||||||
|
{
|
||||||
|
int yFloor = Mathf.FloorToInt(y * ratioY);
|
||||||
|
var y1 = yFloor * curWidth;
|
||||||
|
var y2 = (yFloor + 1) * curWidth;
|
||||||
|
var yw = y * newWidth;
|
||||||
|
|
||||||
return texture;
|
for (int x = 0; x < newWidth; x++)
|
||||||
}
|
{
|
||||||
#endregion
|
int xFloor = Mathf.FloorToInt(x * ratioX);
|
||||||
|
var xLerp = x * ratioX - xFloor;
|
||||||
|
|
||||||
#region combine
|
newColors[yw + x] = ColorLerpUnclamped(ColorLerpUnclamped(curColors[y1 + xFloor], curColors[y1 + xFloor + 1], xLerp),
|
||||||
public static Texture2D MA_Combine2D(this Texture2D texture, Texture2D combineTexture, int offsetX, int offsetY, bool flipY = true)
|
ColorLerpUnclamped(curColors[y2 + xFloor], curColors[y2 + xFloor + 1], xLerp),
|
||||||
|
y * ratioY - yFloor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return newColors;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Color[] MA_PointScale(Color[] curColors, int curWidth, int curHeight, int newWidth, int newHeight)
|
||||||
|
{
|
||||||
|
Color[] newColors = new Color[newWidth * newHeight];
|
||||||
|
|
||||||
|
float ratioX = ((float)curWidth) / newWidth;
|
||||||
|
float ratioY = ((float)curHeight) / newHeight;
|
||||||
|
|
||||||
|
for (int y = 0; y < newHeight; y++)
|
||||||
|
{
|
||||||
|
var thisY = Mathf.RoundToInt((ratioY * y) * curWidth);
|
||||||
|
var yw = y * newWidth;
|
||||||
|
|
||||||
|
for (int x = 0; x < newWidth; x++)
|
||||||
|
{
|
||||||
|
newColors[yw + x] = curColors[Mathf.RoundToInt(thisY + ratioX * x)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return newColors;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Color ColorLerpUnclamped(Color c1, Color c2, float value)
|
||||||
|
{
|
||||||
|
return new Color(c1.r + (c2.r - c1.r) * value,
|
||||||
|
c1.g + (c2.g - c1.g) * value,
|
||||||
|
c1.b + (c2.b - c1.b) * value,
|
||||||
|
c1.a + (c2.a - c1.a) * value);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region combine
|
||||||
|
public static Texture2D MA_Combine2D(this Texture2D texture, Texture2D combineTexture, int offsetX, int offsetY, bool flipY = true)
|
||||||
{
|
{
|
||||||
for (int x = 0; x < combineTexture.width; x++)
|
for (int x = 0; x < combineTexture.width; x++)
|
||||||
{
|
{
|
||||||
@ -172,7 +198,7 @@ namespace MA_Texture
|
|||||||
//Y is 'flipped' because textures are made from left to right, bottom to top. We want to draw from left to right and top to bottom.
|
//Y is 'flipped' because textures are made from left to right, bottom to top. We want to draw from left to right and top to bottom.
|
||||||
for (int y = combineTexture.height; y > 0; y--)
|
for (int y = combineTexture.height; y > 0; y--)
|
||||||
{
|
{
|
||||||
texture.SetPixel(x + offsetX, texture.height - y - offsetY, combineTexture.GetPixel(x, texture.height - y));
|
texture.SetPixel(x + offsetX, y + (texture.height - offsetY - combineTexture.height), combineTexture.GetPixel(x, y));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -192,7 +218,7 @@ namespace MA_Texture
|
|||||||
public static Texture MA_Combine(this Texture texture, Texture combineTexture, int offsetX, int offsetY)
|
public static Texture MA_Combine(this Texture texture, Texture combineTexture, int offsetX, int offsetY)
|
||||||
{
|
{
|
||||||
Texture2D texture2D = (Texture2D)MA_TextureUtils.ConvertToReadableTexture(texture);
|
Texture2D texture2D = (Texture2D)MA_TextureUtils.ConvertToReadableTexture(texture);
|
||||||
Texture2D combineTexture2D = (Texture2D)MA_TextureUtils.ConvertToReadableTexture(texture);
|
Texture2D combineTexture2D = (Texture2D)MA_TextureUtils.ConvertToReadableTexture(combineTexture);
|
||||||
|
|
||||||
texture = texture2D.MA_Combine2D(combineTexture2D, offsetX, offsetY);
|
texture = texture2D.MA_Combine2D(combineTexture2D, offsetX, offsetY);
|
||||||
|
|
||||||
@ -200,4 +226,5 @@ namespace MA_Texture
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
18
README.md
18
README.md
@ -1,9 +1,21 @@
|
|||||||
# MA_TextureAtlasser
|
# MA_TextureAtlasser
|
||||||
Texture atlas creator for Unity
|
Texture atlas creator for Unity
|
||||||
|
|
||||||
|
[]()
|
||||||
|
|
||||||
You can combine textures and/or remap the UV’s for the 3D models.
|
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.
|
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.
|
||||||
|
|
||||||
https://youtu.be/PBRKlopkZP0
|
- 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.
|
||||||
|
|
||||||
For more information: https://maxartz15.com/ma_textureatlas/
|
[Example video](https://youtu.be/PBRKlopkZP0)
|
||||||
|
|
||||||
|
Download the UnityPackage here: https://github.com/maxartz15/MA_TextureAtlasser/releases
|
||||||
|
|
||||||
|
[]()
|
||||||
|
|
||||||
|
For more information: https://maxartz15.com/ma-textureatlasser/
|
Reference in New Issue
Block a user