-
-
Save John-O-Really/db321a6ac05c7ba9572d2bbb26f4e795 to your computer and use it in GitHub Desktop.
A quick wizard to create Texture Array assets from standard textures in unity, updated to use Graphics.CopyTexture for Unity URP, 2023.2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEditor; | |
using UnityEditorInternal; | |
namespace MK.Utilities | |
{ | |
public class TextureArrayCreator : ScriptableWizard | |
{ | |
[MenuItem("Window/Texture Array Creator")] | |
public static void ShowWindow() | |
{ | |
ScriptableWizard.DisplayWizard<TextureArrayCreator>("Create Texture Array", "Build Asset"); | |
} | |
public string path = "Assets/"; | |
public string filename = "MyTextureArray"; | |
public List<Texture2D> textures = new List<Texture2D>(); | |
private ReorderableList list; | |
void OnWizardCreate() | |
{ | |
CompileArray(textures, path, filename); | |
} | |
private void CompileArray(List<Texture2D> textures, string path, string filename) | |
{ | |
if(textures == null || textures.Count == 0) | |
{ | |
Debug.LogError("No textures assigned"); | |
return; | |
} | |
Texture2D sample = textures[0]; | |
Texture2DArray textureArray = new Texture2DArray(sample.width, sample.height, textures.Count, sample.format, false); | |
textureArray.filterMode = FilterMode.Trilinear; | |
textureArray.wrapMode = TextureWrapMode.Repeat; | |
for (int i = 0; i < textures.Count; i++) | |
{ | |
Graphics.CopyTexture(textures[i], 0, 0, textureArray, i, 0); | |
} | |
textureArray.Apply(); | |
string uri = path + filename+".asset"; | |
AssetDatabase.CreateAsset(textureArray, uri); | |
Debug.Log("Saved asset to " + uri); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment