5 Commits
1.7 ... 1.7.3

Author SHA1 Message Date
max
521cb34541 Bugfixes: Texture width as height & build errors.
Bugfixes: Texture width as height typo and project build errors.
2020-01-14 19:42:30 +01:00
max
d8c59e86ca Corrected Unity version for prefab support.
UNITY_2018_4_OR_NEWER -> UNITY_2018_3_OR_NEWER
2019-11-29 00:12:04 +01:00
max
e894fcf797 Merge branch 'master' of https://github.com/maxartz15/MA_TextureAtlasser 2019-11-29 00:03:23 +01:00
max
0dfa466d78 Support old prefab system
Added support for the prefab system used before Unity 2018.
2019-11-29 00:03:18 +01:00
78f3daa145 Update README.md 2019-11-28 23:54:23 +01:00
8 changed files with 541 additions and 537 deletions

View File

@ -1,21 +1 @@
# MA_TextureAtlasser README: https://github.com/maxartz15/MA_TextureAtlasser/blob/master/README.md
Texture atlas creator for Unity
[![Image](https://maxartz15.com/wp-content/uploads/2019/04/MA_TextureAtlas.png)]()
You can combine textures and/or remap the UVs for the 3D models.
By having full control over the size and position of the textures that are being placed in the atlas you will never stand for surprises when exporting. This will cost some more time than auto-generating your texture atlases but you know whats going on and which models/textures are getting priority. The tool can also be used to make 2D sprite sheets.
- Combine textures/sprites.
- Automatically adjusts the UV's of the assigned meshes to match the new texture atlas.
- Exports meshes as OBJ.
- Exports texture atlas as PNG.
- Exports texture atlas as a (sliced) sprite sheet.
[Example video](https://youtu.be/PBRKlopkZP0)
Download the UnityPackage here: https://github.com/maxartz15/MA_TextureAtlasser/releases
[![Github All Releases](https://img.shields.io/github/downloads/maxartz15/MA_TextureAtlasser/total.svg)]()
For more information: https://maxartz15.com/ma-textureatlasser/

View File

@ -1,4 +1,5 @@
using UnityEngine; #if UNITY_EDITOR
using UnityEngine;
using System.Collections; using System.Collections;
using MA_Texture; using MA_Texture;
using System.Collections.Generic; using System.Collections.Generic;
@ -67,3 +68,4 @@ namespace MA_TextureAtlasserPro
SpriteSliced SpriteSliced
} }
} }
#endif

View File

@ -8,8 +8,6 @@ using MA_Texture;
namespace MA_TextureAtlasserPro namespace MA_TextureAtlasserPro
{ {
public static class MA_TextureAtlasserProUtils public static class MA_TextureAtlasserProUtils
{ {
public const string TEXTURE_ATLASSER_PATH = "Assets/MA_ToolBox/MA_TextureAtlasserPro/"; public const string TEXTURE_ATLASSER_PATH = "Assets/MA_ToolBox/MA_TextureAtlasserPro/";
@ -457,13 +455,14 @@ namespace MA_TextureAtlasserPro
newMesh = MA_MeshUtils.MA_DuplicateMesh(quad.meshes[m]); newMesh = MA_MeshUtils.MA_DuplicateMesh(quad.meshes[m]);
//Remap UV's //Remap UV's
newMesh = MA_MeshUtils.MA_UVReMap(newMesh, atlas.textureAtlasSize, quad.guiRect, modelExportSettings.uvChannel, modelExportSettings.uvFlipY, modelExportSettings.uvWrap); newMesh = MA_MeshUtils.MA_UVReMap(newMesh, atlas.textureAtlasSize, quad.guiRect, modelExportSettings.uvChannel, modelExportSettings.uvFlipY, modelExportSettings.uvWrap);
//Save it //Set name
string meshName = string.IsNullOrEmpty(quad.name) ? "" : quad.name + "-"; string meshName = string.IsNullOrEmpty(quad.name) ? "" : quad.name + "-";
meshName += quad.meshes[m].name; meshName += quad.meshes[m].name;
int n = m + 1; int n = m + 1;
meshName += "_" + n.ToString("#000"); meshName += "_" + n.ToString("#000");
newMesh.name = meshName;
string asset = MA_MeshUtils.MA_SaveMeshPrefab(newMesh, meshName, savePath, material: material); //Save it
string asset = MA_MeshUtils.MA_SaveMeshPrefab(newMesh, meshName, savePath, materialPath: material);
assetPaths.Add(asset); assetPaths.Add(asset);
} }
} }

View File

@ -17,58 +17,69 @@ namespace MA_Mesh
{ {
public static class MA_MeshUtils public static class MA_MeshUtils
{ {
public static string MA_SaveMeshAsset(Mesh mesh, string meshName, string savePath) public static string MA_SaveMeshAsset(Mesh mesh, string savePath)
{ {
Mesh newMesh = mesh; if (string.IsNullOrEmpty(mesh.name))
if(meshName == "")
{ {
newMesh.name = mesh.name; mesh.name = UnityEngine.Random.Range(11111, 99999).ToString();
}
else
{
newMesh.name = meshName;
} }
string assetPath = savePath + newMesh.name + ".asset"; string assetPath = savePath + mesh.name + ".asset";
AssetDatabase.CreateAsset(newMesh, assetPath); AssetDatabase.CreateAsset(mesh, assetPath);
AssetDatabase.SaveAssets(); AssetDatabase.SaveAssets();
return assetPath; return assetPath;
} }
public static string MA_SaveMeshPrefab(Mesh mesh, string meshName, string savePath, string material) public static string MA_SaveMeshPrefab(Mesh mesh, string prefabName, string savePath, string materialPath)
{ {
string assetPath = ""; string assetPath = null;
if (meshName == "") string meshAssetPath = MA_SaveMeshAsset(mesh, savePath);
{ Mesh meshAsset = AssetDatabase.LoadAssetAtPath<Mesh>(meshAssetPath);
meshName = mesh.name;
}
string meshPath = MA_SaveMeshAsset(mesh, meshName, savePath); if (meshAsset != null)
Mesh curMesh = AssetDatabase.LoadAssetAtPath<Mesh>(meshPath);
if (curMesh != null)
{ {
GameObject gameObject = new GameObject GameObject gameObject = new GameObject
{ {
name = meshName name = prefabName
}; };
gameObject.AddComponent<MeshFilter>().mesh = curMesh; gameObject.AddComponent<MeshFilter>().mesh = meshAsset;
gameObject.AddComponent<MeshRenderer>(); gameObject.AddComponent<MeshRenderer>();
Material curMaterial = AssetDatabase.LoadAssetAtPath<Material>(material); Material curMaterial = AssetDatabase.LoadAssetAtPath<Material>(materialPath);
if (curMaterial != null) if (curMaterial != null)
{ {
gameObject.GetComponent<MeshRenderer>().material = curMaterial; gameObject.GetComponent<MeshRenderer>().material = curMaterial;
} }
assetPath = savePath + meshName + ".prefab"; if (string.IsNullOrEmpty(prefabName))
{
prefabName = UnityEngine.Random.Range(11111, 99999).ToString();
}
assetPath = savePath + prefabName + ".prefab";
#if UNITY_2018_3_OR_NEWER
PrefabUtility.SaveAsPrefabAsset(gameObject, assetPath); PrefabUtility.SaveAsPrefabAsset(gameObject, assetPath);
#else
GameObject go = AssetDatabase.LoadAssetAtPath<GameObject>(assetPath);
if (go != null)
{
PrefabUtility.ReplacePrefab(gameObject, go, ReplacePrefabOptions.ReplaceNameBased);
}
else
{
PrefabUtility.CreatePrefab(assetPath, gameObject, ReplacePrefabOptions.ReplaceNameBased);
}
#endif
UnityEngine.GameObject.DestroyImmediate(gameObject); UnityEngine.GameObject.DestroyImmediate(gameObject);
} }

View File

@ -41,7 +41,7 @@ namespace MA_Texture
RenderTexture.active = tmp; RenderTexture.active = tmp;
// Create a new readable Texture2D to copy the pixels to it // Create a new readable Texture2D to copy the pixels to it
Texture2D myTexture2D = new Texture2D(texture.width, texture.width); Texture2D myTexture2D = new Texture2D(texture.width, texture.height);
// Copy the pixels from the RenderTexture to the new Texture // Copy the pixels from the RenderTexture to the new Texture
myTexture2D.ReadPixels(new Rect(0, 0, tmp.width, tmp.height), 0, 0); myTexture2D.ReadPixels(new Rect(0, 0, tmp.width, tmp.height), 0, 0);

View File

@ -1,7 +1,12 @@
{ {
"dependencies": { "dependencies": {
"com.unity.package-manager-ui": "2.1.2", "com.unity.2d.sprite": "1.0.0",
"com.unity.ext.nunit": "1.0.0",
"com.unity.package-manager-ui": "2.2.0",
"com.unity.test-framework": "1.0.13",
"com.unity.ugui": "1.0.0",
"com.unity.modules.ai": "1.0.0", "com.unity.modules.ai": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
"com.unity.modules.animation": "1.0.0", "com.unity.modules.animation": "1.0.0",
"com.unity.modules.assetbundle": "1.0.0", "com.unity.modules.assetbundle": "1.0.0",
"com.unity.modules.audio": "1.0.0", "com.unity.modules.audio": "1.0.0",

View File

@ -1,2 +1,2 @@
m_EditorVersion: 2019.1.10f1 m_EditorVersion: 2019.2.13f1
m_EditorVersionWithRevision: 2019.1.10f1 (f007ed779b7a) m_EditorVersionWithRevision: 2019.2.13f1 (e20f6c7e5017)

View File

@ -1,21 +1,28 @@
# MA_TextureAtlasser
Texture atlas creator for Unity
[![Image](https://maxartz15.com/wp-content/uploads/2019/04/MA_TextureAtlas.png)]() [![Image](https://maxartz15.com/wp-content/uploads/2019/04/MA_TextureAtlas.png)]()
You can combine textures and/or remap the UVs for the 3D models. # MA_TextureAtlasser
By having full control over the size and position of the textures that are being placed in the atlas you will never stand for surprises when exporting. This will cost some more time than auto-generating your texture atlases but you know whats going on and which models/textures are getting priority. The tool can also be used to make 2D sprite sheets. Texture atlas creator tool for Unity. <br> This tool is made to combine textures and/or remap the UVs for 3D models. The tool can also be used to make 2D sprite sheets. The visual editor gives you the ability to set and prioritize the sizes and positions in the texture atlas/sprite sheet.
- Combine textures/sprites. - Combine textures/sprites.
- Automatically adjusts the UV's of the assigned meshes to match the new texture atlas. - Automatically adjusts the UV's of the assigned meshes to match the new texture atlas.
- Exports meshes as OBJ.
- Exports texture atlas as PNG.
- Exports texture atlas as a (sliced) sprite sheet.
[Example video](https://youtu.be/PBRKlopkZP0)
Download the UnityPackage here: https://github.com/maxartz15/MA_TextureAtlasser/releases
### Download unitypackage
https://github.com/maxartz15/MA_TextureAtlasser/releases <br>
[![Github All Releases](https://img.shields.io/github/downloads/maxartz15/MA_TextureAtlasser/total.svg)]() [![Github All Releases](https://img.shields.io/github/downloads/maxartz15/MA_TextureAtlasser/total.svg)]()
For more information: https://maxartz15.com/ma-textureatlasser/ ### Tested Unity versions
[![Image](https://img.shields.io/badge/Unity-2017.4-green)]() [![Image](https://img.shields.io/badge/Unity-2018.4-green)]() [![Image](https://img.shields.io/badge/Unity-2019.2-green)]()
## Export options
### Meshes
- UnityMesh (with prefab setup)
- OBJ
- Replace orginal (this will replace the orginal model, make sure to backup before doing this!)
### Textures
- PNG
- PNG (sliced) sprite sheet
### Materials
- Material (with assigned textures and selected shader)
## Resources
[Youtube video](https://youtu.be/PBRKlopkZP0) <br>
[Website](https://maxartz15.com/ma-textureatlasser/)