本文整理汇总了C#中UnityEngine.Texture2D.All方法的典型用法代码示例。如果您正苦于以下问题:C# Texture2D.All方法的具体用法?C# Texture2D.All怎么用?C# Texture2D.All使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Texture2D
的用法示例。
在下文中一共展示了Texture2D.All方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PackTexturesWithTiling
public static float PackTexturesWithTiling(this Texture2D atlas, Texture2D[] textures, float copypercent, int maximumAtlasSize, bool makeNoLongerReadable)
{
atlas.name = "Atlas";
int textureSize = textures[0].width;
bool sameSize = textures.All(tex => tex.width == textureSize && tex.height == textureSize);
if (!sameSize)
throw new ArgumentException("All textures must be the same size to fit in this pallate.");
int texturePalateX = Mathf.CeilToInt(Mathf.Sqrt(textures.Length));
int k = textureSize * AtlasTextureSize(textures.Length / 2, copypercent);
atlas.Resize(k, k);
//Calculate texture width/height
//int textureWidth = CalcFinalTextureWidth(textures[0].width, textures.Length / 2, copypercent);
for(int i = 0; i < textures.Length; i++)
{
Texture2D tex = textures[i];
int width = tex.width;
int height = tex.height;
if (!IsPOTTexture(width, height)) throw new ArgumentException("All textures must be power of 2");
int copyPixels = (int)(width * copypercent);
int x = (i % texturePalateX) * (width + (copyPixels * 2));
int y = (i / texturePalateX) * (height + (copyPixels * 2));
Color[] left = tex.GetPixels(0, 0, copyPixels, height);
Color[] right = tex.GetPixels(width - copyPixels, 0, copyPixels, height);
Color[] top = tex.GetPixels(0, 0, width, copyPixels);
Color[] bottom = tex.GetPixels(0, height - copyPixels, width, copyPixels);
atlas.SetPixels(x, y + copyPixels, copyPixels, height, right); // set the right set of copied pixels to the left side of the atlas
atlas.SetPixels(x + copyPixels, y, width, copyPixels, bottom);// set the top set to the bottom copied pixels
atlas.SetPixels(x + copyPixels, y + copyPixels, width, height, tex.GetPixels());
atlas.SetPixels(x + copyPixels, y + height + copyPixels, width, copyPixels, top);
atlas.SetPixels(x + width + copyPixels, y + copyPixels, copyPixels, height, left);
//mirror the corners into their respective...corners
Color[] topLeft = tex.GetPixels(0, 0, copyPixels, copyPixels);
atlas.SetPixels(x + width + copyPixels, y + height + copyPixels, copyPixels, copyPixels, topLeft);
Color[] bottomRight = tex.GetPixels(width - copyPixels, height - copyPixels, copyPixels, copyPixels);
atlas.SetPixels(x, y, copyPixels, copyPixels, bottomRight);
Color[] topRight = tex.GetPixels(width - copyPixels, 0, copyPixels, copyPixels);
atlas.SetPixels(x, y + height + copyPixels, copyPixels, copyPixels, topRight);
Color[] bottomLeft = tex.GetPixels(0, height - copyPixels, copyPixels, copyPixels);
atlas.SetPixels(x + width + copyPixels, y, copyPixels, copyPixels, bottomLeft);
}
return texturePalateX;
}