Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

WebGL Screenshot & share like the benchmark

Discussion in 'WebGL' started by Jonathan459, Jun 16, 2015.

  1. Jonathan459

    Jonathan459

    Joined:
    Dec 1, 2013
    Posts:
    10
    Hi...

    Im trying to re-create the screenshot & functionality of the screenshot and the facebook share like the WebGL benchmark with no success... @jonas echterhoff could you share the code, or give me some guidelines please?

    thank you very much
     
  2. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    Hey,

    I found getting this set up with facebook to be more work then I had expected. Quite possibly, this has become easier now, that facebook has released an SDK for Unity WebGL:

    https://developers.facebook.com/docs/unity/reference/beta/webgl

    When I did that, this was not available, so I had to use the JavaScript SDK.

    But, anyways, some pointers:

    - I would get a screen shot using Texture2D.ReadPixels and Texture2D.EncodeToPNG
    - I would send those png bytes to a JavaScript function, which would then upload this image to facebook using an XMLHttpRequest
    - then I would use the JS Facebook SDK to post a story, referencing this uploaded image.
    - the story type/format would previously need to be configured in your facebook app developer setup page

    I found it easier to simply upload the picture to the facebook photos on your account, then to use a custom story type like this. The problem is that if you do that, Facebook requires the text caption you use to only contain text input manually by the user - ie, you are not allowed to pre-fill that with information like the benchmark score or browser used.
     
  3. Jonathan459

    Jonathan459

    Joined:
    Dec 1, 2013
    Posts:
    10
    @jonas echterhoff Thank you very much! This was really helpfull... i think ill give the WebGL SDK a try.