Integrating a Unity component into Lectora

sulaimaanrb
sulaimaanrb Community Member Posts: 7 ☆ Roadie ☆
Hi,



I am investigating the integration of an interactive 3D Unity component into Lectora.



So far I have been able to embedded the component using the External HTML Object. My next step is to establish the communication channels between the component and Lectora (using variables to pass values back and forth, event triggers etc.).



Has anyone attempted a similar integration? Any advice/suggestions will be appreciated

Comments

  • ssneg
    ssneg Community Member Posts: 1,456 ♪ Opening Act ♪
    Yes, and it's really easy. So you have your Unity stuff running in an iframe on a webpage. What you need is to let it talk to the parent page (Lectora course) and use JS to set variable values.



    Part 1. Talking to the parent page.



    Method A. If both the course and the Unity object are on the same host, you use ExternalCalls in Unity (http://docs.unity3d.com/ScriptReference/Application.ExternalCall.html) to run JS commands in the HTML page, such as window.parent.VarMyScore1.set('99'). Nothing has to be done in Lectora.



    Method B. If the Unity object is somewhere else, this won't work. So you need to use postMessage() to communicate. In Unity, it's pretty much the same, you use external calls to execute JS that issues postMessage calls. But also you will need to run a simple script in Lectora ( window.addEventListener('message', function() {}) ) to listen to the messages and act on them.



    Part 2. Setting Lectora variables via JS.



    There's a ton of information on these forums, but here's a short overview:



    - set a variable - VarMyvariablename.set("value")

    - get value from a variable - VarMyvariablename.value()

    - go to next page in title - trivNextPage(); trivPrevPage();

    - execute a Lectora action - action1234();

    - hide/show an object - image1234.actionHide(); image1234.actionShow()
  • sulaimaanrb
    sulaimaanrb Community Member Posts: 7 ☆ Roadie ☆
    Awesome, thanks alot.



    Will give it a try and let you know what the outcome is. ;)