Skip to content

Commit

Permalink
Fixed importing.
Browse files Browse the repository at this point in the history
  • Loading branch information
goto01 committed Jul 23, 2019
1 parent 9d53f74 commit 68b3dda
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,30 @@

namespace MA_TextureAtlasserPro
{
public class MA_TextureAtlasserProExportWindow : EditorWindow
public class MA_TextureAtlasserProExportWindow : EditorWindow
{
private const int WindowHeight = 215;

private enum ExportMode
{
None,
D3,
D2,
Meshes,
}

//Editor
private static MA_TextureAtlasserProExportWindow thisWindow;
public static MA_TextureAtlasserProWindow curWindow;

//Data
private static bool isLoaded = false; //Make sure we wait a frame at the start to setup and don't draw.

private ExportMode _selectedExportMode;
private bool _showAdvancedEditor;

private bool exportObjDefault = false;
private bool _replaceMeshes = false;
private bool exportPngDefault = false;
private bool exportSprite = false;
private bool exportSliceSprite = false;
Expand All @@ -26,8 +40,8 @@ private static void Init()
{
GetCurrentWindow();

thisWindow.minSize = new Vector2(420, 200);
thisWindow.maxSize = new Vector2(420, 200);
thisWindow.minSize = new Vector2(420, WindowHeight);
thisWindow.maxSize = new Vector2(420, WindowHeight);

thisWindow.titleContent.text = "MA_ExportTextureAtlas";

Expand All @@ -40,8 +54,8 @@ public static void InitEditorWindow(MA_TextureAtlasserProWindow currentEditorWin

GetCurrentWindow();

thisWindow.minSize = new Vector2(420, 200);
thisWindow.maxSize = new Vector2(420, 200);
thisWindow.minSize = new Vector2(420, WindowHeight);
thisWindow.maxSize = new Vector2(420, WindowHeight);

thisWindow.titleContent.text = "MA_ExportTextureAtlas";

Expand Down Expand Up @@ -101,52 +115,25 @@ private void OnGUI()
{
//Export
GUILayout.BeginVertical();
GUILayout.BeginHorizontal(EditorStyles.helpBox);

if (GUILayout.Button("3D", GUILayout.ExpandWidth(false)))
{
exportObjDefault = true;
exportPngDefault = true;
exportSprite = false;
exportSliceSprite = false;
}

if (GUILayout.Button("2D", GUILayout.ExpandWidth(false)))
{
exportObjDefault = false;
exportPngDefault = true;
exportSprite = true;
exportSliceSprite = true;
}

GUILayout.EndHorizontal();

GUILayout.Label("Meshes:");
exportObjDefault = GUILayout.Toggle(exportObjDefault, "OBJ default.");

GUILayout.Label("Textures:");
GUILayout.BeginHorizontal();
exportPngDefault = GUILayout.Toggle(exportPngDefault, "PNG default.");
if(exportPngDefault)
{
exportSprite = GUILayout.Toggle(exportSprite, "Sprite.");
if (exportSprite)
{
exportSliceSprite = GUILayout.Toggle(exportSliceSprite, "Slice sprites.");
}
}
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
DrawExportModeEditor();
DrawAdvancedEditor();

GUILayout.BeginHorizontal(EditorStyles.helpBox);

GUI.enabled = _selectedExportMode != ExportMode.None;
if (GUILayout.Button("Export", GUILayout.ExpandWidth(true), GUILayout.Height(37)))
{
if(exportObjDefault)
{
MA_TextureAtlasserProUtils.ExportAtlasMeshesObj(curWindow.textureAtlas);
}

if (_replaceMeshes)
{

}

if(exportPngDefault)
{
if(exportSprite)
Expand All @@ -160,6 +147,8 @@ private void OnGUI()
}
}

GUI.enabled = true;

GUILayout.EndHorizontal();
GUILayout.EndVertical();
}
Expand Down Expand Up @@ -187,6 +176,79 @@ private void OnGUI()
if(e.type == EventType.Repaint)
isLoaded = true;
}

private void DrawExportModeEditor()
{
GUILayout.BeginHorizontal(EditorStyles.helpBox);
GUILayout.FlexibleSpace();
var value = GUILayout.Toggle(_selectedExportMode == ExportMode.D3, "3D", EditorStyles.miniButtonLeft,
GUILayout.ExpandWidth(false));
if (value && _selectedExportMode != ExportMode.D3)
{
_selectedExportMode = ExportMode.D3;
exportObjDefault = true;
_replaceMeshes = false;
exportPngDefault = true;
exportSprite = false;
exportSliceSprite = false;
}
value = GUILayout.Toggle(_selectedExportMode == ExportMode.D2, "2D", EditorStyles.miniButtonMid,
GUILayout.ExpandWidth(false));
if (value && _selectedExportMode != ExportMode.D2)
{
_selectedExportMode = ExportMode.D2;
exportObjDefault = false;
_replaceMeshes = false;
exportPngDefault = true;
exportSprite = true;
exportSliceSprite = true;
}
value = GUILayout.Toggle(_selectedExportMode == ExportMode.Meshes, "Replace source meshes", EditorStyles.miniButtonRight,
GUILayout.ExpandWidth(false));
if (value && _selectedExportMode != ExportMode.Meshes)
{
_selectedExportMode = ExportMode.Meshes;
exportObjDefault = false;
_replaceMeshes = true;
exportPngDefault = true;
exportSprite = false;
exportSliceSprite = false;
}
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
}

private void DrawAdvancedEditor()
{
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
_showAdvancedEditor = EditorGUILayout.Foldout(_showAdvancedEditor, "Advanced editor");
if (!_showAdvancedEditor)
{
EditorGUILayout.EndVertical();
return;
}

GUILayout.Label("Meshes:", EditorStyles.miniBoldLabel);
EditorGUILayout.BeginHorizontal();
exportObjDefault = GUILayout.Toggle(exportObjDefault, "OBJ default.");
_replaceMeshes = GUILayout.Toggle(_replaceMeshes, "Replace meshes");
EditorGUILayout.EndHorizontal();

GUILayout.Label("Textures:", EditorStyles.miniBoldLabel);
GUILayout.BeginHorizontal();
exportPngDefault = GUILayout.Toggle(exportPngDefault, "PNG default.");
if(exportPngDefault)
{
exportSprite = GUILayout.Toggle(exportSprite, "Sprite.");
if (exportSprite)
{
exportSliceSprite = GUILayout.Toggle(exportSliceSprite, "Slice sprites.");
}
}
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
EditorGUILayout.EndVertical();
}
}
}
#endif
9 changes: 4 additions & 5 deletions MA_ToolBox/MA_Utilities/MeshUtils/MA_MeshUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ public static Mesh MA_UVReMap(this Mesh mesh, Vector2 atlasSize, Rect textureRec
{
if(flipY)
{
//Debug.Log("01" + uvs[i].x);
uvs[i] = new Vector2((uvs[i].x / atlasSize.x * textureRect.width) + (1 / atlasSize.x * textureRect.x), (uvs[i].y / atlasSize.y * textureRect.height) + (1 / atlasSize.y * (atlasSize.y - textureRect.height - textureRect.y)));
//Debug.Log("02" + uvs[i].x);
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)));
}
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));
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);
}
}
Expand Down Expand Up @@ -181,7 +181,6 @@ public static void MeshToFile(Mesh mesh, string filename, string savePath)
using (StreamWriter sw = new StreamWriter(savePath + filename + ".obj"))
{
sw.Write(MeshToString(mesh));
Debug.Log(savePath + filename);
}
}
//End
Expand Down
2 changes: 1 addition & 1 deletion MA_ToolBox/MA_Utilities/TextureUtils/MA_TextureUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public static Texture2D MA_Combine2D(this Texture2D texture, Texture2D combineTe
//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--)
{
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
Expand Down

0 comments on commit 68b3dda

Please sign in to comment.