Search Unity

LWF - an open-source tool for bringing Flash animation to Unity and HTML5

Discussion in 'Assets and Asset Store' started by Kazuki_Sakamoto, Nov 16, 2012.

  1. Kazuki_Sakamoto

    Kazuki_Sakamoto

    Joined:
    Jul 6, 2012
    Posts:
    88
    Yeah, it will work.
     
  2. blastone

    blastone

    Joined:
    Apr 7, 2009
    Posts:
    168
    Ok, I tried that with the various LWFs, and it didn't seem to work, I still ended up with incorrect depth displays.

    However using sortingLayers worked well:
    m_LWFObject.Load(a_lwfPath, useAdditionalColor:true, sortingLayerName:"Hero", sortingOrder:5);

    Good work on it all. I look forward to seeing what you come up with next
     
    Last edited: Aug 29, 2014
  3. Kazuki_Sakamoto

    Kazuki_Sakamoto

    Joined:
    Jul 6, 2012
    Posts:
    88
    Good to hear, thanks
     
  4. blastone

    blastone

    Joined:
    Apr 7, 2009
    Posts:
    168
    Question for you:
    Whats the best way to intercept a Touch/MouseEvent on a LWF.Movie?
    If there is a native method, does it work on bounds, or transparency?
     
  5. blastone

    blastone

    Joined:
    Apr 7, 2009
    Posts:
    168
    And more questions for you :D ( sorry )
    I am attaching a LWF dynamically. Code below.

    How do I get the bounds for it. I have tried the code suggested on the previous page, but nothing gets returned

    Code (CSharp):
    1. // Attach Tile Background to background layer
    2.         m_tileBackground = m_tileBackgroundContainer.AttachMovie( "TileBackground", "TileBackground"+x+"-"+y); // Add Tile Background
    3.         m_tileBackground.ScaleTo(1.2f,1.2f);
    4.         m_tileBackground.MoveTo(dx,dy);
    5.         m_tileBackground.GotoAndStop( Random.Range(1, m_tileBackground.totalFrames));
    Do you have a working example where you get the bounds returned correctly in c# from an attched LWF movie.

    One of the failed things I tried is this:

    Code (CSharp):
    1.  m_tileBackground.RequestCalculateBounds((m) => {
    2. LWF.Boundsb = m.GetBounds();
    3. Debug.Log(string.Format("{0} {1} {2} {3}", b.xMin, b.xMax, b.yMin, b.yMax));
    4. });
    Whilst trying to work around this, I also noticed that
    LocalToGlobal

    doesnt seem to work as intended, it always just returns 0,0.
    Sorry for all the bugs :D
     
    Last edited: Aug 30, 2014
  6. Kazuki_Sakamoto

    Kazuki_Sakamoto

    Joined:
    Jul 6, 2012
    Posts:
    88
    You can use the button feature of LWF https://github.com/gree/lwf/issues/61
    Or you can also use ScreenPointToRay + Physics.Raycast.
     
  7. Kazuki_Sakamoto

    Kazuki_Sakamoto

    Joined:
    Jul 6, 2012
    Posts:
    88
    This code snippet should work.

    Code (CSharp):
    1.  m_tileBackground.RequestCalculateBounds((m) => {
    2.     LWF.Bounds b = m.GetBounds();
    3.     Debug.Log(string.Format("{0} {1} {2} {3}", b.xMin, b.xMax, b.yMin, b.yMax));
    4. });
    And you may need to call LWF.Movie.LocalToGlobal after update. For example, using update handler.

    Code (CSharp):
    1. m_tileBackground.AddEventHandler("update", (m) => {
    2.             var p = m.LocalToGlobal(new LWF.Point(0, 0));
    3.             Debug.Log(string.Format("local(0,0) -> global({0},{1})", p.x, p.y));
    4. });
     
  8. blastone

    blastone

    Joined:
    Apr 7, 2009
    Posts:
    168
    Putting it on that update callback worked well. I was able to get the LocalToGlobal working perfectly. Many thanks for all your help so far. You have a task in front of you now getting the documentation up to the code evolution now :D
     
  9. blastone

    blastone

    Joined:
    Apr 7, 2009
    Posts:
    168
    Heres a question for you:
    Is there a way to attach movies from a LWF to another LWF object. Say I have a global "stage" LWF object and I want to attach effects from an "effects" LWF object, and characters from a "Characters" LWF Object all on single location, so I can easily manage depth sorting etc etc
     
  10. Kazuki_Sakamoto

    Kazuki_Sakamoto

    Joined:
    Jul 6, 2012
    Posts:
    88
    Yes, it is AttachLWF API. But AttachLWF API can only attach a LWF onto a Movie. So you may need to call AttachMovie from the child LWF. (AttachMovie cannot work across LWF data)

    Code (CSharp):
    1. Base LWF
    2.     _root
    3.         character
    4.             weapon
    5.                 Child LWF - weapon.AttachLWF(...)
    6.                     _root
    7.                         effect - childLWF.rootMovie.AttachMovie(...)
     
  11. blastone

    blastone

    Joined:
    Apr 7, 2009
    Posts:
    168
    Hi Kazuki, is it possible for me to load different textures for an LWF, so for example if I have a base texture, and I've made another duplicate texture with some tinted variations, can I specify a different file to load as the texture?

    I tried by putting a texture into a subfolder and editing the texturePrefix parameter but this didnt work as expected.
     
  12. Kazuki_Sakamoto

    Kazuki_Sakamoto

    Joined:
    Jul 6, 2012
    Posts:
    88
    Hmm, it should work well. LWF actually caches textures and the key of the caches are texturePrefix + texture.name. the default of LWFObject.Load texturePrefix argument is the same path of the LWF data file, but you can override it.
     
  13. blastone

    blastone

    Joined:
    Apr 7, 2009
    Posts:
    168
    I'll try again. Next question :D I was able to get depth sorting working with sortingOrder in the load statement.
    Am I able to dynamically change the sorting order of LWFs so that I can bring them back and forth?
    I tried SetRenderingOffset but I suspect that the sortingOrder overwrites it.
    Ill try again with the texture paths as well, but may send you a project so you can see the issues if I still get he same errors
     
  14. Kazuki_Sakamoto

    Kazuki_Sakamoto

    Joined:
    Jul 6, 2012
    Posts:
    88
    Good question! I have added sortingLayerName and sortingOrder properties in LWFObject instance and a custom inspector which seems as SpriteRenderer, for it. So I had to change LWFObject.Load API, sorry. You can change these properties dynamically in GUI and from code.
     
  15. Kazuki_Sakamoto

    Kazuki_Sakamoto

    Joined:
    Jul 6, 2012
    Posts:
    88
    For example, in this data,
    https://github.com/splhack/Hello-LWF-Unity/tree/master/Assets/Resources/cat

    Code (CSharp):
    1. $ cd Assets/Resources/cat
    2. $ mkdir another
    3. $ cp cat_atlas.png another
    4.  
    And modify the tint color of another/cat_atlas.png,

    Code (CSharp):
    1. Load("cat/cat", texturePrefix:"cat/another/");
    2.  
    It works well.
     
  16. blastone

    blastone

    Joined:
    Apr 7, 2009
    Posts:
    168
    You sir, are awesome. That sortingDepth works perfectly, and its exactly what I needed. the multi texture loading works perfectly too. Great work mate.
     
  17. Kazuki_Sakamoto

    Kazuki_Sakamoto

    Joined:
    Jul 6, 2012
    Posts:
    88
    I'm happy to hear that:) You're welcome!
     
  18. Kazuki_Sakamoto

    Kazuki_Sakamoto

    Joined:
    Jul 6, 2012
    Posts:
    88
  19. blastone

    blastone

    Joined:
    Apr 7, 2009
    Posts:
    168
    You know all we need now is Masking support :D
     
  20. Kazuki_Sakamoto

    Kazuki_Sakamoto

    Joined:
    Jul 6, 2012
    Posts:
    88
    Yeah, I know:D Actually I did try it with Pro license, but RenderTexture didn't work as I expected...
     
  21. hoangdackien

    hoangdackien

    Joined:
    Nov 18, 2013
    Posts:
    2
    Hi there ! I can't using bitmap Font renderer with windows platform.
    i think fontconv.rb only using with Mac OS.
    Pleases help me solve it with windows OS.
    Thanks !!
     
    Last edited: Sep 12, 2014
  22. Kazuki_Sakamoto

    Kazuki_Sakamoto

    Joined:
    Jul 6, 2012
    Posts:
    88
    Yes, fontconv.rb works only on OS X. And I’m afraid I have a bad news about that. BitmapFontRenderer had been deprecated. You can render text using the latest LWF without BitmapFontRenderer nor SystemFontRenderer. LWF uses TextGenerator API right now.
     
    hoangdackien likes this.
  23. hoangdackien

    hoangdackien

    Joined:
    Nov 18, 2013
    Posts:
    2
    thank you so much. I will try it now. !!
     
  24. Kazuki_Sakamoto

    Kazuki_Sakamoto

    Joined:
    Jul 6, 2012
    Posts:
    88
  25. k.honda

    k.honda

    Joined:
    Oct 24, 2014
    Posts:
    2
    Kazuki_Sakamotさん
    はじめまして、最近になってUnityでLWFを使い始めたものです。
    いきなりな質問ですいません。
    ブレンドモードを使ったマスクはUnityでは利用できないという事ですが、
    今後実装される予定はあるのでしょうか?
    というのもUnity+SWFでなんとかマスクつかいた~い!という話から調べていたところ
    コード上にConstant.BLEND_MODE_MASKやIRendererFactory.SetMaskMode等の定義を見つけまして・・・
    これらは単純に他プラットフォーム用の名残でしょうか?
     
  26. Kazuki_Sakamoto

    Kazuki_Sakamoto

    Joined:
    Jul 6, 2012
    Posts:
    88
    As I said, "Actually I did try it with Pro license, but RenderTexture didn't work as I expected..."

    https://gist.github.com/splhack/992233254922771ee748

    I don't have much time to investigate, experiment on RenderTexture properly to implement the mask feature. I'd appreciate if anyone could get there!
     
  27. k.honda

    k.honda

    Joined:
    Oct 24, 2014
    Posts:
    2
    I understand. Thank you.
    Its content has been very helpful.
    Even here I will challenge it.
     
  28. Kazuki_Sakamoto

    Kazuki_Sakamoto

    Joined:
    Jul 6, 2012
    Posts:
    88
  29. blastone

    blastone

    Joined:
    Apr 7, 2009
    Posts:
    168
    Hi Kazuki,
    one thing I noticed is that using LWFS with a lot of flash animations, I end up with a lot of texture sheets.

    In a previous project I used a system where I would have PNG images for my textures, then compress them using TinyPNG.org ( or similar tools eg imageOptim ).

    I would then rename the compressed png file to .bytes and put it in the resources folder.
    What it meant for me was that I could get much smaller file sizes ( 70% smaller ) then I would get with using unity compression.

    My question then: Is it easy for me to pass through a texture2d to LWF so that I can use this system, as keeping the quality high, and the file size low is important.

    For reference attached is a simple project showing how I used it, which should you think is worthwhile, you are welcome to use or include it.
     

    Attached Files:

  30. Kazuki_Sakamoto

    Kazuki_Sakamoto

    Joined:
    Jul 6, 2012
    Posts:
    88
    You can set TextureLoader and TextureUnloader via ResourceCache.SetLoader for global or via LWFObject.Load for just the LWFObject instance.

    Code (CSharp):
    1. LWF.UnityRenderer.ResourceCache.SharedInstance().SetLoader(
    2.     textureLoader:(name) => {
    3.         Texture2D texture2d;
    4.         // load texture2d yourself
    5.         return texture2d;
    6.     },
    7.     textureUnloader:(texture2d) => {
    8.         // unload texture2d yourself
    9.     });
     
  31. blastone

    blastone

    Joined:
    Apr 7, 2009
    Posts:
    168
    Hi Kazuki,
    do you have on your roadmap a uGUI wrapper, that allows LWF animations to be layered with uGUI?
    I have a LWF animation I want to put over some uGUI content ( and possible with a title so it needs to be layered ).
     
  32. janimator

    janimator

    Joined:
    Apr 5, 2013
    Posts:
    52
    When playing lwf in unity I find that the separate symbols being displayed are far to spread apart in z-depth. Is there a way to bring them closer together. I know i can change the z scale of the GameObject, but was hoping for something that doesn't require adjusting the transforms of the main game object.. Perhaps a way to set the scale and transform for the mesh object that gets created when using lwf? (I'm not sure how to access that data / image bellow). Or maybe assign it a parent object which I can then control?

    One more question. Is it possible to retrieve the scene width and height? The one you input when starting a new flash document.
     
    Last edited: Nov 27, 2014
  33. Kazuki_Sakamoto

    Kazuki_Sakamoto

    Joined:
    Jul 6, 2012
    Posts:
    88
    I'd like to implement and release it immediately, but it seems I need more time to do it. I can't say when I will release it. sorry.
     
  34. Kazuki_Sakamoto

    Kazuki_Sakamoto

    Joined:
    Jul 6, 2012
    Posts:
    88
    Could you try to set zRate argument in LWFObject.Load method?

    Code (CSharp):
    1. lwfObject.Load(lwfPath, zRate:0.001f);
    And you can get the scene width and height via lwfObject.lwf.width and height property.
     
  35. janimator

    janimator

    Joined:
    Apr 5, 2013
    Posts:
    52
    Thank you so very much Kazuki!! I'm still looking for a way to translate(move) lwf created mesh without effecting the parent Game Object.

    A dynamic way to do this would be nice but a way to initialize the lwf object in an offset position would also be helpful. I've tried many methods, but have only succeeded in scaling the LWF. Again, if there is a way to control the transform parameters of the mesh object, that might be one way to solve my problem.
     
  36. Kazuki_Sakamoto

    Kazuki_Sakamoto

    Joined:
    Jul 6, 2012
    Posts:
    88
    Eh, ok. I misunderstood it. Did you try to use zOffset argument of LWFObject.Load? You may need to adjust the zOffset value.

    Code (CSharp):
    1. lwfObject.Load(lwfPath, zOffset:100.0f);
    BTW, you can set offset of X or Y coordinate by Move method.

    Code (CSharp):
    1. lwfObject.Move(100.f, 100.f);
     
  37. janimator

    janimator

    Joined:
    Apr 5, 2013
    Posts:
    52
    Just had the time to test Move / zOffset:100.0f / and lwf.width and they all work great. I think i was trying to dig too deep to find those functionalities. Thank you soo much for your expertise!
     
  38. primus88

    primus88

    Joined:
    May 14, 2013
    Posts:
    611
    Where is the actual tool / binary that helps me convert from flash to unity format??
    I checked everywhere and I cannot find those binaries.

    Using Windows.
     
    Last edited: Jan 4, 2015
  39. Kazuki_Sakamoto

    Kazuki_Sakamoto

    Joined:
    Jul 6, 2012
    Posts:
    88
    The tool is LWFS. Please take a look at the site https://github.com/gree/lwfs .
     
  40. primus88

    primus88

    Joined:
    May 14, 2013
    Posts:
    611
    Yeah. I figured it out in the meantime. Took me a very long time since there weren't links pointing towards LWFS.
    Anyway, I followed the procedure for creating swf but the ruby binary is still extracting completely white (no PNGs). I used to get different errors but I sorted them out one by one. So now I don't get any errors but the file is white and there are no images in the output.
     
  41. Kazuki_Sakamoto

    Kazuki_Sakamoto

    Joined:
    Jul 6, 2012
    Posts:
    88
    Hmm, interesting. Have you tried "Publish for LWF" command from Adobe Flash CS6 or CC? LWFS automatically installed "Publish for LWF" command into your Adobe Flash environment. The command extracts bitmaps from fla file.
     
  42. blastone

    blastone

    Joined:
    Apr 7, 2009
    Posts:
    168
    Hey Kazuki, any update on the ugui layering? Currently I'm solving with 2 cameras, but ideally being able to layer with ugui elements will be much better
     
  43. Kazuki_Sakamoto

    Kazuki_Sakamoto

    Joined:
    Jul 6, 2012
    Posts:
    88
    Sorry, no luck to have time to do that...
     
  44. janimator

    janimator

    Joined:
    Apr 5, 2013
    Posts:
    52
    Hi Kazuki_Sakamoto. I always thank you for your great support and would like to keep the tradition. Thank you :)

    I have an issue trying to find the current scale of the lwfObject. Earlier I asked about how I can scale the lwfs and you pointed me to use 'Scale' command which I am embarrassed to have missed. Now I can't seem to find a way to return/get the current scale of the LWFObject. Do you know of a way?
     
  45. Kazuki_Sakamoto

    Kazuki_Sakamoto

    Joined:
    Jul 6, 2012
    Posts:
    88
    You are welcome!

    LWFObject.Scale() and ScaleTo() modify lwfObject.property. And you can use lwfObject.property.m_scaleX and m_scaleY if you didn't use Rotate(), RotateTo() or SetMatrix().
     
  46. Kazuki_Sakamoto

    Kazuki_Sakamoto

    Joined:
    Jul 6, 2012
    Posts:
    88
    Good news! @fum1h1ro implemented a renderer for uGUI!
    https://github.com/gree/lwf/pull/111

    Would you try the latest LWF?
    You should call lwfObject.UseUIVertexRenderer() ahead of Load().
     
  47. AtticusMarkane

    AtticusMarkane

    Joined:
    Aug 6, 2014
    Posts:
    18
    Hi all. I'm hoping you can help me out with what I am guessing is a minor issue.

    I have created my animation in Flash (I'm using CC) and tried to add an event to a frame using fscommand("event", "idleLoopEnd"); But when I try to subscribe to the event in C# it does not work. I dug around in the source code an it appears as though my events aren't even making it into the Events array in the Data class. Any idea why this might be the case?

    Code (CSharp):
    1. AddEventHandler("idleLoopEnd", IdleEndhandler);
    2.  
    3. void IdleEndhandler(LWF.Movie a, LWF.Button b)
    4. {
    5.     Debug.Log("Test A");
    6. }
    upload_2015-2-13_11-8-20.png
     
  48. Kazuki_Sakamoto

    Kazuki_Sakamoto

    Joined:
    Jul 6, 2012
    Posts:
    88
    It seems it should work. Did you use LWFS and "Publish for LWF" command to convert your data? You can download LWFS from https://github.com/gree/lwfs/releases/latest osx or win, and "Publish for LWF" command is automatically installed in your Flash CC environment when you launch LWFS.
     
  49. AtticusMarkane

    AtticusMarkane

    Joined:
    Aug 6, 2014
    Posts:
    18
    Hey, thanks for getting back to me! I did try "Publish for LWF" when I found it by reading through the forums. These are the publish settings after running the jsfl script:

    upload_2015-2-13_15-58-53.png
    upload_2015-2-13_16-22-0.png
     
    Last edited: Feb 13, 2015
  50. AtticusMarkane

    AtticusMarkane

    Joined:
    Aug 6, 2014
    Posts:
    18
    Last edited: Feb 13, 2015