本文整理汇总了C#中UnityEngine.Texture2D.PackTexturesWithTiling方法的典型用法代码示例。如果您正苦于以下问题:C# Texture2D.PackTexturesWithTiling方法的具体用法?C# Texture2D.PackTexturesWithTiling怎么用?C# Texture2D.PackTexturesWithTiling使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Texture2D
的用法示例。
在下文中一共展示了Texture2D.PackTexturesWithTiling方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RegistrationComplete
public void RegistrationComplete()
{
IEnumerable<Block> blocks = RegisteredBlocks.Select(kv => kv.Value.Block);
Texture2D noTexture = (Texture2D)Resources.Load("notexture");
noTexture.name = "notexture";
//Figure out what blocks will get what UV
List<string> texturesToLoad = new List<string>();
foreach(Block b in blocks)
{
foreach (string texture in b.Data.TextureNames)
{
if (texture == "notexture") continue; //Skip 'notexture' textures, because are are already going to load
//those
if (!texturesToLoad.Contains(texture))
{
texturesToLoad.Add(texture);
}
}
}
//Load each of the textures, make sure they are square and a power of 2 between 32 and 512.
List<Texture2D> LoadedTextures = new List<Texture2D>();
List<string> NotLoadedTextures = new List<string>();
LoadedTextures.Add(noTexture);
foreach(string t in texturesToLoad)
{
if (t == "notexture") continue;
Texture2D loadedTexture = (Texture2D)Resources.Load(t);
loadedTexture.name = t;
if (loadedTexture.width != loadedTexture.height)
{
Debug.Log(string.Format("Texture {0} is not square!", t));
NotLoadedTextures.Add(t);
continue;
}
if (loadedTexture.width < 32 || loadedTexture.width > 512)
{
Debug.Log(string.Format("Texture {0} must be a power of 2 between 32 and 512", t));
NotLoadedTextures.Add(t);
continue;
}
if (!Mathf.IsPowerOfTwo(loadedTexture.width))
{
Debug.Log(string.Format("Texture {0} must be a power of 2 between 32 and 512", t));
NotLoadedTextures.Add(t);
continue;
}
LoadedTextures.Add(loadedTexture);
}
//Load and pack the textures
for (int i = 32; i <= 512; i = i * 2)
{
IEnumerable<Texture2D> TexturesOfThisSize = LoadedTextures.Where(t => t.width == i);
if (TexturesOfThisSize.Count() == 0) continue;
//Pack them into an atlas
Texture2D atlas = new Texture2D(1024, 1024, TextureFormat.ARGB32, true, false);
atlas.anisoLevel = 9;
atlas.mipMapBias = -.5f;
atlas.filterMode = FilterMode.Point;
float percent = 1f / 8f;
float atlasWidth = atlas.PackTexturesWithTiling(TexturesOfThisSize.ToArray(), percent, 1024, false);
atlas.Apply(true);
AtlasSize thisSize = (AtlasSize)Enum.Parse(typeof(AtlasSize), "_" + i);
Debug.Log("Building Atlas of size " + thisSize.ToString());
TextureAtlases[thisSize] = new TextureAtlasLookup()
{
Atlas = atlas,
TextureNamesInThisAtlas = TexturesOfThisSize.Select(t => t.name).ToList(),
CopyPercent = percent,
PalleteSize = atlasWidth,
};
}
//Go through the loaded names and assign IDs and Blocks to them.
foreach(Block b in blocks)
{
List<int> Ids = new List<int>();
List<AtlasSize> atlasLocations = new List<AtlasSize>();
//Find which atlas each block's texture is in
for(int i = 0; i < 6; i++)
{
string textureName = b.Data.TextureNames[i];
//If we have a notexture or failed to load, index directly into 'notexture'
if(textureName == "notexture" || NotLoadedTextures.Contains(textureName))
{
Ids.Add(0); //notexture is the first texture in the 32sized array
atlasLocations.Add(AtlasSize._32);
continue;
}
//Find which atlas this texture is in
AtlasSize containingAtlas = AtlasSize._32;
//.........这里部分代码省略.........