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
Of course you can.
Uploading works like this (script from Unity - Scripting API: WWWForm )
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 Unity - Scripting API: WWW.texture ):
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;
}