- Home /
Is it possible to exchange textures in a ready game by upload?
Hello people, my idea is to make it possible for friends/customers to upload their own textures (PNGs) for a 3D model even when the game is built. That means I have to make it possible to exchange these textures in-between the FBM file. Best of all would be by an online upload! Did anyone of you try this? Thanx for your answers!!!
Aljoscha
Answer by $$anonymous$$ · May 06, 2014 at 04:49 PM
Of course you can.
Uploading works like this (script from http://docs.unity3d.com/Documentation/ScriptReference/WWWForm.html )
var screenShotURL= "http://www.my-server.com/cgi-bin/screenshot.pl";
function UploadPNG() {
// We should only read the screen after all rendering is complete
yield WaitForEndOfFrame();
// Create a texture the size of the screen, RGB24 format
var width = Screen.width;
var height = Screen.height;
var tex = new Texture2D( width, height, TextureFormat.RGB24, false );
// Read screen contents into the texture
tex.ReadPixels( Rect(0, 0, width, height), 0, 0 );
tex.Apply();
// Encode texture into PNG
var bytes = tex.EncodeToPNG();
Destroy( tex );
// Create a Web Form
var form = new WWWForm();
form.AddField("frameCount", Time.frameCount.ToString());
form.AddBinaryData("fileUpload", bytes, "screenShot.png", "image/png");
// Upload to a cgi script
var w = WWW(screenShotURL, form);
yield w;
if (!String.IsNullOrEmpty(w.error))
print(w.error);
else
print("Finished Uploading Screenshot");
}
and downloading (from https://docs.unity3d.com/Documentation/ScriptReference/WWW-texture.html ):
function DownloadPNG ()
{
// Start a download of the given URL
var www : WWW = new WWW (screenShotURL);
// Wait for download to complete
yield www;
// assign texture
renderer.material.mainTexture = www.texture;
}
@Aljoscha - if your question is answered, please click on the checkmark at the top left of the question to mark it as 'answered'. Thanks.
Your answer
Follow this Question
Related Questions
Issue with UnityWebRequest 1 Answer
Assigning UV Map to model at runtime 0 Answers
Unity iphone - texture upload speed 1 Answer
Texture atlas's, how to make them 2 Answers
How do you auto scale the space between Gui Buttons? 1 Answer