mirror of
https://github.com/maxartz15/MA_TextureAtlasser.git
synced 2025-06-20 17:56:51 +02:00
Model groups.
Added model group support, you can now have multiple meshes in one export. Removed OBJ and mesh replace export options. Mesh replace didn't work, might get added again in the feature. OBJ needs to be rewritten as well to support the multiple meshes, and Unity now has model export options in engine. Version 1.8.0+ is now only supports Unity2018.3+.
This commit is contained in:
@ -96,9 +96,9 @@ namespace MA_TextureAtlasserPro
|
||||
exportAtlasGC.tooltip = "Opens the export window.";
|
||||
if (settings.useHotkeys)
|
||||
{
|
||||
createQuadGC.tooltip = string.Format("({0} + {1}), Creates a new quad.", settings.modifierKey, settings.addQuadHotKey);
|
||||
removeQuadGC.tooltip = string.Format("({0} + {1}), Removes the selected quad.", settings.modifierKey, settings.removeQuadHotKey);
|
||||
duplicateQuadGC.tooltip = string.Format("({0} + {1}), Duplicates the selected quad.", settings.modifierKey, settings.duplicateHotKey);
|
||||
createQuadGC.tooltip = string.Format("({0}+{1}), Creates a new quad.", settings.modifierKey, settings.addQuadHotKey);
|
||||
removeQuadGC.tooltip = string.Format("({0}+{1}), Removes the selected quad.", settings.modifierKey, settings.removeQuadHotKey);
|
||||
duplicateQuadGC.tooltip = string.Format("({0}+{1}), Duplicates the selected quad.", settings.modifierKey, settings.duplicateHotKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -5,6 +5,8 @@ using UnityEngine;
|
||||
using UnityEditor;
|
||||
using MA_Mesh;
|
||||
using MA_Texture;
|
||||
using MA_Toolbox.Utils.Editor;
|
||||
using MA_Toolbox.Utils;
|
||||
|
||||
namespace MA_TextureAtlasserPro
|
||||
{
|
||||
@ -259,25 +261,16 @@ namespace MA_TextureAtlasserPro
|
||||
}
|
||||
}
|
||||
|
||||
public static void DuplicateTextureQuad(MA_TextureAtlasserProAtlas atlas, bool focus = true, bool copyData = false, string namePrefix = "new ")
|
||||
public static void DuplicateTextureQuad(MA_TextureAtlasserProAtlas atlas, bool focus = true, string namePrefix = "new ")
|
||||
{
|
||||
if (atlas != null && atlas.selectedTextureQuad != null)
|
||||
{
|
||||
MA_TextureAtlasserProQuad q = CreateTextureQuad(atlas, namePrefix + atlas.selectedTextureQuad.name, atlas.selectedTextureQuad.rect, false);
|
||||
//MA_TextureAtlasserProQuad q = CreateTextureQuad(atlas, namePrefix + atlas.selectedTextureQuad.name, atlas.selectedTextureQuad.rect, false);
|
||||
MA_TextureAtlasserProQuad q = Object.Instantiate(atlas.selectedTextureQuad);
|
||||
q.name = string.Format("{0}{1}", namePrefix, atlas.selectedTextureQuad.name);
|
||||
atlas.textureQuads.Add(q);
|
||||
|
||||
if (copyData)
|
||||
{
|
||||
q.meshes = new List<Mesh>();
|
||||
for (int i = 0; i < atlas.selectedTextureQuad.meshes.Count; i++)
|
||||
{
|
||||
q.meshes.Add(atlas.selectedTextureQuad.meshes[i]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < atlas.selectedTextureQuad.textureGroups.Count; i++)
|
||||
{
|
||||
q.textureGroups[i].texture = atlas.selectedTextureQuad.textureGroups[i].texture;
|
||||
}
|
||||
}
|
||||
AssetDatabase.AddObjectToAsset(q, atlas);
|
||||
|
||||
if (focus)
|
||||
{
|
||||
@ -365,6 +358,12 @@ namespace MA_TextureAtlasserPro
|
||||
if (!AssetDatabase.IsValidFolder(folderPath))
|
||||
{
|
||||
string parentPath = folderPath.Substring(0, folderPath.LastIndexOf('/'));
|
||||
|
||||
if(!AssetDatabase.IsValidFolder(parentPath))
|
||||
{
|
||||
CreateFolder(parentPath);
|
||||
}
|
||||
|
||||
string folderName = folderPath.Substring(folderPath.LastIndexOf('/') + 1);
|
||||
|
||||
AssetDatabase.CreateFolder(parentPath, folderName);
|
||||
@ -387,19 +386,16 @@ namespace MA_TextureAtlasserPro
|
||||
}
|
||||
|
||||
#region Export
|
||||
public static string[] ExportAtlasModels(MA_TextureAtlasserProAtlas atlas, ModelExportSettings modelExportSettings, string material = null, string savePath = EXPORT_ASSET_PATH)
|
||||
public static string[] ExportAtlasModels(MA_TextureAtlasserProAtlas atlas, ModelExportSettings modelExportSettings, string materialPath = null, string savePath = EXPORT_ASSET_PATH)
|
||||
{
|
||||
switch (modelExportSettings.modelFormat)
|
||||
{
|
||||
case ModelFormat.None:
|
||||
break;
|
||||
case ModelFormat.ReplaceMesh:
|
||||
ReplaceAtlasMesh(atlas, modelExportSettings, savePath: savePath);
|
||||
break;
|
||||
case ModelFormat.UnityMeshPrefab:
|
||||
return ExportAtlasUnityMeshPrefab(atlas, modelExportSettings, material: material, savePath: savePath);
|
||||
case ModelFormat.Obj:
|
||||
return ExportAtlasObj(atlas, modelExportSettings, savePath: savePath);
|
||||
return ExportAtlasUnityMeshPrefab(atlas, modelExportSettings, materialPath: materialPath, savePath: savePath);
|
||||
//case ModelFormat.Obj:
|
||||
// return ExportAtlasObj(atlas, modelExportSettings, savePath: savePath);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -407,103 +403,78 @@ namespace MA_TextureAtlasserPro
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void ReplaceAtlasMesh(MA_TextureAtlasserProAtlas atlas, ModelExportSettings modelExportSettings, string savePath = EXPORT_ASSET_PATH)
|
||||
private static string[] ExportAtlasUnityMeshPrefab(MA_TextureAtlasserProAtlas atlas, ModelExportSettings modelExportSettings, string materialPath = null, string savePath = EXPORT_ASSET_PATH)
|
||||
{
|
||||
if (atlas == null || atlas.textureQuads == null)
|
||||
return;
|
||||
|
||||
var quads = atlas.textureQuads;
|
||||
for (var index = 0; index < quads.Count; index++)
|
||||
{
|
||||
var quad = quads[index];
|
||||
if (quad.meshes == null)
|
||||
continue;
|
||||
|
||||
var meshes = quad.meshes;
|
||||
for (var meshIndex = 0; meshIndex < quad.meshes.Count; meshIndex++)
|
||||
{
|
||||
if (meshes[meshIndex] == null)
|
||||
continue;
|
||||
|
||||
MA_MeshUtils.MA_UVReMap(meshes[meshIndex], atlas.textureAtlasSize, quad.guiRect, modelExportSettings.uvChannel, modelExportSettings.uvFlipY, modelExportSettings.uvWrap);
|
||||
EditorUtility.SetDirty(meshes[meshIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
|
||||
private static string[] ExportAtlasUnityMeshPrefab(MA_TextureAtlasserProAtlas atlas, ModelExportSettings modelExportSettings, string material = null, string savePath = EXPORT_ASSET_PATH)
|
||||
{
|
||||
if (atlas == null || atlas.textureQuads == null)
|
||||
return null;
|
||||
}
|
||||
|
||||
List<string> assetPaths = new List<string>();
|
||||
|
||||
foreach (MA_TextureAtlasserProQuad quad in atlas.textureQuads)
|
||||
{
|
||||
//Export Mesh
|
||||
if (quad.meshes != null)
|
||||
{
|
||||
for (int m = 0; m < quad.meshes.Count; m++)
|
||||
{
|
||||
if (quad.meshes[m] != null)
|
||||
{
|
||||
//Create new mesh
|
||||
Mesh newMesh = new Mesh();
|
||||
//Duplicate it from the current one
|
||||
newMesh = MA_MeshUtils.MA_DuplicateMesh(quad.meshes[m]);
|
||||
//Remap UV's
|
||||
newMesh = MA_MeshUtils.MA_UVReMap(newMesh, atlas.textureAtlasSize, quad.guiRect, modelExportSettings.uvChannel, modelExportSettings.uvFlipY, modelExportSettings.uvWrap);
|
||||
//Set name
|
||||
string meshName = string.IsNullOrEmpty(quad.name) ? "" : quad.name + "-";
|
||||
meshName += quad.meshes[m].name;
|
||||
int n = m + 1;
|
||||
meshName += "_" + n.ToString("#000");
|
||||
newMesh.name = meshName;
|
||||
//Save it
|
||||
string asset = MA_MeshUtils.MA_SaveMeshPrefab(newMesh, meshName, savePath, materialPath: material);
|
||||
assetPaths.Add(asset);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return assetPaths.ToArray();
|
||||
}
|
||||
|
||||
private static string[] ExportAtlasObj(MA_TextureAtlasserProAtlas atlas, ModelExportSettings modelExportSettings, string savePath = EXPORT_ASSET_PATH)
|
||||
{
|
||||
if (atlas == null || atlas.textureQuads == null)
|
||||
return null;
|
||||
|
||||
List<string> assetPaths = new List<string>();
|
||||
//Directories.
|
||||
string savePathPrefab = savePath + atlas.name + "/";
|
||||
string savePathMeshes = savePathPrefab + "Meshes/";
|
||||
CreateFolder(savePathPrefab);
|
||||
CreateFolder(savePathMeshes);
|
||||
|
||||
foreach (MA_TextureAtlasserProQuad quad in atlas.textureQuads)
|
||||
{
|
||||
//Export Mesh
|
||||
if (quad.meshes != null)
|
||||
foreach (MA_ModelGroup mg in quad.modelGroups)
|
||||
{
|
||||
for (int m = 0; m < quad.meshes.Count; m++)
|
||||
//Validate name.
|
||||
if (string.IsNullOrEmpty(mg.name) || string.IsNullOrWhiteSpace(mg.name))
|
||||
{
|
||||
if (quad.meshes[m] != null)
|
||||
{
|
||||
//Create new mesh
|
||||
Mesh newMesh = new Mesh();
|
||||
//Duplicate it from the current one
|
||||
newMesh = MA_MeshUtils.MA_DuplicateMesh(quad.meshes[m]);
|
||||
//Remap UV's
|
||||
newMesh = MA_MeshUtils.MA_UVReMap(newMesh, atlas.textureAtlasSize, quad.guiRect, modelExportSettings.uvChannel, modelExportSettings.uvFlipY, modelExportSettings.uvWrap);
|
||||
//Save it
|
||||
string meshName = string.IsNullOrEmpty(quad.name) ? "" : quad.name + "-";
|
||||
meshName += quad.meshes[m].name;
|
||||
int n = m + 1;
|
||||
meshName += "_" + n.ToString("#000");
|
||||
mg.name = MA_StringUtils.RandomAlphabetString(6);
|
||||
Debug.LogWarning("No valid model name assigned!");
|
||||
}
|
||||
|
||||
string asset = MA_MeshUtils.MeshToFile(newMesh, meshName, savePath);
|
||||
assetPaths.Add(asset);
|
||||
//Create new prefab asset.
|
||||
string newPrefabPath = MA_PrefabUtils.CreatePrefab(mg.name, savePathPrefab);
|
||||
GameObject newPrefab = AssetDatabase.LoadAssetAtPath<GameObject>(newPrefabPath);
|
||||
|
||||
foreach (Mesh m in mg.meshes)
|
||||
{
|
||||
if(m != null)
|
||||
{
|
||||
//Validate name.
|
||||
if (string.IsNullOrEmpty(m.name) || string.IsNullOrWhiteSpace(m.name))
|
||||
{
|
||||
m.name = MA_StringUtils.RandomAlphabetString(6);
|
||||
Debug.LogWarning("No valid mesh name assigned!");
|
||||
}
|
||||
|
||||
//Create new mesh.
|
||||
//Duplicate it from the current one.
|
||||
Mesh newMesh = MA_MeshUtils.MA_DuplicateMesh(m);
|
||||
//Remap UV's.
|
||||
newMesh = MA_MeshUtils.MA_UVReMap(newMesh, atlas.textureAtlasSize, quad.guiRect, modelExportSettings.uvChannel, modelExportSettings.uvFlipY, modelExportSettings.uvWrap);
|
||||
//Set name.
|
||||
newMesh.name = string.Format("{0}_{1}", mg.name, m.name);
|
||||
//Save mesh.
|
||||
string savedMeshPath = MA_MeshUtils.MA_SaveMeshAsset(newMesh, savePathMeshes);
|
||||
|
||||
//Load mesh.
|
||||
Mesh savedMesh = AssetDatabase.LoadAssetAtPath<Mesh>(savedMeshPath);
|
||||
//Load material.
|
||||
Material savedMaterial = AssetDatabase.LoadAssetAtPath<Material>(materialPath);
|
||||
|
||||
//Create gameObject.
|
||||
GameObject newGameObject = new GameObject(m.name);
|
||||
//Add mesh filter.
|
||||
MeshFilter mf = newGameObject.AddComponent<MeshFilter>();
|
||||
mf.mesh = savedMesh;
|
||||
//Add mesh renderer.
|
||||
MeshRenderer mr = newGameObject.AddComponent<MeshRenderer>();
|
||||
mr.material = savedMaterial;
|
||||
|
||||
//Add to parent gameObject (prefab).
|
||||
MA_PrefabUtils.AddChild(newPrefab, newGameObject);
|
||||
Object.DestroyImmediate(newGameObject);
|
||||
}
|
||||
}
|
||||
|
||||
assetPaths.Add(newPrefabPath);
|
||||
}
|
||||
}
|
||||
|
||||
@ -528,10 +499,16 @@ namespace MA_TextureAtlasserPro
|
||||
private static string[] ExportAtlasPNG(MA_TextureAtlasserProAtlas atlas, TextureExportSettings textureExportSettings, string savePath = EXPORT_ASSET_PATH, string tempPath = TEMP_ASSET_PATH)
|
||||
{
|
||||
if (atlas == null || atlas.textureQuads == null || atlas.textureGroupRegistration == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
string[] assetPaths = new string[atlas.textureGroupRegistration.Count];
|
||||
|
||||
//Directories.
|
||||
string savePathTextures = savePath + atlas.name + "/Textures/";
|
||||
CreateFolder(savePathTextures);
|
||||
|
||||
//Create temp folder
|
||||
CreateFolder(tempPath);
|
||||
|
||||
@ -582,25 +559,24 @@ namespace MA_TextureAtlasserPro
|
||||
}
|
||||
|
||||
//Save it
|
||||
newTexture.MA_Save2D(newTexture.name, savePath);
|
||||
|
||||
assetPaths[i] = (savePath + newTexture.name + '.' + textureExportSettings.textureFormat.ToString());
|
||||
newTexture.MA_Save2D(newTexture.name, savePathTextures);
|
||||
assetPaths[i] = (savePathTextures + newTexture.name + '.' + textureExportSettings.textureFormat.ToString());
|
||||
|
||||
//Set settings.
|
||||
switch (textureExportSettings.textureType)
|
||||
{
|
||||
case TextureType.Default:
|
||||
{
|
||||
TextureImporter textureImporter = (TextureImporter)AssetImporter.GetAtPath(savePath + newTexture.name + '.' + textureExportSettings.textureFormat.ToString());
|
||||
TextureImporter textureImporter = (TextureImporter)AssetImporter.GetAtPath(savePathTextures + newTexture.name + '.' + textureExportSettings.textureFormat.ToString());
|
||||
textureImporter.textureType = TextureImporterType.Default;
|
||||
textureImporter.SaveAndReimport();
|
||||
}
|
||||
break;
|
||||
case TextureType.Sprite:
|
||||
SetAtlasSpriteSettings(atlas, textureExportSettings, savePath);
|
||||
SetAtlasSpriteSettings(atlas, textureExportSettings, savePathTextures);
|
||||
break;
|
||||
case TextureType.SpriteSliced:
|
||||
SetAtlasSpriteSettings(atlas, textureExportSettings, savePath);
|
||||
SetAtlasSpriteSettings(atlas, textureExportSettings, savePathTextures);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -616,7 +592,7 @@ namespace MA_TextureAtlasserPro
|
||||
return assetPaths;
|
||||
}
|
||||
|
||||
private static void SetAtlasSpriteSettings(MA_TextureAtlasserProAtlas atlas, TextureExportSettings textureExportSettings, string savePath = EXPORT_ASSET_PATH)
|
||||
private static void SetAtlasSpriteSettings(MA_TextureAtlasserProAtlas atlas, TextureExportSettings textureExportSettings, string savePath)
|
||||
{
|
||||
//Foreach texture group
|
||||
for (int i = 0; i < atlas.textureGroupRegistration.Count; i++)
|
||||
@ -663,9 +639,13 @@ namespace MA_TextureAtlasserPro
|
||||
public static string ExportAtlasMaterial(MA_TextureAtlasserProAtlas atlas, MaterialExportSettings materialExportSettings, string[] textures = null, string savePath = EXPORT_ASSET_PATH)
|
||||
{
|
||||
if (atlas == null || atlas.textureQuads == null || atlas.textureGroupRegistration == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
string assetPath = "";
|
||||
//Directories.
|
||||
string savePathMaterial = savePath + atlas.name + "/Materials/";
|
||||
CreateFolder(savePathMaterial);
|
||||
|
||||
Shader shader = materialExportSettings.shader;
|
||||
if (shader)
|
||||
@ -687,14 +667,16 @@ namespace MA_TextureAtlasserPro
|
||||
}
|
||||
}
|
||||
|
||||
assetPath = savePath + material.name + ".mat";
|
||||
string assetPath = savePathMaterial + material.name + ".mat";
|
||||
|
||||
//Save material
|
||||
AssetDatabase.CreateAsset(material, assetPath);
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
return assetPath;
|
||||
}
|
||||
|
||||
return assetPath;
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
@ -4,22 +4,19 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using MA_Editor;
|
||||
using MA_Toolbox.Utils;
|
||||
|
||||
namespace MA_TextureAtlasserPro
|
||||
{
|
||||
public class MA_TextureAtlasserProInspectorView : MA_TextureAtlasserProViewBase
|
||||
public class MA_TextureAtlasserProInspectorView : MA_TextureAtlasserProViewBase
|
||||
{
|
||||
private MA_TextureAtlasserProQuad lastSelectedQuad;
|
||||
|
||||
private bool isEditing = false;
|
||||
|
||||
private bool isEditing = false;
|
||||
private GUIStyle labelStyle = new GUIStyle(GUI.skin.label);
|
||||
|
||||
bool useAddMeshButton = false;
|
||||
|
||||
public MA_TextureAtlasserProInspectorView(MA_TextureAtlasserProWindow currentEditorWindow, string title) : base(currentEditorWindow, title)
|
||||
public MA_TextureAtlasserProInspectorView(MA_TextureAtlasserProWindow currentEditorWindow, string title) : base(currentEditorWindow, title)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override void UpdateView(Event e, Rect editorViewRect)
|
||||
@ -27,32 +24,19 @@ namespace MA_TextureAtlasserPro
|
||||
//Update base derived class
|
||||
base.UpdateView(e, editorViewRect);
|
||||
|
||||
if(isLoaded)
|
||||
if (isLoaded)
|
||||
{
|
||||
//Draw inspector
|
||||
if(curWindow.textureAtlas != null && curWindow.textureAtlas.selectedTextureQuad != null)
|
||||
if (curWindow.textureAtlas != null && curWindow.textureAtlas.selectedTextureQuad != null)
|
||||
{
|
||||
//Change layout during layout event to prevent gui errors
|
||||
if (e.type == EventType.Layout)
|
||||
{
|
||||
if (curWindow.textureAtlas.selectedTextureQuad.meshes != null && curWindow.textureAtlas.selectedTextureQuad.meshes.Count == 0)
|
||||
{
|
||||
useAddMeshButton = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
useAddMeshButton = false;
|
||||
}
|
||||
}
|
||||
|
||||
//Deselect GUI elements when we are focusing on a new quad
|
||||
if (lastSelectedQuad != curWindow.textureAtlas.selectedTextureQuad)
|
||||
//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.BeginArea(editorViewRect, EditorStyles.helpBox);
|
||||
GUILayout.BeginVertical(GUILayout.ExpandWidth(true));
|
||||
|
||||
GUILayout.Label("Quad Name");
|
||||
@ -63,21 +47,21 @@ namespace MA_TextureAtlasserPro
|
||||
//Textures
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Label("Textures", GUILayout.ExpandWidth(true));
|
||||
if(GUILayout.Button(MA_TextureAtlasserProGuiLoader.editGC, EditorStyles.miniButton, GUILayout.Width(36), GUILayout.Height(15)))
|
||||
if (GUILayout.Button(MA_TextureAtlasserProGuiLoader.editGC, EditorStyles.miniButton, GUILayout.Width(36), GUILayout.Height(15)))
|
||||
{
|
||||
isEditing = !isEditing;
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
if(curWindow.textureAtlas.textureGroupRegistration == null || curWindow.textureAtlas.textureGroupRegistration.Count == 0)
|
||||
if (curWindow.textureAtlas.textureGroupRegistration == null || curWindow.textureAtlas.textureGroupRegistration.Count == 0)
|
||||
{
|
||||
if(GUILayout.Button("+", EditorStyles.miniButton, GUILayout.ExpandWidth(true)))
|
||||
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)
|
||||
if (isEditing)
|
||||
{
|
||||
curWindow.textureAtlas.textureGroupRegistration[i].name = curWindow.textureAtlas.selectedTextureQuad.textureGroups[i].name = EditorGUILayout.TextField(curWindow.textureAtlas.textureGroupRegistration[i].name);
|
||||
}
|
||||
@ -87,11 +71,11 @@ namespace MA_TextureAtlasserPro
|
||||
}
|
||||
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)))
|
||||
if (isEditing && GUILayout.Button("-", EditorStyles.miniButtonLeft, GUILayout.ExpandWidth(false)))
|
||||
{
|
||||
MA_TextureAtlasserProUtils.RemoveTextureGroup(curWindow.textureAtlas, i);
|
||||
}
|
||||
if(isEditing && GUILayout.Button("+", EditorStyles.miniButtonRight, GUILayout.ExpandWidth(false)))
|
||||
if (isEditing && GUILayout.Button("+", EditorStyles.miniButtonRight, GUILayout.ExpandWidth(false)))
|
||||
{
|
||||
MA_TextureAtlasserProUtils.CreateTextureGroup(curWindow.textureAtlas, "New TextureGroup");
|
||||
}
|
||||
@ -100,58 +84,90 @@ namespace MA_TextureAtlasserPro
|
||||
|
||||
GUILayout.Space(MA_TextureAtlasserProUtils.VIEW_OFFSET / 2);
|
||||
|
||||
//Meshes
|
||||
GUILayout.Label("Meshes");
|
||||
if (useAddMeshButton)
|
||||
{
|
||||
//Models
|
||||
GUILayout.Label("Models");
|
||||
|
||||
SerializedObject serializedObject = new SerializedObject(curWindow.textureAtlas.selectedTextureQuad);
|
||||
serializedObject.Update();
|
||||
|
||||
if (curWindow.textureAtlas.selectedTextureQuad.modelGroups != null)
|
||||
{
|
||||
SerializedProperty modelGroupsSP = serializedObject.FindProperty("modelGroups");
|
||||
|
||||
for (int i = 0; i < curWindow.textureAtlas.selectedTextureQuad.modelGroups.Count; i++)
|
||||
{
|
||||
using (new GUILayout.VerticalScope(EditorStyles.helpBox))
|
||||
{
|
||||
using (new GUILayout.HorizontalScope())
|
||||
{
|
||||
curWindow.textureAtlas.selectedTextureQuad.modelGroups[i].name = EditorGUILayout.TextField(curWindow.textureAtlas.selectedTextureQuad.modelGroups[i].name);
|
||||
if (GUILayout.Button("-", EditorStyles.miniButton, GUILayout.ExpandWidth(true)))
|
||||
{
|
||||
curWindow.textureAtlas.selectedTextureQuad.modelGroups.RemoveAt(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SerializedProperty meshesSP = modelGroupsSP.GetArrayElementAtIndex(i).FindPropertyRelative("meshes");
|
||||
EditorGUILayout.PropertyField(meshesSP, false, GUILayout.ExpandWidth(false), GUILayout.MaxWidth(editorViewRect.width * 0.5f));
|
||||
|
||||
if (meshesSP.isExpanded)
|
||||
{
|
||||
for (int j = 0; j < curWindow.textureAtlas.selectedTextureQuad.modelGroups[i].meshes.Count; j++)
|
||||
{
|
||||
using (new GUILayout.HorizontalScope())
|
||||
{
|
||||
curWindow.textureAtlas.selectedTextureQuad.modelGroups[i].meshes[j] = (Mesh)EditorGUILayout.ObjectField(curWindow.textureAtlas.selectedTextureQuad.modelGroups[i].meshes[j], typeof(Mesh), false);
|
||||
if (GUILayout.Button("-", EditorStyles.miniButton, GUILayout.ExpandWidth(true)))
|
||||
{
|
||||
curWindow.textureAtlas.selectedTextureQuad.modelGroups[i].meshes.RemoveAt(j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (GUILayout.Button("+", EditorStyles.miniButton))
|
||||
{
|
||||
curWindow.textureAtlas.selectedTextureQuad.modelGroups[i].meshes.Add(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (GUILayout.Button("+", EditorStyles.miniButton, GUILayout.ExpandWidth(true)))
|
||||
{
|
||||
curWindow.textureAtlas.selectedTextureQuad.meshes.Add(null);
|
||||
curWindow.textureAtlas.selectedTextureQuad.modelGroups.Add(new MA_ModelGroup() { name = MA_StringUtils.RandomAlphabetString(6) });
|
||||
}
|
||||
}
|
||||
|
||||
if (curWindow.textureAtlas.selectedTextureQuad.meshes != null)
|
||||
else
|
||||
{
|
||||
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 + 1, null);
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
curWindow.textureAtlas.selectedTextureQuad.modelGroups = new List<MA_ModelGroup>();
|
||||
}
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
GUILayout.Space(MA_TextureAtlasserProUtils.VIEW_OFFSET / 2);
|
||||
|
||||
//x, y, w, h.
|
||||
GUILayout.FlexibleSpace();
|
||||
if (!MA_TextureAtlasserProUtils.IsPowerOfTwo((int)curWindow.textureAtlas.selectedTextureQuad.guiRect.width) || !MA_TextureAtlasserProUtils.IsPowerOfTwo((int)curWindow.textureAtlas.selectedTextureQuad.guiRect.height))
|
||||
{
|
||||
labelStyle.normal.textColor = Color.red;
|
||||
}
|
||||
else
|
||||
{
|
||||
curWindow.textureAtlas.selectedTextureQuad.meshes = new List<Mesh>();
|
||||
labelStyle.normal.textColor = GUI.skin.label.normal.textColor;
|
||||
}
|
||||
|
||||
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(), labelStyle);
|
||||
|
||||
GUILayout.FlexibleSpace();
|
||||
if (!MA_TextureAtlasserProUtils.IsPowerOfTwo((int)curWindow.textureAtlas.selectedTextureQuad.guiRect.width) || !MA_TextureAtlasserProUtils.IsPowerOfTwo((int)curWindow.textureAtlas.selectedTextureQuad.guiRect.height))
|
||||
{
|
||||
labelStyle.normal.textColor = Color.red;
|
||||
}
|
||||
else
|
||||
{
|
||||
labelStyle.normal.textColor = GUI.skin.label.normal.textColor;
|
||||
}
|
||||
|
||||
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(), labelStyle);
|
||||
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.EndArea();
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.EndArea();
|
||||
}
|
||||
}
|
||||
|
||||
if(curWindow.textureAtlas != null && curWindow.textureAtlas.selectedTextureQuad != null)
|
||||
if (curWindow.textureAtlas != null && curWindow.textureAtlas.selectedTextureQuad != null)
|
||||
ProcessEvents(e, editorViewRect);
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ namespace MA_TextureAtlasserPro
|
||||
if (curWindow.textureAtlas.selectedTextureQuad != null && GUILayout.Button(MA_TextureAtlasserProGuiLoader.duplicateQuadGC, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
|
||||
{
|
||||
if (curWindow.textureAtlas.selectedTextureQuad != null)
|
||||
MA_TextureAtlasserProUtils.DuplicateTextureQuad(curWindow.textureAtlas, curWindow.settings.autoFocus, curWindow.settings.copySelectedQuadData, curWindow.settings.duplicatedQuadNamePrefix);
|
||||
MA_TextureAtlasserProUtils.DuplicateTextureQuad(curWindow.textureAtlas, curWindow.settings.autoFocus, curWindow.settings.duplicatedQuadNamePrefix);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,7 +91,7 @@ namespace MA_TextureAtlasserPro
|
||||
e.Use();
|
||||
}
|
||||
|
||||
//Hotkeys.
|
||||
//HotKeys.
|
||||
if (curWindow.settings.useHotkeys)
|
||||
{
|
||||
if(curWindow.textureAtlas != null)
|
||||
@ -123,7 +123,7 @@ namespace MA_TextureAtlasserPro
|
||||
|
||||
if (curWindow.settings.GetHotKey(e, curWindow.settings.duplicateHotKey))
|
||||
{
|
||||
MA_TextureAtlasserProUtils.DuplicateTextureQuad(curWindow.textureAtlas, curWindow.settings.autoFocus, curWindow.settings.copySelectedQuadData, curWindow.settings.duplicatedQuadNamePrefix);
|
||||
MA_TextureAtlasserProUtils.DuplicateTextureQuad(curWindow.textureAtlas, curWindow.settings.autoFocus, curWindow.settings.duplicatedQuadNamePrefix);
|
||||
e.Use();
|
||||
}
|
||||
}
|
||||
|
@ -154,40 +154,23 @@ namespace MA_TextureAtlasserPro
|
||||
|
||||
if (GUILayout.Button("Export", GUILayout.ExpandWidth(true), GUILayout.Height(37)))
|
||||
{
|
||||
bool export = false;
|
||||
string[] textures = null;
|
||||
string material = null;
|
||||
string[] models = null;
|
||||
|
||||
if(curWindow.textureAtlas.exportSettings.modelExportSettings.modelFormat == ModelFormat.ReplaceMesh)
|
||||
if (curWindow.textureAtlas.exportSettings.exportTextures)
|
||||
{
|
||||
if(EditorUtility.DisplayDialog("Replace original models?", "Are you sure you want to replace the original models, this can't be undone!", "Replace", "Cancel"))
|
||||
{
|
||||
export = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
export = true;
|
||||
textures = MA_TextureAtlasserProUtils.ExportAtlasTextures(curWindow.textureAtlas, curWindow.textureAtlas.exportSettings.textureExportSettings);
|
||||
}
|
||||
|
||||
if(export)
|
||||
if (curWindow.textureAtlas.exportSettings.exportMaterials)
|
||||
{
|
||||
string[] textures = null;
|
||||
string material = null;
|
||||
string[] models = null;
|
||||
material = MA_TextureAtlasserProUtils.ExportAtlasMaterial(curWindow.textureAtlas, curWindow.textureAtlas.exportSettings.materialExportSettings, textures: textures);
|
||||
}
|
||||
|
||||
if (curWindow.textureAtlas.exportSettings.exportTextures)
|
||||
{
|
||||
textures = MA_TextureAtlasserProUtils.ExportAtlasTextures(curWindow.textureAtlas, curWindow.textureAtlas.exportSettings.textureExportSettings);
|
||||
}
|
||||
|
||||
if(curWindow.textureAtlas.exportSettings.exportMaterials)
|
||||
{
|
||||
material = MA_TextureAtlasserProUtils.ExportAtlasMaterial(curWindow.textureAtlas, curWindow.textureAtlas.exportSettings.materialExportSettings, textures: textures);
|
||||
}
|
||||
|
||||
if(curWindow.textureAtlas.exportSettings.exportModels)
|
||||
{
|
||||
models = MA_TextureAtlasserProUtils.ExportAtlasModels(curWindow.textureAtlas, curWindow.textureAtlas.exportSettings.modelExportSettings, material: material);
|
||||
}
|
||||
if (curWindow.textureAtlas.exportSettings.exportModels)
|
||||
{
|
||||
models = MA_TextureAtlasserProUtils.ExportAtlasModels(curWindow.textureAtlas, curWindow.textureAtlas.exportSettings.modelExportSettings, materialPath: material);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user