Files
HauntedBloodlines/Assets/Editor/Texture2DArrayCreator.cs
2025-05-29 22:31:40 +03:00

37 lines
1.0 KiB
C#

using UnityEngine;
using UnityEditor;
public class Texture2DArrayCreator
{
[MenuItem("Assets/Create/Texture2DArray From Textures")]
public static void CreateTexture2DArray()
{
var textures = Selection.GetFiltered<Texture2D>(SelectionMode.DeepAssets);
if (textures.Length == 0)
{
Debug.LogWarning("No textures selected!");
return;
}
int width = textures[0].width;
int height = textures[0].height;
TextureFormat format = textures[0].format;
var textureArray = new Texture2DArray(width, height, textures.Length, format, false, false);
for (int i = 0; i < textures.Length; i++)
{
for (int mip = 0; mip < textures[i].mipmapCount; mip++)
{
Graphics.CopyTexture(textures[i], 0, mip, textureArray, i, mip);
}
}
AssetDatabase.CreateAsset(textureArray, "Assets/NewTexture2DArray.asset");
AssetDatabase.SaveAssets();
Debug.Log("Texture2DArray created successfully!");
}
}