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,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;
}
}
}