Saving Texture2D for webplayer to web

Easy Save 2 has been replaced by Easy Save 3, so is no longer supported.
marbas
Posts: 8
Joined: Fri Jun 14, 2013 2:48 pm

Saving Texture2D for webplayer to web

Post by marbas »

Hi.

I have a simple webplayer game that I would like to add a feature to save a screenshot to my server.

I have bought Easysave, setup unity and php on the sever correctly according to the documentation.
What I want to do is to upload a Texture2D datatype (containing the screenshot) to mySQL and (later) load it back to a Texture2D and apply that to a plane mesh in unity.

Is this possible to achieve this with the Easysave system?
Could you please provide a simple unity script example (javascript preferably) how to set this up?

Thanks.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving Texture2D for webplayer to web

Post by Joel »

Hi marbas,

It would be possible to do this if Unity allowed you to capture screenshots from the Web Player. However, on Web Player, Application.CaputreScreenshot() does nothing, so this is not possible. See the CaptureScreenshot documentation for more details.

EDIT: It looks like it's now possible with Texture2D.ReadPixels(), so I'll write up a very basic example when I get a chance.

All the best,
Joel
marbas
Posts: 8
Joined: Fri Jun 14, 2013 2:48 pm

Re: Saving Texture2D for webplayer to web

Post by marbas »

Thanks for the fast reply.

Actually I am most interested in the upload/download of the Texture2D part. There are different approaches to screencapture floating around on the web (that does not use Application.Capturescreenshot()). So I assume some of these would work on the webplayer?

If you do get a chance to write a basic example (just for the up/down Texture2D) part, I would be very grateful.

Thanks.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving Texture2D for webplayer to web

Post by Joel »

That shouldn't be a problem at all. I should be in the office sometime this weekend so hopefully I'll be able to get the example done then for you. Otherwise, it won't be until next week.

Regards,
Joel
marbas
Posts: 8
Joined: Fri Jun 14, 2013 2:48 pm

Re: Saving Texture2D for webplayer to web

Post by marbas »

Thank you Joel :)
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving Texture2D for webplayer to web

Post by Joel »

Hi marbas,

The example you requested has been created, and can be found HERE.

Some of it might cover things that you already know (like applying the texture), but it should be useful to you. The example will also be included in the next update, but I've attached the Unity Package to the example for the time being.

All the best,
Joel
marbas
Posts: 8
Joined: Fri Jun 14, 2013 2:48 pm

Re: Saving Texture2D for webplayer to web

Post by marbas »

Thank you Joel! This example is greatly appreciated. I tried some more myself, but couldn't get it to work in the webplayer (was trying to save to disk after the download, like in the INT example)
Did a quickrun on the example prefab and setup my php parameters. Works good on webplayer :D
Haven't implemented this in my gamecode yet, but looks straightforward and easy. This can be adapted to JS also, true? (Not that it matters much C# is fine)

Thanks for great support!
marbas
Posts: 8
Joined: Fri Jun 14, 2013 2:48 pm

Re: Saving Texture2D for webplayer to web

Post by marbas »

Btw, on the matter of image upload. Is there a size limit? In my previous experiments I often ended up with a maximum of 64kb stored on the server. Is this the limit of the upload data size?
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving Texture2D for webplayer to web

Post by Joel »

Hi marbas,

Glad it's been of some help to you. It shouldn't be too difficult to port over the JS; just remember that you need to put a period before defining generic parameters in JS. For example, this in C#:
int myInt = ES2.Load<int>(path);
Would be this in JS:
var myInt : int = ES2.Load.<int>(path);
Because texture data is saved as a BLOB in the MySQL database rather than a file, there should be no limit to the size of image you can store. The only exception is if your database is configured to limit the maximum size of a BLOB.

All the best,
Joel
marbas
Posts: 8
Joined: Fri Jun 14, 2013 2:48 pm

Re: Saving Texture2D for webplayer to web

Post by marbas »

I guess that my database must be config for a maximum of 64kb BLOB dataset. PHP and database it's all a bit new to me. Im not sure how to increase this. I'll google a bit around :)
Locked