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,61 @@
//Maxartz15
//Version 1.0
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();
}
}
}

View File

@ -0,0 +1,70 @@
//Maxartz15
//Version 1.0
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;
}
}
}

View File

@ -0,0 +1,39 @@
//Maxartz15
//Version 1.0
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));
}
}
}