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
    Possible. LWF for HTML5 works well on Webkit CSS, Canvas and WebGL. But the Flash contents should be convertible into LWF data.
     
  2. System32

    System32

    Joined:
    Sep 19, 2015
    Posts:
    13
    I'm pleased to release version 1.1.0 of LWFmagic!

    There are way too many changes to list them all but now there is a FlashCanvas that will display your flashes and handle the mouse. Look how easy it is to use:

    Code (csharp):
    1. FlashCanvas canvas = FlashCanvas.Create(16, 9, 1920, 1080);
    2. canvas.AddFlash<AppleSwf>();
    3. canvas.AddFlash<BananaSwf>(200, 100, 45);
    The code above will create a GameObject named "FlashCanvas" at position 0,0,0 in the world. In it is a quad with a 1920px*1080px texture, the quad size is 16*9 (Unity units). At the top left corner the flash "Apple.swf" is displayed and at x=200px,y=100px the flash "Banana.swf" is displayed and rotated by 45 degrees.

    You can set up a FlashCanvas in the Unity Editor as well. Just drag the script (FlashCanvas.cs) onto any existing GameObject in the scene, set its size and add flashes to it. You can of course have as many flash canvases as you want and they can have any position/rotation.

    By default the FlashCanvas will listen to mouse events from the main camera so stuff like buttons will work out of the box. You can change the input camera to a different one if you want to (for example maybe you want to use a orthographic camera and just use FlashCanvas for your UI).

    Automatic Fonts

    LWFmagic takes care of finding the correct fonts for you as well and put them into Unity. Feel free to use whatever fonts you want for your text fields in your FLA project. Nothing special needs to be done when making your flash, you don't even have to use the "Publish for LWF" option in Adobe Flash that LWF normally requires. Just hit Ctrl+Enter and LWFmagic takes care of getting everything into Unity correctly.

    LWF has some trouble with positioning text fields so that it will look exactly the same in Unity as it does in Flash. It will just be a couple of pixels off though, all you need to do is nudge the text field a little bit in Flash until it looks like it should in Unity.

    Add event listeners in a similar way to how you do it in ActionScript:

    Code (csharp):
    1. AppleSwf apple = canvas.GetFlash<AppleSwf>();
    2. apple.AddPressListener("myButtonName", ExampleHandler);
    Receiving the press event and removing the listener:

    Code (csharp):
    1. void ExampleHandler(FlashEvent fe) {
    2.   Debug.Log("Button pressed!");
    3.   fe.flash.RemovePressListener("myButtonName", ExampleHandler);
    4. }
    Depth matters

    The FlashCanvas takes care of sorting the flashes you display according to their depth and will prevent mouse clicks from passing through to lower flashes if a button on top should be blocking the way. You can swap depth as you wish. For the final presentation in Unity the layers are rendered to a texture for a 100% flat display surface with no chance of the flashes being displayed incorrectly.

    A ton of useful stuff (examples):

    Code (csharp):
    1. GetCurrentFrame / TotalFrames
    2. GetStageWidth / Height
    3. SetScaledStageSize
    4. SetRotation
    5. GetWidth
    6. BringForward / SendBackward
    7. BringToFront / SendToBack
    8. StartDrag
    9. StartRestrictedDrag
    10. StopDrag (with or without position reset)
    11. AddPressListener
    12. AddReleaseListener
    13. AddRollOverListener
    14. AddRollOutListener
    15. AddFscommandEventListener
    16. AddUpdateListener
    17. AddOnEnterFrameListener
    18. AddMouseButtonListener
    19. Stop / Play
    20. GotoAndStop / GotoAndPlay (frames or labels)
    All methods that normally would return void instead return the flash object to support chaining:

    Code (csharp):
    1. apple.SetXY(50, 50).SetRotation(180);
    Instance References

    Every flash class generated by LWFmagic will list available instance names in the generated class, great to have when trying to remember what that button name was. Example:

    Code (csharp):
    1. public class CarSwf : Flash {
    2.  
    3.   public static readonly string[] MOVIECLIPS = new string[] {"frontwheels", "backwheels"};
    4.   public static readonly string[] BUTTONS = new string[] {"frontdoor", "backdoor"};
    5.   public static readonly string[] TEXTS = new string[] {"healthbar"};
    6.  
    7.   ...
    Requirements

    All you need to do is add a new layer in the Unity Editor called "SWF". If it's not there you will get a reminder at runtime.

    Other than that you don't need to do anything else. LWFmagic will warn you if anything is strange with your swf file during conversion to LWF (for example if you are trying to use ActionScript 3, if the flash is not targeting Flash Player 8 or if you forgot to export a shape as bitmap). Just correct the FLA project and export the flash again, LWFmagic will display instructions as needed.

    In conclusion

    I really think LWF can stand on its own now against the paid options for displaying flash in Unity. When using LWFmagic you'll get a really pleasant and hassle-free workflow.

    Edit: Deleted download link for 1.1.0, please get the newest version from http://www.flash-in-unity.net/ instead.
     
    Last edited: Jan 11, 2016
  3. System32

    System32

    Joined:
    Sep 19, 2015
    Posts:
    13
    New version of LWFmagic: 1.2.0

    + You can now use audio in your flashes!

    In your FLA project: Simply add a start/stop/event sound to a frame and export the SWF file normally. LWFmagic will take care of everything so that the sound plays in Unity when that frame is shown. Adding sound effects for hovering over interface buttons becomes very easy.

    Supports playing the sound only once, repeating it a set number of times or looping it forever. Set your FLA project to export its event sounds as either Mp3 or Raw (creates a .wav file in Unity - needed if you want to loop you audio seamlessly). You can override certain methods of Flash.cs to get complete control over the audio as well, it can even be positioned into the world's 3D space (you can for example use FlashCanvas as computer monitors that make noise when the player is close to them). Added support for ActionScript: stopAllSounds();

    + A "rootbutton" is automatically created by LWFmagic to cover your whole stage (positioned behind everything else). So if you only need one button for your flash you don't have to make it yourself in the FLA project, just use the rootbutton.
    + Cleaned up Flash.cs (changed how scaling is taken into account, added getters and setters for width/height, improved built-in dragging).
    + Some new warnings if the SWF file was exported incorrectly that helps you fix any mistakes in your FLA project. No longer warns if the SWF does not target Flash Player 8 (because that doesn't really matter as long as no unsupported things are being used and the program should warn about those if they are in the swf file).

    Edit: Deleted download link for 1.2.0, please get the newest version from http://www.flash-in-unity.net/ instead.
     
    Last edited: Jan 11, 2016
  4. System32

    System32

    Joined:
    Sep 19, 2015
    Posts:
    13
    New version of LWFmagic: 1.2.1

    Small fix, MovieClip instance names will no longer appear twice in created C# scripts.

    Edit: Deleted download link for 1.2.1, please get the newest version from http://www.flash-in-unity.net/ instead.
     
    Last edited: Jan 11, 2016
  5. hectoraofl

    hectoraofl

    Joined:
    Nov 4, 2015
    Posts:
    1
    Have you guys started the upgrade with Flash CC?
     
  6. System32

    System32

    Joined:
    Sep 19, 2015
    Posts:
    13
    What do you mean? Have the LWF guys said that they are planning some big changes?

    (For anyone out there that might be wondering: I'm still working on LWFmagic.)
     
  7. mkureth

    mkureth

    Joined:
    Nov 4, 2015
    Posts:
    1
    To clarify, are there any plans on updating LWF to support Flash Player 10.3+? Currently, Flash CC 2015 only allows publishing to 10.3 - 17. If not, are there any work flow tips to support Flash CS3 from 2008?
     
  8. juunishi_master

    juunishi_master

    Joined:
    Nov 12, 2015
    Posts:
    2
    I use LWFS to convert swf files from the examples included in the LWFS; no error in the conversion, but I somehow could not make it show up on the scene.

    I follow the step by step tutorial from here https://github.com/gree/lwf/wiki/ForUnity

    I changed Load("gree_logo.lwfdata/gree_logo", "gree_logo.lwfdata/"); >> Load ("cat.lwfdata/LWF_sample_charaAnimation", "cat.lwfdata/");

    1. Is it a requirement to name the folder "something.lwfdata"?

    2. I'm using Unity 5.2.2; is there any known issues with this version?

    3. The example I use is from the LWFS_work_examples included in the LWFS installation found in https://github.com/gree/lwfs/releases; I have no idea which flash version they use to make the example.

    I'm sorry for asking such noob questions here. :(
     
  9. System32

    System32

    Joined:
    Sep 19, 2015
    Posts:
    13
    LWFmagic 2.0.0

    The next version of LWFmagic is out and this time I registered a site for it:

    http://www.flash-in-unity.net/

    Grab it over there! There's been countless of changes since the last version, which is why it jumped all the way up to v2.

    A demonstration Unity project has been created to show off most of the things LWFmagic can do, please check it out.

    If you use LWFmagic I'd be happy to know it, leave a message on the site!
     

    Attached Files:

    Last edited: Jan 12, 2016
  10. System32

    System32

    Joined:
    Sep 19, 2015
    Posts:
    13
    LWFmagic 2.1.0

    + Tweens can now be created from C# with the easing methods available in ActionScript (plus some new ones).
    + The path text fields during config/install now finally have browse buttons.
    + Some fixes here and there.

    Get the new version over at http://www.flash-in-unity.net/ or grab the tween demonstration.
     

    Attached Files:

  11. System32

    System32

    Joined:
    Sep 19, 2015
    Posts:
    13
    LWFmagic 2.2.0

    New method in the Flash class: AttachButtonLogic()

    This makes it very easy to make a flash into a button similar to how a button is in a FLA project.

    On your swf file's timeline you should have five frames: 1 = Up, 2 = Over, 3 = Down, 4 = Pressed, 5 = Disabled. Then you simply call ButtonLogic() on your Flash in Unity and provide a handlerMethod. Now it will behave pretty much just like a button in a real flash file and when the player press the button you get a call to your handler method (for doing whatever the button is supposed to do and for resetting the button if you want it to be pressable again - resetting is done simply by calling ButtonLogic() again or by calling GotoAndStop(1)).

    Get it on http://www.flash-in-unity.net/
     
    Last edited: Jan 27, 2016
  12. System32

    System32

    Joined:
    Sep 19, 2015
    Posts:
    13
    LWFmagic 2.3.0

    New method in the Flash class: AttachEditableLogic()

    This will make a textfield editable by the player. Click its hit area to gain focus and then change the value. Complete with movable caret character, Ctrl + Z/X/C/V support and gainFocus/lostFocus/changed/submit handlers. This version also have many other improvements (such as the ability to delay a tween start by X seconds).

    Get it on http://www.flash-in-unity.net/ or check out the new demonstration project (the third one).
     

    Attached Files:

    Last edited: Jan 27, 2016
    sonofbryce likes this.
  13. jswitalski

    jswitalski

    Joined:
    Aug 23, 2016
    Posts:
    1
    Does anyone know if it is easy to change that LWF supports only loose-less images in swf files? Right now in my project we have thousands of swf files with set quality to jpeg, and rebuilding them is big pain in ass for us. Any help very appreciated.