Unity Community


Page 1 of 10 123 ... LastLast
Results 1 to 20 of 182
  1. Unity



    Location
    Denmark
    Posts
    471

    UnityShared.swc; Communicating between Unity Flash Content and AS3.

    [Edit by Cat: Please note that the below example does not work in Unity 3.5.2. The updated project can be found here.]

    By popular demand, here's an example of how one can use UnityShared.swc to create a custom preloader and communicate between Unity and Flash.

    The ActionScript source of this project can be used with ActionScript tools like FlashBuilder, FDT and FlashDevelop. The project needs to be setup so that the provided UnityShared.swc is used as a library.

    AS3Communication_unity_project.zip
    AS3Communication_as3_src.zip

    In UnityShared an AS3 class named UnityContentLoader is provided, which is the base for loading and communicating with UnityContent.

    When publishing to Flash Application.ExternalCall is routed to what is set as the UnityContentHost, when constructing the UnityContentLoader. These messages (unfortunately there is no way to send arguments at this point in time using Application.ExternalCall), then are directly called on IUnityContentHost.

    The unityInitStart and unityInitComplete have to be implemented by the class set as IUnityContentHost and signify when the UnityContent is done loading and starting to initialize, and when it's done initializing, and ready for communication from AS3.

    To communicate from AS3 to Unity, one calls sendMessage on the unityContent property of unityContentLoader. The sendMessage functionality is similar to the sendMessage functionality of the Unity webplayer.

    sendMessage accepts arguments in the following order; first a string path to the gameobject, then the method to be called on that gameobject, and then an anonymous object to contain the arguments. This way, one can marshall direct references to objects between AS3 and Unity, cache them and call them directly.

    This api is by no means in it's final state and are subject to change in later drops(we are thinking about a full api inside unity towards AS3, similar to custom platform api's for other platforms), but it should help implementing things like networking.

    I'll post more examples in this thread.

    Regards,
    Ralph.
    Last edited by catburton; 05-28-2012 at 06:13 AM. Reason: Added link to updated project.


  2. Posts
    325
    Wow thanks for this. Unfortunately I'm getting a little red box with "Fatal Error : null" when I try compile this or just run the swf provided. Any idea where I may have gone wrong?
    Last edited by tertle; 12-23-2011 at 03:56 AM.

  3. Unity



    Location
    Denmark
    Posts
    471
    You need a content debugger of the flashplayer; please check out the faq here; http://unity3d.com/unity/preview/faq

    Without a proper error message I can't tell you what's going on, but most likely your swf isn't published with version=13 or your wmode isn't set to direct on the flash embed, or your flashplayer is lower then 11.


  4. Posts
    325
    Silly me. Forgot I had 11.2 beta build installed. Cheers.

    -edit- hmm actually runs fine in 11.2 content debugger. just null errors in browser.
    Last edited by tertle; 12-23-2011 at 04:09 AM.


  5. Location
    France
    Posts
    189
    Thank Ralph,

    You can send and receive an arguments with this method (Replace WWW & WWWForm) ?

  6. Unity



    Location
    Denmark
    Posts
    471
    darkloy, yes, check out the provided example; it show sending arguments both ways.


  7. Location
    France
    Posts
    189
    Ok Sorry Ralph !!


  8. Location
    Russia, St.-Petersburg
    Posts
    24
    Hi Ralph! Thank you for your post.
    Can you tell us, is it possible now to integrate compiled stage3d layer (that unity builds) with native flash GUI?
    I mean in FlashDevelop or FlashBuilder
    sorry for my english, my native language was c++

  9. Unity



    Location
    Denmark
    Posts
    471
    @darkloy : glad I could help, let us know how it works out for you.

  10. Unity



    Location
    Denmark
    Posts
    471
    Hi vtornik, in the example I remove the entire opaque preloaded from the stage; however, you can keep an overlay sprite / movie clip over the stage3d content. Keep in mind that this on some configurations/platforms might cost you some performance. However, it's entirely possible do your overlaying gui in flash and the game and the 3d in unity!

    We'd love to see an example of someone using that functionality; let us know what you manage to do with it !
    Last edited by UnityRalph; 12-23-2011 at 10:20 AM.


  11. Location
    Russia, St.-Petersburg
    Posts
    24
    Thank you a lot, Ralph!
    sorry for my english, my native language was c++


  12. Location
    France
    Posts
    189
    @UnityRalph : Ok, no problem


  13. Location
    France
    Posts
    189
    If you provide other examples I would be very happy: D ...


  14. Posts
    39
    i'm trying to run the example in ie8 with the flash debugger and running vizzy flash tracer but when i click the button, nothing seems to happen.
    any ideas on what i'm doing wrong?


  15. Location
    Melbourne, Australia
    Posts
    64


  16. Posts
    3
    Hi Ralph,

    This is really good stuff - just one more question:
    Via the sendMessage method what sort of objects could I theoretically push accross from Flash to Unity? I'm thinking images (loaded from web or created) or audio files... is that possible? As a kind of WWW. replacement as it's missing in the current release?

    Thanks!

  17. Unity



    Location
    Denmark
    Posts
    471
    @shifty, I'm not familiar with that setup; however in our FAQ there is documentation to setup a debugging environment. http://unity3d.com/unity/preview/faq

  18. Unity



    Location
    Denmark
    Posts
    471
    @rogerisland; I'd advice to handle that type of media on the AS3 side for now; however, I will follow up with a new example showing how to for example put a video on a unity texture.


  19. Posts
    39
    Quote Originally Posted by UnityRalph View Post
    @shifty, I'm not familiar with that setup; however in our FAQ there is documentation to setup a debugging environment. http://unity3d.com/unity/preview/faq
    so i went back and reinstalled the setup and followed the instructions and as far as i can tell, it's still not working:

    Install "content debugger" from Adobe Flash Player [used ie9]:
    Check
    Go to http://flashplayerversion.com/, and make sure that it says 'Debugger: Yes': [says WIN 11,1,102,55]
    Check
    Create a file called mm.cfg and added ErrorReportingEnable=1; TraceOutputFileEnable=1
    Check

    i drag the AS3Communication.html into the browser, it loads up, it says running the in the debug player at the bottom right of the screen.
    i click the button a few times

    Find and open your flashlog.txt
    it says: Player: init engine [space] MolehillGfxDevice: DirectX9 (Direct blitting)

    is this "Player: init engine MolehillGfxDevice: DirectX9 (Direct blitting)" the result i'm looking for? this appears before i press the button and only appears on load so i'm assuming the expected result would be different.

  20. Unity



    Location
    Denmark
    Posts
    471
    Shifty Nevers : that looks fine to me; if you now hit the button you should get the flash traces; depending on what you compile the source with though, it might be stripping the traces out of the source code I provided above.

Page 1 of 10 123 ... LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •