Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Unity 5 WebGL data binding?

Discussion in 'Unity 5 Pre-order Beta' started by Zaibach333, Oct 26, 2014.

  1. Zaibach333

    Zaibach333

    Joined:
    Sep 4, 2011
    Posts:
    19
    Since WebGL is javascript, if you had other elements in the page relying on values from unity, is there any support going towards bound access to those variables? This could be really useful for integrating WebGL canvases throughout existing web applications.
     
  2. sluice

    sluice

    Joined:
    Jan 31, 2014
    Posts:
    416
    For sure there is a way to communicate back and fourth with Javascript.

    My best bet is that it is the same as with the WebPlayer:
    Code (csharp):
    1. Application.ExternalCall("MyJavascriptFunction", myData);
     
  3. Zaibach333

    Zaibach333

    Joined:
    Sep 4, 2011
    Posts:
    19
    true, but how would I go about say

    Code (CSharp):
    1. void Update() {
    2.      MyBoundData.position += Vector3.up * 4.0f * Time.deltaTime;
    3. }

    and simply do this in javascript

    Code (JavaScript):
    1. $("MyParagraphID").val(MyUnityObject.MyBoundData.position.x);
    and do this without a ton of sync calls in high level code.

    It just seems like a very possible thing when there's no barrier of a webPlayer
     
  4. RalphH

    RalphH

    Administrator

    Joined:
    Dec 22, 2011
    Posts:
    592
    "It just seems like a very possible thing when there's no barrier of a webPlayer"

    This is somewhat of a misassumption about how we convert the C# types; they are all represented by data in a singular typed array, which is shared by both the converted managed code and the engine code, through a few conversion steps; explicit marshalling from C# types to JavaScript types will always need to happen.
     
  5. Zaibach333

    Zaibach333

    Joined:
    Sep 4, 2011
    Posts:
    19
    Thanks for jumping in, you see the benefit of binding at least, unfortunate that it isn't an option. If I wind up in a situation which could use it in unity 5... I'd just have to keep doing it like the web player. Again, thanks for the clarification.