mirror of
https://github.com/maxartz15/MA_TextureAtlasser.git
synced 2024-11-21 21:05:38 +01:00
Support old prefab system
Added support for the prefab system used before Unity 2018.
This commit is contained in:
parent
406720d718
commit
0dfa466d78
@ -1,21 +1 @@
|
||||
# MA_TextureAtlasser
|
||||
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 UV’s 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/
|
||||
README: https://github.com/maxartz15/MA_TextureAtlasser/blob/master/README.md
|
||||
|
@ -8,8 +8,6 @@ using MA_Texture;
|
||||
|
||||
namespace MA_TextureAtlasserPro
|
||||
{
|
||||
|
||||
|
||||
public static class MA_TextureAtlasserProUtils
|
||||
{
|
||||
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]);
|
||||
//Remap UV's
|
||||
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 + "-";
|
||||
meshName += quad.meshes[m].name;
|
||||
int n = m + 1;
|
||||
meshName += "_" + n.ToString("#000");
|
||||
|
||||
string asset = MA_MeshUtils.MA_SaveMeshPrefab(newMesh, meshName, savePath, material: material);
|
||||
newMesh.name = meshName;
|
||||
//Save it
|
||||
string asset = MA_MeshUtils.MA_SaveMeshPrefab(newMesh, meshName, savePath, materialPath: material);
|
||||
assetPaths.Add(asset);
|
||||
}
|
||||
}
|
||||
|
@ -17,58 +17,69 @@ namespace MA_Mesh
|
||||
{
|
||||
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(meshName == "")
|
||||
if (string.IsNullOrEmpty(mesh.name))
|
||||
{
|
||||
newMesh.name = mesh.name;
|
||||
}
|
||||
else
|
||||
{
|
||||
newMesh.name = meshName;
|
||||
mesh.name = UnityEngine.Random.Range(11111, 99999).ToString();
|
||||
}
|
||||
|
||||
string assetPath = savePath + newMesh.name + ".asset";
|
||||
string assetPath = savePath + mesh.name + ".asset";
|
||||
|
||||
AssetDatabase.CreateAsset(newMesh, assetPath);
|
||||
AssetDatabase.CreateAsset(mesh, assetPath);
|
||||
AssetDatabase.SaveAssets();
|
||||
|
||||
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 == "")
|
||||
{
|
||||
meshName = mesh.name;
|
||||
}
|
||||
string meshAssetPath = MA_SaveMeshAsset(mesh, savePath);
|
||||
Mesh meshAsset = AssetDatabase.LoadAssetAtPath<Mesh>(meshAssetPath);
|
||||
|
||||
string meshPath = MA_SaveMeshAsset(mesh, meshName, savePath);
|
||||
Mesh curMesh = AssetDatabase.LoadAssetAtPath<Mesh>(meshPath);
|
||||
|
||||
if (curMesh != null)
|
||||
if (meshAsset != null)
|
||||
{
|
||||
GameObject gameObject = new GameObject
|
||||
{
|
||||
name = meshName
|
||||
name = prefabName
|
||||
};
|
||||
|
||||
gameObject.AddComponent<MeshFilter>().mesh = curMesh;
|
||||
gameObject.AddComponent<MeshFilter>().mesh = meshAsset;
|
||||
gameObject.AddComponent<MeshRenderer>();
|
||||
|
||||
Material curMaterial = AssetDatabase.LoadAssetAtPath<Material>(material);
|
||||
Material curMaterial = AssetDatabase.LoadAssetAtPath<Material>(materialPath);
|
||||
if (curMaterial != null)
|
||||
{
|
||||
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_4_OR_NEWER
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,12 @@
|
||||
{
|
||||
"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.androidjni": "1.0.0",
|
||||
"com.unity.modules.animation": "1.0.0",
|
||||
"com.unity.modules.assetbundle": "1.0.0",
|
||||
"com.unity.modules.audio": "1.0.0",
|
||||
|
@ -1,2 +1,2 @@
|
||||
m_EditorVersion: 2019.1.10f1
|
||||
m_EditorVersionWithRevision: 2019.1.10f1 (f007ed779b7a)
|
||||
m_EditorVersion: 2019.2.13f1
|
||||
m_EditorVersionWithRevision: 2019.2.13f1 (e20f6c7e5017)
|
||||
|
Loading…
Reference in New Issue
Block a user