1.0, gitignore

This commit is contained in:
max
2018-08-27 11:55:21 +02:00
parent 88e5537d9b
commit 13b1344a23
30 changed files with 2092 additions and 0 deletions

View File

@ -0,0 +1 @@
The created atlasses wil go here.

View File

@ -0,0 +1 @@
The exported assets will be saved in this folder.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1006 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 278 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 301 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1006 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 878 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 204 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 846 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -0,0 +1,103 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using MA_Editor;
using MA_Editor.Grid;
namespace MA_TextureAtlasserPro
{
[System.Serializable]
public class MA_TextureAtlasserProAtlas : ScriptableObject
{
//Editor
public List<MA_TextureAtlasserProQuad> textureQuads;
public MA_TextureAtlasserProQuad selectedTextureQuad;
private Rect editorWorkRect;
public bool showTextures = false;
//Data
public Vector2 textureAtlasSize;
public List<MA_TextureGroupRegistration> textureGroupRegistration;
public void CreateAtlas(string name, Vector2 size)
{
this.name = name;
textureAtlasSize = size;
}
public void UpdateTextureQuads(Event e, Rect editorViewRect, Vector2 zoomCoordsOrigin, bool useEvents)
{
textureAtlasSize.x = Mathf.Clamp(textureAtlasSize.x, 128, 8192);
textureAtlasSize.y = Mathf.Clamp(textureAtlasSize.y, 128, 8192);
editorWorkRect = new Rect(Vector2.zero - zoomCoordsOrigin, textureAtlasSize);
GUI.backgroundColor = new Color(0, 0, 0, 0.1f);
GUI.Box(editorWorkRect, this.name);
GUI.backgroundColor = Color.white;
MA_Editor.Grid.Grid.DrawZoomableGrid(editorWorkRect, 64, new Color(0, 0, 0, 0.1f), zoomCoordsOrigin);
if(textureQuads != null)
{
foreach (MA_TextureAtlasserProQuad ts in textureQuads)
{
ts.UpdateTextureQuad(e, editorViewRect, editorWorkRect, zoomCoordsOrigin, useEvents, showTextures);
}
}
if(useEvents)
ProcessEvents(e, zoomCoordsOrigin, useEvents);
EditorUtility.SetDirty(this);
}
private void ProcessEvents(Event e, Vector2 zoomCoordsOrigin, bool useEvents)
{
if(e.button == 0)
{
if(e.type == EventType.MouseDown)
{
DeselectQuad();
if(textureQuads != null)
{
foreach(MA_TextureAtlasserProQuad quad in textureQuads)
{
if(new Rect((int)quad.guiRect.x - zoomCoordsOrigin.x, (int)quad.guiRect.y - zoomCoordsOrigin.y, quad.guiRect.width, quad.guiRect.height).Contains(e.mousePosition))
{
SelectQuad(quad);
e.Use();
}
}
}
}
}
}
private void SelectQuad(MA_TextureAtlasserProQuad quad)
{
if(selectedTextureQuad)
{
DeselectQuad();
}
quad.isSelected = true;
selectedTextureQuad = quad;
}
private void DeselectQuad()
{
if(textureQuads != null)
{
foreach(MA_TextureAtlasserProQuad quad in textureQuads)
{
quad.isSelected = false;
}
selectedTextureQuad = null;
}
}
}
}

View File

@ -0,0 +1,166 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using MA_Editor;
namespace MA_TextureAtlasserPro
{
[System.Serializable]
public class MA_TextureAtlasserProQuad : ScriptableObject
{
//Editor
public bool isSelected = false; //Is this thing selected
public Rect rect; //The internal rect
public Rect guiRect; //The visual clamped and snapped rect
public bool debugMode = false; //Are we debugging, for showing some other things (like handles)
private bool isDragging = false; //Are we editing the pos or size
private bool isDraggingRectHeigt = false;
public Rect dragRectHeight;
private bool isDraggingRectWidth = false;
public Rect dragRectWidth;
private bool isDraggingRectPos = false;
public Rect dragRectPos;
//Data
public Texture texture; //Replace this with texture groups
public List<MA_TextureGroup> textureGroups;
public List<Mesh> meshes;
public void UpdateTextureQuad(Event e, Rect editorViewRect, Rect editorWorkRect, Vector2 zoomCoordsOrigin, bool useEvents, bool showTexture)
{
if(isSelected)
{
GUI.backgroundColor = new Color(0.05f, 0.05f, 0.05f, 0.75f);
}
else
{
GUI.backgroundColor = new Color(1, 1, 1, 0.5f);
}
//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);
//Draw the sqaud background
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);
else
GUI.Box(new Rect(guiRect.x - zoomCoordsOrigin.x, guiRect.y - zoomCoordsOrigin.y, guiRect.width, guiRect.height), "");
GUILayout.BeginArea(new Rect(guiRect.x - zoomCoordsOrigin.x, guiRect.y - zoomCoordsOrigin.y, guiRect.width, guiRect.height));
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
GUILayout.Label(this.name);
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
if(isSelected)
{
dragRectPos = new Rect(guiRect.width / 2 + guiRect.x - zoomCoordsOrigin.x - 16, guiRect.height / 2 + guiRect.y - zoomCoordsOrigin.y - 16, 32, 32);
dragRectWidth = new Rect(guiRect.width + guiRect.x - zoomCoordsOrigin.x - 16, guiRect.height / 2 + guiRect.y - zoomCoordsOrigin.y - 32, 16, 64);
dragRectHeight = new Rect(guiRect.width / 2 + guiRect.x - zoomCoordsOrigin.x - 32, guiRect.height + guiRect.y - zoomCoordsOrigin.y - 16, 64, 16);
if(debugMode)
{
GUI.Box(new Rect(dragRectPos.x - guiRect.x + zoomCoordsOrigin.x, dragRectPos.y - guiRect.y + zoomCoordsOrigin.y, dragRectPos.width, dragRectPos.height), "");
GUI.Box(new Rect(dragRectWidth.x - guiRect.x + zoomCoordsOrigin.x, dragRectWidth.y - guiRect.y + zoomCoordsOrigin.y, dragRectWidth.width, dragRectWidth.height), "");
GUI.Box(new Rect(dragRectHeight.x - guiRect.x + zoomCoordsOrigin.x, dragRectHeight.y - guiRect.y + zoomCoordsOrigin.y, dragRectHeight.width, dragRectHeight.height), "");
}
}
else
{
}
GUI.backgroundColor = Color.white;
GUILayout.EndArea();
if(useEvents)
ProcessEvents(e, editorViewRect, editorWorkRect, zoomCoordsOrigin);
EditorUtility.SetDirty(this);
}
void ProcessEvents(Event e, Rect editorViewRect, Rect editorWorkRect, Vector2 zoomCoordsOrigin)
{
if(isSelected)
{
//Right mouse
if(e.button == 0)
{
//Mouse drag
if(e.type == EventType.MouseDrag)
{
if(dragRectPos.Contains(e.mousePosition) && isDragging == false)
{
//Debug.Log("P");
isDragging = true;
isDraggingRectPos = true;
}
if(dragRectWidth.Contains(e.mousePosition) && isDragging == false)
{
//Debug.Log("W");
isDragging = true;
isDraggingRectWidth = true;
}
if(dragRectHeight.Contains(e.mousePosition) && isDragging == false)
{
//Debug.Log("W");
isDragging = true;
isDraggingRectHeigt = true;
}
if(isDraggingRectPos)
{
rect.x += e.delta.x;
rect.y += e.delta.y;
}
if(isDraggingRectWidth)
{
rect.width += e.delta.x;
}
if(isDraggingRectHeigt)
{
rect.height += e.delta.y;
}
//Clamp rect with min/max values to stay inside the workrect
rect.width = Mathf.Clamp(rect.width, 64, editorWorkRect.width);
rect.height = Mathf.Clamp(rect.height, 64, editorWorkRect.height);
rect.x = Mathf.Clamp(rect.x, 0, editorWorkRect.width - rect.width);
rect.y = Mathf.Clamp(rect.y, 0, editorWorkRect.height - rect.height);
if(isDragging)
e.Use();
}
}
//Deselect on mouse up
if(e.type == EventType.MouseUp)
{
StopDragging();
}
}
//Stop if we are not selected
else if(!isSelected && isDragging)
{
StopDragging();
}
}
private void StopDragging()
{
//Debug.Log("StopDragging");
isDragging = false;
isDraggingRectPos = false;
isDraggingRectWidth = false;
isDraggingRectHeigt = false;
}
public void SetDebugMode(bool isDebugging)
{
debugMode = isDebugging;
}
}
}

View File

@ -0,0 +1,19 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace MA_TextureAtlasserPro
{
[System.Serializable]
public class MA_TextureGroup
{
public string name;
public Texture texture = null;
}
[System.Serializable]
public class MA_TextureGroupRegistration
{
public string name;
}
}

View File

@ -0,0 +1,33 @@
using UnityEngine;
using UnityEditor;
namespace MA_TextureAtlasserPro
{
public static class MA_TextureAtlasserProIcons
{
private const string LOADICONPATH = "Assets/MA_ToolBox/MA_TextureAtlasserPro/Icons/";
public static GUIContent createAtlasIcon;
public static GUIContent loadAtlasIcon;
public static GUIContent exportAtlasIcon;
public static GUIContent createQuadIcon;
public static GUIContent removeQuadIcon;
public static GUIContent showTexturesOnIcon;
public static GUIContent showTexturesOffIcon;
public static GUIContent dragHandleIcon;
public static GUIContent editIcon;
public static void LoadIcons()
{
createAtlasIcon = new GUIContent("", (Texture)EditorGUIUtility.Load(LOADICONPATH + "createAtlasIcon" + ".png"));
loadAtlasIcon = new GUIContent("", (Texture)EditorGUIUtility.Load(LOADICONPATH + "loadAtlasIcon" + ".png"));
exportAtlasIcon = new GUIContent("", (Texture)EditorGUIUtility.Load(LOADICONPATH + "exportAtlasIcon" + ".png"));
createQuadIcon = new GUIContent("", (Texture)EditorGUIUtility.Load(LOADICONPATH + "createQuadIcon" + ".png"));
removeQuadIcon = new GUIContent("", (Texture)EditorGUIUtility.Load(LOADICONPATH + "removeQuadIcon" + ".png"));
showTexturesOnIcon = new GUIContent("", (Texture)EditorGUIUtility.Load(LOADICONPATH + "showTexturesOnIcon" + ".png"));
showTexturesOffIcon = new GUIContent("", (Texture)EditorGUIUtility.Load(LOADICONPATH + "showTexturesOffIcon" + ".png"));
dragHandleIcon = new GUIContent("", (Texture)EditorGUIUtility.Load(LOADICONPATH + "dragHandleIcon" + ".png"));
editIcon = new GUIContent("", (Texture)EditorGUIUtility.Load(LOADICONPATH + "editIcon" + ".png"));
}
}
}

View File

@ -0,0 +1,317 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using MA_Mesh;
using MA_Texture;
namespace MA_TextureAtlasserPro
{
public static class MA_TextureAtlasserProUtils
{
public const string SAVEASSETPATH = "Assets/MA_ToolBox/MA_TextureAtlasserPro/Atlasses/";
public const string LOADASSETPATH = "Assets/MA_ToolBox/MA_TextureAtlasserPro/Atlasses/";
public const string EXPORTASSETPATH = "Assets/MA_ToolBox/MA_TextureAtlasserPro/Exports/";
public const float VIEWOFFSET = 20;
public const string DEFAULTTEXTUREGROUPNAME = "Albedo";
public static MA_TextureAtlasserProAtlas CreateTextureAtlas(string name, Vector2 size)
{
MA_TextureAtlasserProAtlas _atlas = (MA_TextureAtlasserProAtlas)ScriptableObject.CreateInstance<MA_TextureAtlasserProAtlas>();
if(_atlas != null)
{
_atlas.CreateAtlas(name, size);
MA_CheckTextureAtlas(_atlas);
AssetDatabase.CreateAsset(_atlas, SAVEASSETPATH + name + ".asset");
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
return _atlas;
}
else
{
return null;
}
}
public static MA_TextureAtlasserProAtlas LoadTextureAtlas()
{
MA_TextureAtlasserProAtlas _atlas = null;
string absPath = EditorUtility.OpenFilePanel("Select Texture Atlas", LOADASSETPATH, "");
if(absPath.StartsWith(Application.dataPath))
{
string relPath = absPath.Substring(Application.dataPath.Length - "Assets".Length);
_atlas = AssetDatabase.LoadAssetAtPath(relPath, typeof(MA_TextureAtlasserProAtlas)) as MA_TextureAtlasserProAtlas;
MA_CheckTextureAtlas(_atlas);
if(_atlas)
{
EditorPrefs.SetString("AtlasPath", null);
}
}
if(_atlas != null)
{
if(_atlas.selectedTextureQuad != null)
{
_atlas.selectedTextureQuad.isSelected = false;
}
_atlas.selectedTextureQuad = null;
}
return _atlas;
}
public static void MA_CheckTextureAtlas(MA_TextureAtlasserProAtlas atlas)
{
if(atlas.textureGroupRegistration == null)
{
atlas.textureGroupRegistration = new List<MA_TextureGroupRegistration>();
MA_TextureGroupRegistration groupRegistration = new MA_TextureGroupRegistration();
groupRegistration.name = DEFAULTTEXTUREGROUPNAME;
atlas.textureGroupRegistration.Add(groupRegistration);
}
if(atlas.textureQuads == null)
{
atlas.textureQuads = new List<MA_TextureAtlasserProQuad>();
}
else
{
bool _sameCount = true;
foreach (MA_TextureAtlasserProQuad q in atlas.textureQuads)
{
if(q.textureGroups.Count != atlas.textureGroupRegistration.Count)
{
_sameCount = false;
Debug.LogWarning("TextureAtlasser: " + q.name + " doesn't have the right amount of texture groups!");
}
}
if(_sameCount)
{
foreach (MA_TextureAtlasserProQuad q in atlas.textureQuads)
{
for (int i = 0; i < atlas.textureQuads.Count; i++)
{
for (int j = 0; j < atlas.textureGroupRegistration.Count; j++)
{
if(atlas.textureQuads[i].textureGroups[j].name != atlas.textureGroupRegistration[j].name)
{
Debug.LogWarning("TextureAtlasser: " + q.name + " doesn't have the right texture group name!");
}
}
}
}
}
}
}
public static void CreateTextureQuad(MA_TextureAtlasserProAtlas atlas, string name, Rect rect)
{
if(atlas != null)
{
//Create new list if we haven't one already
if(atlas.textureQuads == null)
{
atlas.textureQuads = new List<MA_TextureAtlasserProQuad>();
}
//Create new quad
MA_TextureAtlasserProQuad _quad = (MA_TextureAtlasserProQuad)ScriptableObject.CreateInstance("MA_TextureAtlasserProQuad");
//Add quad to asset
if(_quad != null)
{
//Set quad settings
_quad.name = name;
_quad.rect = rect;
SetTextureGroups(atlas, _quad);
atlas.textureQuads.Add((MA_TextureAtlasserProQuad)_quad);
AssetDatabase.AddObjectToAsset(_quad, atlas);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
else
{
Debug.LogError("CreateTextureQuad Failed: _TextureQuad");
}
}
else
{
Debug.LogError("CreateTextureQuad Failed: textureAtlas");
}
}
public static void RemoveTextureQuad(MA_TextureAtlasserProAtlas atlas)
{
if(atlas != null && atlas.selectedTextureQuad != null)
{
atlas.textureQuads.Remove(atlas.selectedTextureQuad);
GameObject.DestroyImmediate(atlas.selectedTextureQuad, true);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
}
public static void SetTextureGroups(MA_TextureAtlasserProAtlas atlas, MA_TextureAtlasserProQuad quad)
{
if(quad.textureGroups == null)
{
quad.textureGroups = new List<MA_TextureGroup>();
}
//Add texture groups
foreach (MA_TextureGroupRegistration tgr in atlas.textureGroupRegistration)
{
MA_TextureGroup textureGroup = new MA_TextureGroup();
textureGroup.name = tgr.name;
quad.textureGroups.Add(textureGroup);
}
}
public static void CreateTextureGroup(MA_TextureAtlasserProAtlas atlas, string name)
{
MA_TextureGroupRegistration _textureGroupRegistration = new MA_TextureGroupRegistration();
_textureGroupRegistration.name = name;
atlas.textureGroupRegistration.Add(_textureGroupRegistration);
foreach (MA_TextureAtlasserProQuad q in atlas.textureQuads)
{
MA_TextureGroup _textureGroup = new MA_TextureGroup();
_textureGroup.name = name;
q.textureGroups.Add(_textureGroup);
}
}
public static void RemoveTextureGroup(MA_TextureAtlasserProAtlas atlas, int index)
{
atlas.textureGroupRegistration.RemoveAt(index);
foreach (MA_TextureAtlasserProQuad q in atlas.textureQuads)
{
q.textureGroups.RemoveAt(index);
}
}
public static void CloseWindow(MA_TextureAtlasserProWindow curWindow)
{
if(curWindow == null)
{
Debug.LogError("Closing window Failed: curWindow == null");
}
curWindow.Close();
}
public static void ExportAtlas(MA_TextureAtlasserProAtlas atlas, string savePath = EXPORTASSETPATH)
{
if(atlas != null && atlas.textureQuads != null)
{
ExportAtlasMeshesObj(atlas);
ExportAtlasTexturesPNG(atlas);
AssetDatabase.Refresh();
}
}
public static void ExportAtlasMeshesObj(MA_TextureAtlasserProAtlas atlas, string savePath = EXPORTASSETPATH)
{
if(atlas != null && atlas.textureQuads != null)
{
foreach (MA_TextureAtlasserProQuad ta in atlas.textureQuads)
{
//Export Mesh
if(ta.meshes != null)
{
for (int m = 0; m < ta.meshes.Count; m++)
{
if(ta.meshes[m] != null)
{
//Create new mesh
Mesh newMesh = new Mesh();
//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);
}
}
}
}
}
}
// public static void ExportAtlasTexturePNG(MA_TextureAtlasserProAtlas atlas, 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++)
{
//Create new Texture Atlas
Texture2D newTexture = new Texture2D((int)atlas.textureAtlasSize.x, (int)atlas.textureAtlasSize.y);
newTexture.name = atlas.name + "_" + atlas.textureGroupRegistration[i].name;
foreach (MA_TextureAtlasserProQuad q in atlas.textureQuads)
{
if(q.textureGroups != null && q.textureGroups[i].texture != null)
{
//Create new texture part
Texture2D newTexturePart = (Texture2D)MA_Texture.MA_TextureUtils.ConvertToReadableTexture(q.textureGroups[i].texture);
//Scale it
newTexturePart = newTexturePart.MA_Scale2D((int)q.guiRect.width, (int)q.guiRect.height);
//Add it
newTexture = newTexture.MA_Combine2D(newTexturePart, (int)q.guiRect.x, (int)q.guiRect.y);
}
}
//Save it
newTexture.MA_Save2D("MA_" + newTexture.name, savePath);
}
//Refresh
AssetDatabase.Refresh();
}
}
}
}

View File

@ -0,0 +1,78 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using MA_Editor;
namespace MA_TextureAtlasserPro
{
public class MA_TextureAtlasserProDebugView : MA_TextureAtlasserProViewBase
{
private bool isEditing = false;
public MA_TextureAtlasserProDebugView(MA_TextureAtlasserProWindow currentEditorWindow, string title) : base(currentEditorWindow, title)
{
}
public override void UpdateView(Event e, Rect editorViewRect)
{
//Update base derived class
base.UpdateView(e, editorViewRect);
//Draw inspector
if(isLoaded)
{
GUILayout.BeginArea(editorViewRect, EditorStyles.helpBox);
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
//GUILayout.Label(curWindow.workView.Zoom.ToString("F2"));
if(GUILayout.Button(curWindow.workView.Zoom.ToString("F2"), EditorStyles.label))
{
curWindow.workView.ResetWindow();
}
if(curWindow.textureAtlas != null)
{
GUILayout.FlexibleSpace();
//GUILayout.Label(curWindow.textureAtlas.textureAtlasSize.ToString());
if(!isEditing)
{
if(GUILayout.Button(curWindow.textureAtlas.textureAtlasSize.ToString("F0"), EditorStyles.label))
{
isEditing = true;
}
}
else
{
curWindow.textureAtlas.textureAtlasSize = EditorGUILayout.Vector2Field("", curWindow.textureAtlas.textureAtlasSize, GUILayout.Width(110));
}
}
GUILayout.EndHorizontal();
GUILayout.EndArea();
}
ProcessEvents(e, editorViewRect);
}
protected override void ProcessEvents(Event e, Rect editorViewRect)
{
base.ProcessEvents(e, editorViewRect);
if(isEditing)
{
if(e.type == EventType.KeyDown && e.keyCode == KeyCode.Return)
{
isEditing = false;
return;
}
if(e.type == EventType.MouseDown && !isMouseInEditorViewRect)
{
isEditing = false;
return;
}
}
}
}
}

View File

@ -0,0 +1,134 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using MA_Editor;
namespace MA_TextureAtlasserPro
{
public class MA_TextureAtlasserProInspectorView : MA_TextureAtlasserProViewBase
{
private MA_TextureAtlasserProQuad lastSelectedQuad;
private bool isEditing = false;
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)
{
//Draw inspector
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.BeginArea(editorViewRect, EditorStyles.helpBox);
GUILayout.BeginVertical(GUILayout.ExpandWidth(true));
GUILayout.Label("Quad Name");
curWindow.textureAtlas.selectedTextureQuad.name = EditorGUILayout.TextField(curWindow.textureAtlas.selectedTextureQuad.name);
GUILayout.Space(MA_TextureAtlasserProUtils.VIEWOFFSET / 2);
//Textures
GUILayout.BeginHorizontal();
GUILayout.Label("Textures", GUILayout.ExpandWidth(true));
if(GUILayout.Button(MA_TextureAtlasserProIcons.editIcon, EditorStyles.miniButton, GUILayout.Width(36), GUILayout.Height(15)))
{
isEditing = !isEditing;
}
GUILayout.EndHorizontal();
if(curWindow.textureAtlas.textureGroupRegistration == null || curWindow.textureAtlas.textureGroupRegistration.Count == 0)
{
if(GUILayout.Button("+", EditorStyles.miniButton, GUILayout.ExpandWidth(true)))
{
MA_TextureAtlasserProUtils.CreateTextureGroup(curWindow.textureAtlas, "New TextureGroup");
}
}
for (int i = 0; i < curWindow.textureAtlas.textureGroupRegistration.Count; i++)
{
if(isEditing)
{
curWindow.textureAtlas.textureGroupRegistration[i].name = curWindow.textureAtlas.selectedTextureQuad.textureGroups[i].name = EditorGUILayout.TextField(curWindow.textureAtlas.textureGroupRegistration[i].name);
}
else
{
GUILayout.Label(curWindow.textureAtlas.textureGroupRegistration[i].name);
}
GUILayout.BeginHorizontal();
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)))
{
MA_TextureAtlasserProUtils.RemoveTextureGroup(curWindow.textureAtlas, i);
}
if(isEditing && GUILayout.Button("+", EditorStyles.miniButtonRight, GUILayout.ExpandWidth(false)))
{
MA_TextureAtlasserProUtils.CreateTextureGroup(curWindow.textureAtlas, "New TextureGroup");
}
GUILayout.EndHorizontal();
}
GUILayout.Space(MA_TextureAtlasserProUtils.VIEWOFFSET / 2);
//Meshes
GUILayout.Label("Meshes");
if(curWindow.textureAtlas.selectedTextureQuad.meshes != null)
{
if(curWindow.textureAtlas.selectedTextureQuad.meshes.Count == 0)
{
if(GUILayout.Button("+", EditorStyles.miniButton, GUILayout.ExpandWidth(true)))
{
curWindow.textureAtlas.selectedTextureQuad.meshes.Add(null);
}
}
for (int i = 0; i < curWindow.textureAtlas.selectedTextureQuad.meshes.Count; i++)
{
GUILayout.BeginHorizontal();
curWindow.textureAtlas.selectedTextureQuad.meshes[i] = (Mesh)EditorGUILayout.ObjectField(curWindow.textureAtlas.selectedTextureQuad.meshes[i], typeof(Mesh), false);
if(GUILayout.Button("-", EditorStyles.miniButtonLeft, GUILayout.ExpandWidth(false)))
{
curWindow.textureAtlas.selectedTextureQuad.meshes.RemoveAt(i);
}
if(GUILayout.Button("+", EditorStyles.miniButtonRight, GUILayout.ExpandWidth(false)))
{
curWindow.textureAtlas.selectedTextureQuad.meshes.Insert(i, null);
}
GUILayout.EndHorizontal();
}
}
else
{
curWindow.textureAtlas.selectedTextureQuad.meshes = new List<Mesh>();
}
GUILayout.FlexibleSpace();
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.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);
}
}
}

View File

@ -0,0 +1,76 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using MA_Editor;
namespace MA_TextureAtlasserPro
{
public class MA_TextureAtlasserProMenuView : MA_TextureAtlasserProViewBase
{
public MA_TextureAtlasserProMenuView(MA_TextureAtlasserProWindow currentEditorWindow, string title) : base(currentEditorWindow, title)
{
}
public override void UpdateView(Event e, Rect editorViewRect)
{
//Update base derived class
base.UpdateView(e, editorViewRect);
//Draw Menu
if(isLoaded)
{
GUILayout.BeginArea(editorViewRect, EditorStyles.helpBox);
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
if(GUILayout.Button(MA_TextureAtlasserProIcons.createAtlasIcon, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
{
MA_TextureAtlasserProCreateWindow.InitEditorWindow(curWindow);
}
if(GUILayout.Button(MA_TextureAtlasserProIcons.loadAtlasIcon, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
{
curWindow.textureAtlas = MA_TextureAtlasserProUtils.LoadTextureAtlas();
}
if(curWindow.textureAtlas != null)
{
if(GUILayout.Button(MA_TextureAtlasserProIcons.exportAtlasIcon, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
{
MA_TextureAtlasserProExportWindow.InitEditorWindow(curWindow);
//MA_TextureAtlasserProUtils.ExportAtlas(curWindow.textureAtlas);
}
GUILayout.Space(MA_TextureAtlasserProUtils.VIEWOFFSET);
if(curWindow.textureAtlas.showTextures && GUILayout.Button(MA_TextureAtlasserProIcons.showTexturesOnIcon, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
{
curWindow.textureAtlas.showTextures = false;
}
else if(!curWindow.textureAtlas.showTextures && GUILayout.Button(MA_TextureAtlasserProIcons.showTexturesOffIcon, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
{
curWindow.textureAtlas.showTextures = true;
}
GUILayout.Space(MA_TextureAtlasserProUtils.VIEWOFFSET);
if(GUILayout.Button(MA_TextureAtlasserProIcons.createQuadIcon, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
{
MA_TextureAtlasserProUtils.CreateTextureQuad(curWindow.textureAtlas, "new Quad", new Rect(0, 0, 128, 128));
}
if(curWindow.textureAtlas.selectedTextureQuad != null && GUILayout.Button(MA_TextureAtlasserProIcons.removeQuadIcon, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
{
if(curWindow.textureAtlas.selectedTextureQuad != null)
MA_TextureAtlasserProUtils.RemoveTextureQuad(curWindow.textureAtlas);
}
}
GUILayout.EndHorizontal();
GUILayout.EndArea();
}
ProcessEvents(e, editorViewRect);
}
protected override void ProcessEvents(Event e, Rect editorViewRect)
{
base.ProcessEvents(e, editorViewRect);
}
}
}

View File

@ -0,0 +1,55 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
namespace MA_TextureAtlasserPro
{
public class MA_TextureAtlasserProViewBase
{
public MA_TextureAtlasserProWindow curWindow;
public string viewTitle;
public bool isMouseInEditorViewRect = false;
public static bool editorIsLoaded = false;
public bool isLoaded = false;
public MA_TextureAtlasserProViewBase(MA_TextureAtlasserProWindow currentEditorWindow, string title)
{
curWindow = currentEditorWindow;
viewTitle = title;
}
[UnityEditor.Callbacks.DidReloadScripts]
static void OnReload()
{
//Make sure that when the compiler is finished and reloads the scripts, we are waiting for the next Event.
editorIsLoaded = false;
}
public virtual void UpdateView(Event e, Rect editorViewRect)
{
}
protected virtual void ProcessEvents(Event e, Rect editorViewRect)
{
if(e.type == EventType.Repaint)
{
if(!isLoaded && editorIsLoaded)
isLoaded = true;
if(!editorIsLoaded)
editorIsLoaded = true;
}
if(editorViewRect.Contains(e.mousePosition))
{
isMouseInEditorViewRect = true;
}
else
{
isMouseInEditorViewRect = false;
}
}
}
}

View File

@ -0,0 +1,122 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MA_Editor;
using MA_Editor.GUILayoutZoom;
using MA_Editor.RectUtils;
namespace MA_TextureAtlasserPro
{
public class MA_TextureAtlasserProWorkView : MA_TextureAtlasserProViewBase
{
public MA_TextureAtlasserProWorkView(MA_TextureAtlasserProWindow currentEditorWindow, string title) : base(currentEditorWindow, title)
{
zoomCoordsOrigin = new Vector2(-(curWindow.position.width / 2) + (curWindow.position.width / 3), -(curWindow.position.height / 2) + (curWindow.position.height / 3));
}
private const float kZoomMin = 0.05f;
private const float kZoomMax = 2.0f;
private Rect zoomArea;
private float zoom = 1.0f;
public float Zoom { get { return zoom; } }
private Vector2 zoomCoordsOrigin = Vector2.zero;
public override void UpdateView(Event e, Rect editorViewRect)
{
//Update base derived class
base.UpdateView(e, editorViewRect);
zoomArea = editorViewRect;
bool useEvents;
if(curWindow.menuView.isMouseInEditorViewRect || curWindow.inspectorView.isMouseInEditorViewRect || curWindow.debugView.isMouseInEditorViewRect)
useEvents = false;
else
useEvents = true;
//Draw Work
if(isLoaded)
{
//Start zoom area
GUILayoutZoom.BeginArea(zoom, zoomArea);
//Draw quads
if(curWindow.textureAtlas != null)
{
curWindow.textureAtlas.UpdateTextureQuads(e, editorViewRect, zoomCoordsOrigin, useEvents);
DrawQuadGUI();
}
//End zoom area
GUILayoutZoom.EndArea();
}
if(useEvents)
ProcessEvents(e, editorViewRect);
}
protected override void ProcessEvents(Event e, Rect editorViewRect)
{
base.ProcessEvents(e, editorViewRect);
// Allow adjusting the zoom with the mouse wheel as well. In this case, use the mouse coordinates
// as the zoom center instead of the top left corner of the zoom area. This is achieved by
// maintaining an origin that is used as offset when drawing any GUI elements in the zoom area.
if (e.type == EventType.ScrollWheel)
{
Vector2 screenCoordsMousePos = e.mousePosition;
Vector2 delta = e.delta;
Vector2 zoomCoordsMousePos = ConvertScreenCoordsToZoomCoords(screenCoordsMousePos);
float zoomDelta = -delta.y / 100.0f;
float oldZoom = zoom;
zoom += zoomDelta;
zoom = Mathf.Clamp(zoom, kZoomMin, kZoomMax);
if(zoom < 1.025f && zoom > 0.995f)
{
zoom = 1;
}
zoomCoordsOrigin += (zoomCoordsMousePos - zoomCoordsOrigin) - (oldZoom / zoom) * (zoomCoordsMousePos - zoomCoordsOrigin);
e.Use();
}
// Allow moving the zoom area's origin by dragging by dragging with the left mouse button with Alt pressed.
if (e.type == EventType.MouseDrag && (e.button == 2 || (e.button == 0 && e.modifiers == EventModifiers.Alt)))
{
Vector2 delta = Event.current.delta;
delta /= zoom;
zoomCoordsOrigin -= delta;
e.Use();
}
}
private Vector2 ConvertScreenCoordsToZoomCoords(Vector2 screenCoords)
{
return (screenCoords - zoomArea.TopLeft()) / zoom + zoomCoordsOrigin;
}
//Draw quad GUI ontop of quad with custom GUIContent.
private void DrawQuadGUI()
{
if(curWindow.textureAtlas.textureQuads != null)
{
foreach (MA_TextureAtlasserProQuad q in curWindow.textureAtlas.textureQuads)
{
if(q.isSelected)
{
GUI.Button(new Rect(q.dragRectPos.x, q.dragRectPos.y, q.dragRectPos.width, q.dragRectPos.height), MA_TextureAtlasserProIcons.dragHandleIcon);
GUI.Button(new Rect(q.dragRectWidth.x, q.dragRectWidth.y, q.dragRectWidth.width, q.dragRectWidth.height), MA_TextureAtlasserProIcons.dragHandleIcon);
GUI.Button(new Rect(q.dragRectHeight.x, q.dragRectHeight.y, q.dragRectHeight.width, q.dragRectHeight.height), MA_TextureAtlasserProIcons.dragHandleIcon);
}
}
}
}
public void ResetWindow()
{
zoom = 1;
zoomCoordsOrigin = new Vector2(-(curWindow.position.width / 2) + (curWindow.position.width / 3), -(curWindow.position.height / 2) + (curWindow.position.height / 3));
}
}
}

View File

@ -0,0 +1,170 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using MA_Editor;
namespace MA_TextureAtlasserPro
{
public class MA_TextureAtlasserProCreateWindow : EditorWindow
{
//Editor
private static MA_TextureAtlasserProCreateWindow thisWindow;
public static MA_TextureAtlasserProWindow curWindow;
private bool linkedAtlasSize = true;
private bool nameError = true;
private bool sizeError = true;
//Data
private string textureAtlasName = "Atlas name";
private Vector2 textureAtlasSize = new Vector2(512, 512);
private MA_TextureAtlasserProAtlas textureAtlas;
private static bool isLoaded = false;
[MenuItem("MA_ToolKit/MA_TextureAtlasserPro/New Atlas")]
private static void Init()
{
GetCurrentWindow();
thisWindow.minSize = new Vector2(500,160);
thisWindow.maxSize = new Vector2(500,160);
thisWindow.titleContent.text = "MA_CreateTextureAtlas";
thisWindow.Show();
}
public static void InitEditorWindow(MA_TextureAtlasserProWindow currentEditorWindow)
{
curWindow = currentEditorWindow;
GetCurrentWindow();
thisWindow.minSize = new Vector2(500,160);
thisWindow.maxSize = new Vector2(500,160);
thisWindow.titleContent.text = "MA_CreateTextureAtlas";
thisWindow.Show();
}
private static void GetCurrentWindow()
{
thisWindow = (MA_TextureAtlasserProCreateWindow)EditorWindow.GetWindow<MA_TextureAtlasserProCreateWindow>();
}
private void CloseWindow()
{
if(thisWindow == null)
{
GetCurrentWindow();
thisWindow.Close();
}
else
{
thisWindow.Close();
}
}
private Event ProcessEvents()
{
Event e = Event.current;
return e;
}
[UnityEditor.Callbacks.DidReloadScripts]
static void OnReload()
{
//Make sure that when the compiler is finished and reloads the scripts, we are waiting for the next Event.
isLoaded = false;
}
private void OnGUI()
{
if(thisWindow == null)
{
GetCurrentWindow();
return;
}
//Get current event
Event e = ProcessEvents();
if(isLoaded)
{
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
textureAtlasName = EditorGUILayout.TextField("Atlas name", textureAtlasName, GUILayout.ExpandWidth(true));
if(textureAtlasName == "Atlas name" || string.IsNullOrEmpty(textureAtlasName))
{
nameError = true;
GUI.backgroundColor = Color.red;
GUILayout.Box("Error: Enter a valid atlas name!", EditorStyles.helpBox);
GUI.backgroundColor = Color.white;
}
else
{
nameError = false;
}
textureAtlasSize.x = EditorGUILayout.IntField("Atlas width", (int)textureAtlasSize.x, GUILayout.ExpandWidth(true));
if(linkedAtlasSize)
{
linkedAtlasSize = EditorGUILayout.Toggle("link height", linkedAtlasSize, GUILayout.ExpandWidth(true));
textureAtlasSize.y = textureAtlasSize.x;
}
else
{
textureAtlasSize.y = EditorGUILayout.IntField("Atlas height", (int)textureAtlasSize.y, GUILayout.ExpandWidth(true));
}
if(!Mathf.IsPowerOfTwo((int)textureAtlasSize.x) || !Mathf.IsPowerOfTwo((int)textureAtlasSize.y))
{
GUI.backgroundColor = Color.yellow;
GUILayout.Box("Warning: Atlas size value isn't a power of two!", EditorStyles.helpBox);
GUI.backgroundColor = Color.white;
}
if(textureAtlasSize.x < 64 || textureAtlasSize.y < 64)
{
sizeError = true;
GUI.backgroundColor = Color.red;
GUILayout.Box("Error: The minimum atlas size is 64!", EditorStyles.helpBox);
GUI.backgroundColor = Color.white;
}
else
{
sizeError = false;
}
//Create
if(!nameError && !sizeError)
{
if(GUILayout.Button("Create Atlas", GUILayout.ExpandWidth(true), GUILayout.Height(37)))
{
textureAtlas = MA_TextureAtlasserProUtils.CreateTextureAtlas(textureAtlasName, textureAtlasSize);
if(curWindow != null)
{
curWindow.textureAtlas = textureAtlas;
}
else
{
Debug.Log("No editor window found");
}
CloseWindow();
}
}
GUILayout.EndVertical();
GUILayout.EndArea();
}
if(e.type == EventType.Repaint)
isLoaded = true;
}
}
}

View File

@ -0,0 +1,135 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using MA_Editor;
namespace MA_TextureAtlasserPro
{
public class MA_TextureAtlasserProExportWindow : EditorWindow
{
//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.
[MenuItem("MA_ToolKit/MA_TextureAtlasserPro/Export Atlas")]
private static void Init()
{
GetCurrentWindow();
thisWindow.minSize = new Vector2(500,160);
thisWindow.maxSize = new Vector2(500,160);
thisWindow.titleContent.text = "MA_ExportTextureAtlas";
thisWindow.Show();
}
public static void InitEditorWindow(MA_TextureAtlasserProWindow currentEditorWindow)
{
curWindow = currentEditorWindow;
GetCurrentWindow();
thisWindow.minSize = new Vector2(500,160);
thisWindow.maxSize = new Vector2(500,160);
thisWindow.titleContent.text = "MA_ExportTextureAtlas";
thisWindow.Show();
}
private static void GetCurrentWindow()
{
thisWindow = (MA_TextureAtlasserProExportWindow)EditorWindow.GetWindow<MA_TextureAtlasserProExportWindow>();
}
private void CloseWindow()
{
if(thisWindow == null)
{
GetCurrentWindow();
thisWindow.Close();
}
else
{
thisWindow.Close();
}
}
private Event ProcessEvents()
{
Event e = Event.current;
return e;
}
[UnityEditor.Callbacks.DidReloadScripts]
private static void OnReload()
{
//Make sure that when the compiler is finished and reloads the scripts, we are waiting for the next Event.
isLoaded = false;
}
private void OnGUI()
{
if(thisWindow == null)
{
GetCurrentWindow();
return;
}
//Get current event
Event e = ProcessEvents();
if(isLoaded)
{
GUILayout.BeginArea(new Rect(MA_TextureAtlasserProUtils.VIEWOFFSET, MA_TextureAtlasserProUtils.VIEWOFFSET, position.width - (MA_TextureAtlasserProUtils.VIEWOFFSET * 2), position.height - (MA_TextureAtlasserProUtils.VIEWOFFSET * 2)));
GUILayout.BeginVertical();
if(curWindow != null && curWindow.textureAtlas != null)
{
//Export options
GUILayout.Box("Note: No custom export options right now.. :<", EditorStyles.helpBox);
//Export
GUILayout.BeginVertical(EditorStyles.helpBox);
GUILayout.Label("Meshes: OBJ | Textures: PNG");
if(GUILayout.Button("Export Atlas", GUILayout.ExpandWidth(true), GUILayout.Height(37)))
{
MA_TextureAtlasserProUtils.ExportAtlas(curWindow.textureAtlas);
}
GUILayout.EndVertical();
}
else if(curWindow == null)
{
GUI.backgroundColor = Color.red;
GUILayout.Box("Error: Link with the Texture Atlas Editor lost!", EditorStyles.helpBox);
if(GUILayout.Button("Link Atlas Editor", GUILayout.ExpandWidth(true), GUILayout.Height(37)))
{
curWindow = (MA_TextureAtlasserProWindow)EditorWindow.GetWindow<MA_TextureAtlasserProWindow>();
}
GUI.backgroundColor = Color.white;
}
else if(curWindow.textureAtlas == null)
{
GUI.backgroundColor = Color.red;
GUILayout.Box("Error: No Texture Atlas found make sure to open one!", EditorStyles.helpBox);
GUI.backgroundColor = Color.white;
}
GUILayout.EndVertical();
GUILayout.EndArea();
}
if(e.type == EventType.Repaint)
isLoaded = true;
}
}
}

View File

@ -0,0 +1,119 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
namespace MA_TextureAtlasserPro
{
public class MA_TextureAtlasserProWindow : EditorWindow
{
public static MA_TextureAtlasserProWindow thisWindow;
public MA_TextureAtlasserProAtlas textureAtlas;
public MA_TextureAtlasserProWorkView workView;
public MA_TextureAtlasserProMenuView menuView;
public MA_TextureAtlasserProInspectorView inspectorView;
public MA_TextureAtlasserProDebugView debugView;
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/Atlas Editor")]
private static void Init()
{
GetCurrentWindow();
thisWindow.titleContent.text = "MA_TextureAtlasserPro";
thisWindow.minSize = new Vector2(375, 360);
thisWindow.wantsMouseMove = true;
thisWindow.Show();
}
private void OnEnable()
{
//Load the icons
MA_TextureAtlasserProIcons.LoadIcons();
}
private static void GetCurrentWindow()
{
thisWindow = (MA_TextureAtlasserProWindow)EditorWindow.GetWindow<MA_TextureAtlasserProWindow>();
}
private void CloseCurrentWindow()
{
if(thisWindow == null)
{
GetCurrentWindow();
}
thisWindow.Close();
}
private static void CreateViews()
{
if(thisWindow == null)
{
GetCurrentWindow();
}
thisWindow.workView = new MA_TextureAtlasserProWorkView(thisWindow, "workView");
thisWindow.menuView = new MA_TextureAtlasserProMenuView(thisWindow, "menuView");
thisWindow.inspectorView = new MA_TextureAtlasserProInspectorView(thisWindow, "inspectorView");
thisWindow.debugView = new MA_TextureAtlasserProDebugView(thisWindow, "debugView");
}
private Event ProcessEvents()
{
Event e = Event.current;
return e;
}
[UnityEditor.Callbacks.DidReloadScripts]
private static void OnReload()
{
//Make sure that when the compiler is finished and reloads the scripts, we are waiting for the next Event.
isLoaded = false;
}
private void OnGUI()
{
//Check window
if(thisWindow == null)
{
GetCurrentWindow();
return;
}
//Check views
if(workView == null || menuView == null || inspectorView == null || debugView == null)
{
CreateViews();
return;
}
//Get current event
Event e = ProcessEvents();
//Calculate view rects
Rect workViewRect = new Rect(position.width - position.width, position.height - position.height, position.width, position.height);
Rect debugViewRect = new Rect(position.width - MA_TextureAtlasserProUtils.VIEWOFFSET - 164, position.height - MA_TextureAtlasserProUtils.VIEWOFFSET - 22, 164, 22);
Rect menuViewRect = new Rect(MA_TextureAtlasserProUtils.VIEWOFFSET, MA_TextureAtlasserProUtils.VIEWOFFSET, position.width - (MA_TextureAtlasserProUtils.VIEWOFFSET * 2), 44);
Rect inspectorViewRect = new Rect(MA_TextureAtlasserProUtils.VIEWOFFSET, menuViewRect.y + menuViewRect.height + MA_TextureAtlasserProUtils.VIEWOFFSET, 164, position.height - menuViewRect.height - (MA_TextureAtlasserProUtils.VIEWOFFSET * 3));
//Draw views and windows in the right oder from back to front
if(isLoaded)
{
workView.UpdateView(e, workViewRect);
debugView.UpdateView(e, debugViewRect);
inspectorView.UpdateView(e, inspectorViewRect);
menuView.UpdateView(e, menuViewRect);
}
Repaint();
if(e.type == EventType.Repaint)
isLoaded = true;
}
}
}