DrawTexture() private method

private DrawTexture ( InternalDrawTextureArguments &arguments ) : void
arguments InternalDrawTextureArguments
return void
        private static void SaveResized(Texture2D tex, int width, int height, int x, int y)
        {
            var target     = new Texture2D(width, height, TextureFormat.RGBA32, false);
            var targetData = target.GetRawTextureData <Color32>();
            var clearColor = Color.clear;

            for (int l = 0; l < height; ++l)
            {
                for (int k = 0; k < x; ++k) //left border
                {
                    targetData[l * width + k] = clearColor;
                }
                for (int k = tex.width - x; k < width; ++k) //right border
                {
                    targetData[l * width + k] = clearColor;
                }
            }
            for (int k = x; k < width - x; ++k)
            {
                for (int l = 0; l < y; ++l) //bottom border
                {
                    targetData[l * width + k] = clearColor;
                }
                for (int l = tex.height - y; l < height; ++l) //top border
                {
                    targetData[l * width + k] = clearColor;
                }
            }
            var rt  = RenderTexture.GetTemporary(tex.width, tex.height);
            var rta = RenderTexture.active;

            RenderTexture.active = rt;
            GL.Clear(false, true, Color.clear);
            GL.LoadPixelMatrix(0, 1, 1, 0);
            UnityGraphics.DrawTexture(new Rect(0, 0, 1, 1), tex, MatCopy, 0);//point copy
            target.ReadPixels(new Rect(0, 0, tex.width, tex.height), x, y);
            RenderTexture.active = rta;
            RenderTexture.ReleaseTemporary(rt);
            string projectPath = Application.dataPath.Replace("/Assets", "/");
            string path        = AssetDatabase.GetAssetPath(tex);

            File.WriteAllBytes(projectPath + path, target.EncodeToPNG());
            AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
        }
 public static void CreatePreview128()
 {
     AssetDatabase.StartAssetEditing();
     foreach (var tex in Selection.GetFiltered <Texture2D>(SelectionMode.DeepAssets))
     {
         if (tex.width == tex.height)
         {
             continue;
         }
         int  size = tex.width;
         Rect drawRect;
         if (tex.height > tex.width)
         {
             size = tex.height;
             int xr = (size - tex.width) / 2;
             drawRect = new Rect((float)xr / size, 0, (float)tex.width / size, 1);
         }
         else
         {
             int yr = size - tex.height;
             drawRect = new Rect(0, (float)yr / size, 1, (float)tex.width / size);
         }
         int tsize  = 128;
         var target = new Texture2D(tsize, tsize, TextureFormat.RGBA32, false);
         var rt     = RenderTexture.GetTemporary(tsize, tsize);
         var rta    = RenderTexture.active;
         RenderTexture.active = rt;
         GL.Clear(false, true, Color.clear);
         GL.LoadPixelMatrix(0, 1, 1, 0);
         UnityGraphics.DrawTexture(drawRect, tex, MatCopy, 1);//bilinear copy
         target.ReadPixels(new Rect(0, 0, tsize, tsize), 0, 0);
         RenderTexture.active = rta;
         RenderTexture.ReleaseTemporary(rt);
         string projectPath = Application.dataPath.Replace("/Assets", "/");
         string path        = AssetDatabase.GetAssetPath(tex) + "_sqprv.png";
         File.WriteAllBytes(projectPath + path, target.EncodeToPNG());
         AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
     }
     AssetDatabase.StopAssetEditing();
 }
Exemplo n.º 3
0
        public static void DrawTexture(Rect screenRect, Texture texture, Rect sourceRect, int leftBorder, int rightBorder, int topBorder, int bottomBorder)
        {
            Material mat = null;

            Graphics.DrawTexture(screenRect, texture, sourceRect, leftBorder, rightBorder, topBorder, bottomBorder, mat);
        }
Exemplo n.º 4
0
 public static void DrawTexture(Rect screenRect, Texture texture, int leftBorder, int rightBorder, int topBorder, int bottomBorder, [UnityEngine.Internal.DefaultValue("null")] Material mat)
 {
     Graphics.DrawTexture(screenRect, texture, new Rect(0f, 0f, 1f, 1f), leftBorder, rightBorder, topBorder, bottomBorder, mat);
 }
Exemplo n.º 5
0
 public static void DrawTexture(Rect screenRect, Texture texture, [UnityEngine.Internal.DefaultValue("null")] Material mat)
 {
     Graphics.DrawTexture(screenRect, texture, 0, 0, 0, 0, mat);
 }
Exemplo n.º 6
0
        public static void DrawTexture(Rect screenRect, Texture texture)
        {
            Material mat = null;

            Graphics.DrawTexture(screenRect, texture, mat);
        }
Exemplo n.º 7
0
        public static void DrawTexture(Rect screenRect, Texture texture, Rect sourceRect, int leftBorder, int rightBorder, int topBorder, int bottomBorder, Color color, Material mat)
        {
            int pass = -1;

            Graphics.DrawTexture(screenRect, texture, sourceRect, leftBorder, rightBorder, topBorder, bottomBorder, color, mat, pass);
        }
Exemplo n.º 8
0
        public static void DrawTexture(Rect screenRect, Texture texture, Material mat)
        {
            int pass = -1;

            Graphics.DrawTexture(screenRect, texture, mat, pass);
        }