Exemplo n.º 1
0
 public static UnityEngine.Texture2D RenderStaticPreview(Sprite sprite, Color color, int width, int height, Matrix4x4 transform)
 {
     UnityEngine.Texture2D result;
     if (sprite == null)
     {
         result = null;
     }
     else
     {
         PreviewHelpers.AdjustWidthAndHeightForStaticPreview((int)sprite.rect.width, (int)sprite.rect.height, ref width, ref height);
         SavedRenderTargetState savedRenderTargetState = new SavedRenderTargetState();
         RenderTexture          temporary = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.Default, RenderTextureReadWrite.Default);
         RenderTexture.active = temporary;
         GL.Clear(true, true, new Color(0f, 0f, 0f, 0.1f));
         SpriteUtility.previewSpriteDefaultMaterial.mainTexture = sprite.texture;
         SpriteUtility.previewSpriteDefaultMaterial.SetPass(0);
         SpriteUtility.RenderSpriteImmediate(sprite, color, transform);
         UnityEngine.Texture2D texture2D = new UnityEngine.Texture2D(width, height, TextureFormat.ARGB32, false);
         texture2D.hideFlags = HideFlags.HideAndDontSave;
         texture2D.ReadPixels(new Rect(0f, 0f, (float)width, (float)height), 0, 0);
         texture2D.Apply();
         RenderTexture.ReleaseTemporary(temporary);
         savedRenderTargetState.Restore();
         result = texture2D;
     }
     return(result);
 }