Compare commits

..

No commits in common. "master" and "1.8.0" have entirely different histories.

4 changed files with 139 additions and 154 deletions

View File

@ -8,182 +8,173 @@ using MA_Toolbox.Utils;
namespace MA_TextureAtlasserPro namespace MA_TextureAtlasserPro
{ {
public class MA_TextureAtlasserProInspectorView : MA_TextureAtlasserProViewBase public class MA_TextureAtlasserProInspectorView : MA_TextureAtlasserProViewBase
{ {
private MA_TextureAtlasserProQuad lastSelectedQuad; private MA_TextureAtlasserProQuad lastSelectedQuad;
private bool isEditing = false; private bool isEditing = false;
private GUIStyle labelStyle = new GUIStyle(GUI.skin.label); private GUIStyle labelStyle = new GUIStyle(GUI.skin.label);
private Vector2 scrollPos = Vector2.zero;
public MA_TextureAtlasserProInspectorView(MA_TextureAtlasserProWindow currentEditorWindow, string title) : base(currentEditorWindow, title)
{
} public MA_TextureAtlasserProInspectorView(MA_TextureAtlasserProWindow currentEditorWindow, string title) : base(currentEditorWindow, title)
{
public override void UpdateView(Event e, Rect editorViewRect) }
{
//Update base derived class
base.UpdateView(e, editorViewRect);
if (isLoaded) public override void UpdateView(Event e, Rect editorViewRect)
{ {
//Draw inspector //Update base derived class
if (curWindow.textureAtlas != null && curWindow.textureAtlas.selectedTextureQuad != null) base.UpdateView(e, editorViewRect);
{
//Deselect GUI elements when we are focusing on a new quad
if (lastSelectedQuad != curWindow.textureAtlas.selectedTextureQuad)
{
lastSelectedQuad = curWindow.textureAtlas.selectedTextureQuad;
GUI.FocusControl(null);
}
GUILayout.BeginArea(editorViewRect, EditorStyles.helpBox); if (isLoaded)
using (var scrollViewScope = new EditorGUILayout.ScrollViewScope(scrollPos, false, false)) {
{ //Draw inspector
scrollPos = scrollViewScope.scrollPosition; if (curWindow.textureAtlas != null && curWindow.textureAtlas.selectedTextureQuad != null)
{
//Deselect GUI elements when we are focusing on a new quad
if (lastSelectedQuad != curWindow.textureAtlas.selectedTextureQuad)
{
lastSelectedQuad = curWindow.textureAtlas.selectedTextureQuad;
GUI.FocusControl(null);
}
GUILayout.BeginVertical(GUILayout.ExpandWidth(true)); GUILayout.BeginArea(editorViewRect, EditorStyles.helpBox);
GUILayout.BeginVertical(GUILayout.ExpandWidth(true));
GUILayout.Label("Quad Name"); GUILayout.Label("Quad Name");
curWindow.textureAtlas.selectedTextureQuad.name = EditorGUILayout.TextField(curWindow.textureAtlas.selectedTextureQuad.name); curWindow.textureAtlas.selectedTextureQuad.name = EditorGUILayout.TextField(curWindow.textureAtlas.selectedTextureQuad.name);
GUILayout.Space(MA_TextureAtlasserProUtils.VIEW_OFFSET / 2); GUILayout.Space(MA_TextureAtlasserProUtils.VIEW_OFFSET / 2);
//Textures //Textures
GUILayout.BeginHorizontal(); GUILayout.BeginHorizontal();
GUILayout.Label("Textures", GUILayout.ExpandWidth(true)); GUILayout.Label("Textures", GUILayout.ExpandWidth(true));
if (GUILayout.Button(MA_TextureAtlasserProGuiLoader.editGC, EditorStyles.miniButton, GUILayout.Width(36), GUILayout.Height(15))) if (GUILayout.Button(MA_TextureAtlasserProGuiLoader.editGC, EditorStyles.miniButton, GUILayout.Width(36), GUILayout.Height(15)))
{ {
isEditing = !isEditing; isEditing = !isEditing;
} }
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
if (curWindow.textureAtlas.textureGroupRegistration == null || curWindow.textureAtlas.textureGroupRegistration.Count == 0) if (curWindow.textureAtlas.textureGroupRegistration == null || curWindow.textureAtlas.textureGroupRegistration.Count == 0)
{ {
if (GUILayout.Button("+", EditorStyles.miniButton, GUILayout.ExpandWidth(true))) if (GUILayout.Button("+", EditorStyles.miniButton, GUILayout.ExpandWidth(true)))
{ {
MA_TextureAtlasserProUtils.CreateTextureGroup(curWindow.textureAtlas, "New TextureGroup"); MA_TextureAtlasserProUtils.CreateTextureGroup(curWindow.textureAtlas, "New TextureGroup");
} }
} }
for (int i = 0; i < curWindow.textureAtlas.textureGroupRegistration.Count; i++) for (int i = 0; i < curWindow.textureAtlas.textureGroupRegistration.Count; i++)
{ {
if (isEditing) if (isEditing)
{ {
curWindow.textureAtlas.textureGroupRegistration[i].name = curWindow.textureAtlas.selectedTextureQuad.textureGroups[i].name = EditorGUILayout.TextField(curWindow.textureAtlas.textureGroupRegistration[i].name); curWindow.textureAtlas.textureGroupRegistration[i].name = curWindow.textureAtlas.selectedTextureQuad.textureGroups[i].name = EditorGUILayout.TextField(curWindow.textureAtlas.textureGroupRegistration[i].name);
} }
else else
{ {
GUILayout.Label(curWindow.textureAtlas.textureGroupRegistration[i].name); GUILayout.Label(curWindow.textureAtlas.textureGroupRegistration[i].name);
} }
GUILayout.BeginHorizontal(); GUILayout.BeginHorizontal();
curWindow.textureAtlas.selectedTextureQuad.textureGroups[i].texture = (Texture)EditorGUILayout.ObjectField(curWindow.textureAtlas.selectedTextureQuad.textureGroups[i].texture, typeof(Texture), false); curWindow.textureAtlas.selectedTextureQuad.textureGroups[i].texture = (Texture)EditorGUILayout.ObjectField(curWindow.textureAtlas.selectedTextureQuad.textureGroups[i].texture, typeof(Texture), false);
if (isEditing && GUILayout.Button("-", EditorStyles.miniButtonLeft, GUILayout.ExpandWidth(false))) if (isEditing && GUILayout.Button("-", EditorStyles.miniButtonLeft, GUILayout.ExpandWidth(false)))
{ {
MA_TextureAtlasserProUtils.RemoveTextureGroup(curWindow.textureAtlas, i); MA_TextureAtlasserProUtils.RemoveTextureGroup(curWindow.textureAtlas, i);
} }
if (isEditing && GUILayout.Button("+", EditorStyles.miniButtonRight, GUILayout.ExpandWidth(false))) if (isEditing && GUILayout.Button("+", EditorStyles.miniButtonRight, GUILayout.ExpandWidth(false)))
{ {
MA_TextureAtlasserProUtils.CreateTextureGroup(curWindow.textureAtlas, "New TextureGroup"); MA_TextureAtlasserProUtils.CreateTextureGroup(curWindow.textureAtlas, "New TextureGroup");
} }
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
} }
GUILayout.Space(MA_TextureAtlasserProUtils.VIEW_OFFSET / 2); GUILayout.Space(MA_TextureAtlasserProUtils.VIEW_OFFSET / 2);
//Models //Models
GUILayout.Label("Models"); GUILayout.Label("Models");
SerializedObject serializedObject = new SerializedObject(curWindow.textureAtlas.selectedTextureQuad); SerializedObject serializedObject = new SerializedObject(curWindow.textureAtlas.selectedTextureQuad);
serializedObject.Update(); serializedObject.Update();
if (curWindow.textureAtlas.selectedTextureQuad.modelGroups != null)
{
SerializedProperty modelGroupsSP = serializedObject.FindProperty("modelGroups");
if (curWindow.textureAtlas.selectedTextureQuad.modelGroups != null) for (int i = 0; i < curWindow.textureAtlas.selectedTextureQuad.modelGroups.Count; i++)
{ {
SerializedProperty modelGroupsSP = serializedObject.FindProperty("modelGroups"); using (new GUILayout.VerticalScope(EditorStyles.helpBox))
{
for (int i = 0; i < curWindow.textureAtlas.selectedTextureQuad.modelGroups.Count; i++) using (new GUILayout.HorizontalScope())
{
using (new GUILayout.VerticalScope(EditorStyles.helpBox))
{ {
using (new GUILayout.HorizontalScope()) curWindow.textureAtlas.selectedTextureQuad.modelGroups[i].name = EditorGUILayout.TextField(curWindow.textureAtlas.selectedTextureQuad.modelGroups[i].name);
if (GUILayout.Button("-", EditorStyles.miniButton, GUILayout.ExpandWidth(true)))
{ {
curWindow.textureAtlas.selectedTextureQuad.modelGroups[i].name = EditorGUILayout.TextField(curWindow.textureAtlas.selectedTextureQuad.modelGroups[i].name); curWindow.textureAtlas.selectedTextureQuad.modelGroups.RemoveAt(i);
if (GUILayout.Button("-", EditorStyles.miniButton, GUILayout.ExpandWidth(true))) break;
{
curWindow.textureAtlas.selectedTextureQuad.modelGroups.RemoveAt(i);
break;
}
} }
}
SerializedProperty meshesSP = modelGroupsSP.GetArrayElementAtIndex(i).FindPropertyRelative("meshes"); SerializedProperty meshesSP = modelGroupsSP.GetArrayElementAtIndex(i).FindPropertyRelative("meshes");
#if UNITY_2020_2_OR_NEWER EditorGUILayout.PropertyField(meshesSP, false, GUILayout.ExpandWidth(false), GUILayout.MaxWidth(editorViewRect.width * 0.5f));
meshesSP.isExpanded = EditorGUILayout.Foldout(meshesSP.isExpanded, "Meshes", true);
#else if (meshesSP.isExpanded)
EditorGUILayout.PropertyField(meshesSP, false, GUILayout.ExpandWidth(false), GUILayout.MaxWidth(editorViewRect.width * 0.5f)); {
#endif for (int j = 0; j < curWindow.textureAtlas.selectedTextureQuad.modelGroups[i].meshes.Count; j++)
if (meshesSP.isExpanded)
{ {
for (int j = 0; j < curWindow.textureAtlas.selectedTextureQuad.modelGroups[i].meshes.Count; j++) using (new GUILayout.HorizontalScope())
{ {
using (new GUILayout.HorizontalScope()) curWindow.textureAtlas.selectedTextureQuad.modelGroups[i].meshes[j] = (Mesh)EditorGUILayout.ObjectField(curWindow.textureAtlas.selectedTextureQuad.modelGroups[i].meshes[j], typeof(Mesh), false);
if (GUILayout.Button("-", EditorStyles.miniButton, GUILayout.ExpandWidth(true)))
{ {
curWindow.textureAtlas.selectedTextureQuad.modelGroups[i].meshes[j] = (Mesh)EditorGUILayout.ObjectField(curWindow.textureAtlas.selectedTextureQuad.modelGroups[i].meshes[j], typeof(Mesh), false); curWindow.textureAtlas.selectedTextureQuad.modelGroups[i].meshes.RemoveAt(j);
if (GUILayout.Button("-", EditorStyles.miniButton, GUILayout.ExpandWidth(true))) break;
{
curWindow.textureAtlas.selectedTextureQuad.modelGroups[i].meshes.RemoveAt(j);
break;
}
} }
} }
} }
}
if (GUILayout.Button("+", EditorStyles.miniButton)) if (GUILayout.Button("+", EditorStyles.miniButton))
{ {
curWindow.textureAtlas.selectedTextureQuad.modelGroups[i].meshes.Add(null); curWindow.textureAtlas.selectedTextureQuad.modelGroups[i].meshes.Add(null);
}
} }
} }
if (GUILayout.Button("+", EditorStyles.miniButton, GUILayout.ExpandWidth(true)))
{
curWindow.textureAtlas.selectedTextureQuad.modelGroups.Add(new MA_ModelGroup() { name = MA_StringUtils.RandomAlphabetString(6) });
}
} }
else
if (GUILayout.Button("+", EditorStyles.miniButton, GUILayout.ExpandWidth(true)))
{ {
curWindow.textureAtlas.selectedTextureQuad.modelGroups = new List<MA_ModelGroup>(); curWindow.textureAtlas.selectedTextureQuad.modelGroups.Add(new MA_ModelGroup() { name = MA_StringUtils.RandomAlphabetString(6) });
} }
serializedObject.ApplyModifiedProperties();
GUILayout.Space(MA_TextureAtlasserProUtils.VIEW_OFFSET / 2);
//x, y, w, h.
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 = GUI.skin.label.normal.textColor;
}
GUILayout.Label("x " + curWindow.textureAtlas.selectedTextureQuad.guiRect.x.ToString() + ", y " + curWindow.textureAtlas.selectedTextureQuad.guiRect.y.ToString());
GUILayout.Label("w " + curWindow.textureAtlas.selectedTextureQuad.guiRect.width.ToString() + ", h " + curWindow.textureAtlas.selectedTextureQuad.guiRect.height.ToString(), labelStyle);
} }
GUILayout.EndVertical(); else
GUILayout.EndArea(); {
} curWindow.textureAtlas.selectedTextureQuad.modelGroups = new List<MA_ModelGroup>();
} }
if (curWindow.textureAtlas != null && curWindow.textureAtlas.selectedTextureQuad != null) serializedObject.ApplyModifiedProperties();
ProcessEvents(e, editorViewRect);
}
protected override void ProcessEvents(Event e, Rect editorViewRect) GUILayout.Space(MA_TextureAtlasserProUtils.VIEW_OFFSET / 2);
{
base.ProcessEvents(e, editorViewRect); //x, y, w, h.
} 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 = GUI.skin.label.normal.textColor;
}
GUILayout.Label("x " + curWindow.textureAtlas.selectedTextureQuad.guiRect.x.ToString() + ", y " + curWindow.textureAtlas.selectedTextureQuad.guiRect.y.ToString());
GUILayout.Label("w " + curWindow.textureAtlas.selectedTextureQuad.guiRect.width.ToString() + ", h " + curWindow.textureAtlas.selectedTextureQuad.guiRect.height.ToString(), labelStyle);
GUILayout.EndVertical();
GUILayout.EndArea();
}
}
if (curWindow.textureAtlas != null && curWindow.textureAtlas.selectedTextureQuad != null)
ProcessEvents(e, editorViewRect);
}
protected override void ProcessEvents(Event e, Rect editorViewRect)
{
base.ProcessEvents(e, editorViewRect);
}
}
} }
#endif #endif

View File

@ -84,12 +84,7 @@ namespace MA_Mesh
newMesh.SetTriangles(mesh.GetTriangles(i), i); newMesh.SetTriangles(mesh.GetTriangles(i), i);
} }
newMesh.SetNormals(new List<Vector3>(mesh.normals)); newMesh.SetNormals(new List<Vector3>(mesh.normals));
for (int i = 0; i < 8; i++) newMesh.SetUVs(0, new List<Vector2>(mesh.uv));
{
List<Vector2> uvs = new List<Vector2>();
mesh.GetUVs(i, uvs);
newMesh.SetUVs(i, uvs);
}
newMesh.SetTangents(new List<Vector4>(mesh.tangents)); newMesh.SetTangents(new List<Vector4>(mesh.tangents));
newMesh.SetColors(new List<Color>(mesh.colors)); newMesh.SetColors(new List<Color>(mesh.colors));

View File

@ -199,7 +199,7 @@ namespace MA_Texture
if(flipY) if(flipY)
{ {
//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 - 1; y >= 0; y--) for (int y = combineTexture.height; y > 0; y--)
{ {
texture.SetPixel(x + offsetX, y + (texture.height - offsetY - combineTexture.height), combineTexture.GetPixel(x, y)); texture.SetPixel(x + offsetX, y + (texture.height - offsetY - combineTexture.height), combineTexture.GetPixel(x, y));
} }

View File

@ -11,7 +11,6 @@ Texture atlas creator tool for Unity. <br> This tool is made to combine textures
### Unity versions ### Unity versions
- Latest release requires Unity 2018.3 or higher. - Latest release requires Unity 2018.3 or higher.
- Releases before 1.8 should work with older Unity versions. - Releases before 1.8 should work with older Unity versions.
- Upgrading to 1.8+ will break existing atlasses.
## Export options ## Export options
### Meshes ### Meshes
@ -24,4 +23,4 @@ Texture atlas creator tool for Unity. <br> This tool is made to combine textures
## Resources ## Resources
[Youtube video](https://youtu.be/PBRKlopkZP0) <br> [Youtube video](https://youtu.be/PBRKlopkZP0) <br>
[Website](https://maxartz15.com/ma_textureatlas/) [Website](https://maxartz15.com/ma-textureatlasser/)