mirror of
https://github.com/maxartz15/MA_TextureAtlasser.git
synced 2025-06-30 05:46:06 +02:00
1.0, gitignore
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user