Hey so I’m trying to create a spritesheet and it seems to work fine when I set the maximumAtlasSize arguement to a size where I know the final texture would not fit causing it to downsample. Other then setting that to something really large where I know that the final texture would fit, the sprite atlas shows up black but at the correct size.
I don’t know what’s going on
Here’s some of the code:
static void GenerateSpriteSheet()
{
Object textureObjects = (Object)Selection.GetFiltered(typeof(Texture2D), SelectionMode.DeepAssets);
int textureCount = textureObjects.Length;
if (textureCount <= 0)
return;
Texture2D[] textures = new Texture2D[textureCount];
for (int i = 0; i < textureCount; ++i)
textures _= (Texture2D)textureObjects*;*_
string newSpriteSheetPath = “Assets/Game Assets/Resources/Spritesheets/NewEntries/”;
// Texture
Texture2D packedTexture = new Texture2D(1024, 1024, TextureFormat.ARGB32, true);
Material newMaterial = new Material(Shader.Find(“Transparent/Cutout/Diffuse”));
Rect[] uvs = packedTexture.PackTextures(textures, 1, 1024);
newMaterial.mainTexture = packedTexture; //set the main texture of the newMaterial as the new packed textures…
packedTexture.Apply();
EditorUtility.CompressTexture(packedTexture, TextureFormat.ARGB32);
string fileName = newSpriteSheetPath + “NewSpriteSheet-Texture.png”;
byte[] bytes = packedTexture.EncodeToPNG();
File.WriteAllBytes(fileName , bytes);
AssetDatabase.ImportAsset(fileName );
packedTexture= (Texture2D)AssetDatabase.LoadMainAssetAtPath(fileName );
*EditorUtility.SetDirty(packedTexture); *
AssetDatabase.ImportAsset(fileName );
AssetDatabase.CreateAsset(newMaterial, newSpriteSheetPath + “NewSpriteSheet-material.mat”);
AssetDatabase.SaveAssets();
}