[英]Load array of textures into individual Image components into a grid layout in Unity 4.6 (using uGUI)
I'm having a lot of trouble trying to develop a loader that grabs a group of textures located in an array and populates them into a grid layout. 我在尝试开发一种加载程序时遇到了很多麻烦,该加载程序可以获取位于数组中的一组纹理并将其填充到网格布局中。 Could anyone share some code insight or a snippet that might do the trick? 任何人都可以分享一些可以解决问题的代码见解或摘要吗?
Lets say you want to show your images in the format below. 假设您要以以下格式显示图像。 What you can do is merging your images into a 1 big Texture2D (But as I know image size should not exceed 2048x2048) 您可以做的是将图像合并为1个大Texture2D(但据我所知,图像大小不应超过2048x2048)
The function below should do the work: 以下功能可以完成工作:
private Texture2D ConcatTexture(Texture2D[,] textures, int imageWidth, int imageHeight)
{
int rowCount = textures.GetLength(0);
int columnCount = textures.GetLength(1);
//Space allocation for the final texture
Texture2D finalTexture = new Texture2D(columnCount * imageWidth, rowCount * imageHeight);
for (int i = 0; i < rowCount; i++)
for(int j=0 ; j < columnCount ; j++)
finalTexture.SetPixels(j * imageWidth, (rowCount-i-1) * imageHeight, imageWidth, imageHeight, textures[i, j].GetPixels());
return finalTexture;
}
You can also edit this code and put some spaces between images if it is what you are looking for. 您也可以编辑此代码,并根据需要在图像之间放置一些空格。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.