Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Reading webplayer custom tags

Discussion in 'Scripting' started by benblo, Sep 2, 2008.

  1. benblo

    benblo

    Joined:
    Aug 14, 2007
    Posts:
    476
    We can modify the webplayer's behavior using custom tags... but is it possible to get the value of those tags Unity-side (ie inside the webplayer)?
    I guess one could use browser-javascript to get those tags, but is there a more direct (and elegant) way?

    In my game I have a fullscreen button, but I don't want to show it if fullscreen has been disabled by tags... of course I can make a special build, but again: not elegant ;) !

    Also, I could use tags to configure a few game options in PHP, which would save using SendMessage (which relies on the browser allowing javascript)...
     
  2. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    No, the only object/embed tag value you can read directly is the src tag (using Application.srcValue). With that in mind here are the options as I see 'em:

    1. As you mentioned, use browser-based JS to get the information and message that back into your content.

    2. If you really just want to know this one parameter's value then perhaps you can modify the src URL a bit and parse it from there? For example, make your src value something like "yourfile.unity3d?fs=true". Then in your content you read the src value and parse out the fs ("full screen") value and go from there.

    In either case no special build is necessary, but you will have to do some page and/or tag modifying.


    Edit: Oh, and FYI, you might be able to devise routines here using entirely ExternalEval (no function calls which then use SendMessage to send back the data). It will require you to have a GetUnity() type function in the page, but then in one line you could get at any parameter value you'd like and avoid using SendMessage.
     
  3. benblo

    benblo

    Joined:
    Aug 14, 2007
    Posts:
    476
    Thanks for the tips Tom :) !

    URL params wouldn't be wise in my case because the user can just edit them and that's baaad.

    The other options rely on ExternalEval or SendMessage, so either way on browser-JS being turned on.... I don't really like it but then again it's my (aging) webdev reflexes talking.
    Have you any idea as to the JS penetration these days? (or rather, the percentage of people that do turn it off)
     
  4. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    I think you've misunderstood my suggestion. I was not suggesting that you read the page's URL and parameters it contains (which the user could modify with ease). Instead I was suggesting that you read the object/embed tag's src parameter, and pull any needed information from its value.

    You originally asked if you could read arbitrary object/embed tag parameter values without using browser-based JS, the answer is no and that from within your content you can only read the src parameter's value. So modify the src parameter value and use that to pass information in the same, non-user editable way as you would any other parameter value. :)

    Code (csharp):
    1. <object ...>
    2.   <param name="src" value="file.unity3d?paramname=paramvalue" />
    3.   <embed src="file.unity3d?paramname=paramvalue" ... />
    4. </object>

    No, sorry I don't know or have an estimate for that sort of figure.
     
  5. benblo

    benblo

    Joined:
    Aug 14, 2007
    Posts:
    476
    Oh yes indeed I misunderstood, sorry!
    Your approach is very clever, I didn't think you could modify the src in that way, but like all good tips now that you pointed it out it seems so obvious, thanks a lot :p !

    I think I'll even repeat the disableFullscreen attribute in this fashion, it's a bit redundant but it gets the job done without any browser-JS... sweet!