Last active
August 29, 2015 14:17
-
-
Save efruchter/9110d739e1b397e8c38e to your computer and use it in GitHub Desktop.
Open a texture from Unity3D Web player in another tab of the web browser.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using System.Text; | |
public class RenderTextureInNewTabExample : MonoBehaviour | |
{ | |
public Texture2D texture; | |
void Start () | |
{ | |
RenderTextureInNewTab(texture); | |
} | |
public static void RenderTextureInNewTab(Texture2D texture) | |
{ | |
var encoded = System.Convert.ToBase64String(texture.EncodeToPNG()); | |
StringBuilder command = new StringBuilder(); | |
command.Append("var data = ").Append("\"<img src='data:image/octet-stream;base64,").Append(encoded).Append("'>\";"); | |
command.Append("var myWindow = window.open(\"data:text/html,\" + encodeURIComponent(data), \"_blank\");"); | |
command.Append("myWindow.focus();"); | |
Application.ExternalEval(command.ToString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This only works in the web player.