// with material public static MadMeshCombinerAtlas CreateAtlas(string texturePath, Texture2D[] textures, Shader shader) { var madeReadable = PrepareTextures(textures); try { List<MadMeshCombinerAtlas.Item> items = new List<MadMeshCombinerAtlas.Item>(); PackTextures(textures, texturePath, ref items); var atlas = new MadMeshCombinerAtlas(); atlas.atlasTexture = AssetDatabase.LoadAssetAtPath(texturePath, typeof(Texture2D)) as Texture2D; atlas.AddItemRange(items); // create material out of atlas var materialPath = System.IO.Path.ChangeExtension(texturePath, "mat"); //var atlasMaterial = new Material(Shader.Find("Transparent/Cutout/Diffuse")); var atlasMaterial = new Material(shader); atlasMaterial.mainTexture = atlas.atlasTexture; atlas.atlasMaterial = atlasMaterial; AssetDatabase.CreateAsset(atlasMaterial, materialPath); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); return atlas; } finally { RevertAll(madeReadable); } }
public static Texture2D GetItemOrigin(MadMeshCombinerAtlas.Item item) { var path = AssetDatabase.GUIDToAssetPath(item.textureGUID); if (string.IsNullOrEmpty(path)) { return null; } return AssetDatabase.LoadAssetAtPath(path, typeof(Texture2D)) as Texture2D; }
// without material public static MadMeshCombinerAtlas CreateAtlas(string texturePath, Texture2D[] textures) { var madeReadable = PrepareTextures(textures); try { List<MadMeshCombinerAtlas.Item> items = new List<MadMeshCombinerAtlas.Item>(); PackTextures(textures, texturePath, ref items); var atlas = new MadMeshCombinerAtlas(); atlas.atlasTexture = AssetDatabase.LoadAssetAtPath(texturePath, typeof(Texture2D)) as Texture2D; atlas.AddItemRange(items); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); return atlas; } finally { RevertAll(madeReadable); } }
// =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== public static string GetItemOriginPath(MadMeshCombinerAtlas.Item item) { var path = AssetDatabase.GUIDToAssetPath(item.textureGUID); return path; }
private static List<MadMeshCombinerAtlas.Item> LiveItems(MadMeshCombinerAtlas atlas) { return (from item in atlas.items where MadMeshCombinerAtlasUtil.GetItemOrigin(item) != null select item).ToList(); }