Skip to content

Instantly share code, notes, and snippets.

@efruchter
Last active August 29, 2015 14:17
Show Gist options
  • Save efruchter/9110d739e1b397e8c38e to your computer and use it in GitHub Desktop.
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.
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());
}
}
@efruchter
Copy link
Author

This only works in the web player.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment