Hi everyone!
I'm trying to follow the Mix and Match and this guide [https://esotericsoftware.com/spine-unity-main-components#Runtime-Repacking] to generate new textures at runtime. Everything works perfectly when I'm not including additional textures, but I encounter issues when adding a Normal Map and Light Mask.
The source data for my normal map is set to Texture Type: Normal Map, and the light mask's source data is a standard Sprite. I tried writing some parameters based on my understanding, but the newly generated normal map and light mask don't display correctly, and I got errors: "Graphics.CopyTexture called with incompatible formats."
Here’s my code—any guidance or corrections would be greatly appreciated! Thank you!
public void OptimizeSkin()
{
// Create a repacked skin.
Skin previousSkin = skeleton.Skin;
// Note: materials and textures returned by GetRepackedSkin() behave like 'new Texture2D()' and need to be destroyed
if (runtimeMaterial)
Destroy(runtimeMaterial);
if (runtimeAtlas)
Destroy(runtimeAtlas);
Texture2D[] additionalOutputTextures = null;
int[] additionalTexturePropertyIDsToCopy = new int[] { Shader.PropertyToID("_BumpMap"), Shader.PropertyToID("_MaskTex") };
TextureFormat[] additionalTextureFormats = new TextureFormat[] { TextureFormat.DXT5, TextureFormat.DXT5 };
Skin repackedSkin = previousSkin.GetRepackedSkin
(
"Repacked skin", dataMatrix.fullStyleData.skeletonDataAsset.atlasAssets[0].PrimaryMaterial,
out runtimeMaterial, out runtimeAtlas, 2048, mipmaps:true,
additionalTexturePropertyIDsToCopy: additionalTexturePropertyIDsToCopy,
additionalOutputTextures: additionalOutputTextures
, additionalTextureFormats: additionalTextureFormats
);
previousSkin.Clear();
// Use the repacked skin.
skeleton.Skin = repackedSkin;
skeleton.SetSlotsToSetupPose();
}