当前位置: 首页>>代码示例>>C#>>正文


C# Texture2D.PackTexturesWithTiling方法代码示例

本文整理汇总了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;
//.........这里部分代码省略.........
开发者ID:Arcanum2010,项目名称:UnityVoxelTest,代码行数:101,代码来源:BlockRegistry.cs


注:本文中的UnityEngine.Texture2D.PackTexturesWithTiling方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。