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


C# Texture2D.All方法代码示例

本文整理汇总了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;
        }
开发者ID:Arcanum2010,项目名称:UnityVoxelTest,代码行数:58,代码来源:TextureHelper.cs


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