mirror of
https://github.com/maxartz15/MA_TextureAtlasser.git
synced 2025-06-17 00:26:10 +02:00
Restructured files and folders.
This commit is contained in:
@ -0,0 +1,62 @@
|
||||
//https://github.com/maxartz15/MA_EditorUtils
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace MA_Editor.Grid
|
||||
{
|
||||
public static class Grid
|
||||
{
|
||||
public static void DrawGrid(Rect editorWorkRect, float gridSpacing, Color gridColor)
|
||||
{
|
||||
//Process grid spacing values
|
||||
int widthDivs = Mathf.CeilToInt(editorWorkRect.width / gridSpacing);
|
||||
int heightDivs = Mathf.CeilToInt(editorWorkRect.height / gridSpacing);
|
||||
|
||||
//Using handles
|
||||
Handles.BeginGUI();
|
||||
Handles.color = gridColor;
|
||||
|
||||
for (int x = 0; x < widthDivs; x++)
|
||||
{
|
||||
Handles.DrawLine(new Vector3(gridSpacing * x, 0, 0), new Vector3(gridSpacing * x, editorWorkRect.height, 0));
|
||||
}
|
||||
|
||||
for (int y = 0; y < heightDivs; y++)
|
||||
{
|
||||
Handles.DrawLine(new Vector3(0, gridSpacing * y, 0), new Vector3(editorWorkRect.width, gridSpacing * y, 0));
|
||||
}
|
||||
|
||||
Handles.color = Color.white;
|
||||
Handles.EndGUI();
|
||||
}
|
||||
|
||||
public static void DrawZoomableGrid(Rect editorWorkRect, float gridSpacing, Color gridColor, Vector2 zoomCoordsOrigin)
|
||||
{
|
||||
//Process grid spacing values
|
||||
int widthDivs = Mathf.CeilToInt(editorWorkRect.width / gridSpacing);
|
||||
int heightDivs = Mathf.CeilToInt(editorWorkRect.height / gridSpacing);
|
||||
|
||||
//Using handles
|
||||
Handles.BeginGUI();
|
||||
Handles.color = gridColor;
|
||||
|
||||
for (int x = 1; x < widthDivs; x++)
|
||||
{
|
||||
Handles.DrawLine(new Vector3(gridSpacing * x - zoomCoordsOrigin.x, -zoomCoordsOrigin.y, 0), new Vector3(gridSpacing * x - zoomCoordsOrigin.x, editorWorkRect.height - zoomCoordsOrigin.y, 0));
|
||||
}
|
||||
|
||||
for (int y = 1; y < heightDivs; y++)
|
||||
{
|
||||
Handles.DrawLine(new Vector3(-zoomCoordsOrigin.x, gridSpacing * y - zoomCoordsOrigin.y, 0), new Vector3(editorWorkRect.width - zoomCoordsOrigin.x, gridSpacing * y - zoomCoordsOrigin.y, 0));
|
||||
}
|
||||
|
||||
Handles.color = Color.white;
|
||||
Handles.EndGUI();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 64df885d83caddf48acfa78533a3e76f
|
||||
timeCreated: 1522672827
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,74 @@
|
||||
//https://github.com/maxartz15/MA_EditorUtils
|
||||
|
||||
//References:
|
||||
//http://martinecker.com/martincodes/unity-editor-window-zooming/
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using MA_Editor;
|
||||
|
||||
namespace MA_Editor.RectUtils
|
||||
{
|
||||
public static class RectUtils
|
||||
{
|
||||
//Start http://martinecker.com/martincodes/unity-editor-window-zooming/
|
||||
public static Vector2 TopLeft(this Rect rect)
|
||||
{
|
||||
return new Vector2(rect.xMin, rect.yMin);
|
||||
}
|
||||
|
||||
public static Rect ScaleSizeBy(this Rect rect, float scale)
|
||||
{
|
||||
return rect.ScaleSizeBy(scale, rect.center);
|
||||
}
|
||||
|
||||
public static Rect ScaleSizeBy(this Rect rect, float scale, Vector2 pivotPoint)
|
||||
{
|
||||
Rect result = rect;
|
||||
result.x -= pivotPoint.x;
|
||||
result.y -= pivotPoint.y;
|
||||
result.xMin *= scale;
|
||||
result.xMax *= scale;
|
||||
result.yMin *= scale;
|
||||
result.yMax *= scale;
|
||||
result.x += pivotPoint.x;
|
||||
result.y += pivotPoint.y;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Rect ScaleSizeBy(this Rect rect, Vector2 scale)
|
||||
{
|
||||
return rect.ScaleSizeBy(scale, rect.center);
|
||||
}
|
||||
|
||||
public static Rect ScaleSizeBy(this Rect rect, Vector2 scale, Vector2 pivotPoint)
|
||||
{
|
||||
Rect result = rect;
|
||||
result.x -= pivotPoint.x;
|
||||
result.y -= pivotPoint.y;
|
||||
result.xMin *= scale.x;
|
||||
result.xMax *= scale.x;
|
||||
result.yMin *= scale.y;
|
||||
result.yMax *= scale.y;
|
||||
result.x += pivotPoint.x;
|
||||
result.y += pivotPoint.y;
|
||||
return result;
|
||||
}
|
||||
//End http://martinecker.com/martincodes/unity-editor-window-zooming/
|
||||
|
||||
public static Rect MultiplyRectSize(Rect rect, float amount)
|
||||
{
|
||||
Rect multipliedRect = new Rect(rect.x, rect.y, rect.width * amount, rect.height * amount);
|
||||
return multipliedRect;
|
||||
}
|
||||
|
||||
public static Rect MultiplyRectSizeAndCenter(Rect rect, float amount)
|
||||
{
|
||||
Rect multipliedRect = new Rect(rect.x, rect.y, rect.width * amount, rect.height * amount);
|
||||
multipliedRect.x = -(multipliedRect.width / 2);
|
||||
multipliedRect.y = -(multipliedRect.height / 2);
|
||||
return multipliedRect;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1ec1c2403bd92a84798e0ad68ebf4bad
|
||||
timeCreated: 1522671138
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,43 @@
|
||||
//https://github.com/maxartz15/MA_EditorUtils
|
||||
|
||||
//References:
|
||||
//http://martinecker.com/martincodes/unity-editor-window-zooming/
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using MA_Editor;
|
||||
using MA_Editor.RectUtils;
|
||||
|
||||
namespace MA_Editor.GUILayoutZoom
|
||||
{
|
||||
//http://martinecker.com/martincodes/unity-editor-window-zooming/
|
||||
public class GUILayoutZoom
|
||||
{
|
||||
private const float EditorWindowTabHeight = 21.0f; //The height of the editor window top bar. (were the name, zoom and exit buttons are)
|
||||
private static Matrix4x4 prevGuiMatrix;
|
||||
|
||||
public static Rect BeginArea(float zoomScale, Rect screenCoordsArea)
|
||||
{
|
||||
GUI.EndGroup(); // End the group Unity begins automatically for an EditorWindow to clip out the window tab. This allows us to draw outside of the size of the EditorWindow.
|
||||
|
||||
Rect clippedArea = screenCoordsArea.ScaleSizeBy(1.0f / zoomScale, screenCoordsArea.TopLeft());
|
||||
clippedArea.y += EditorWindowTabHeight;
|
||||
GUI.BeginGroup(clippedArea);
|
||||
|
||||
prevGuiMatrix = GUI.matrix;
|
||||
Matrix4x4 translation = Matrix4x4.TRS(clippedArea.TopLeft(), Quaternion.identity, Vector3.one);
|
||||
Matrix4x4 scale = Matrix4x4.Scale(new Vector3(zoomScale, zoomScale, 1.0f));
|
||||
GUI.matrix = translation * scale * translation.inverse * GUI.matrix;
|
||||
|
||||
return clippedArea;
|
||||
}
|
||||
|
||||
public static void EndArea()
|
||||
{
|
||||
GUI.matrix = prevGuiMatrix;
|
||||
GUI.EndGroup();
|
||||
GUI.BeginGroup(new Rect(0.0f, EditorWindowTabHeight, Screen.width, Screen.height));
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ea365137c05cbd64489983567390af51
|
||||
timeCreated: 1522669939
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user