The infos provided in their wiki are a bit messy, thus this post will try to serve as another organised starting point for using LWF.
For starters, you need to learn how to convert SWF into something readable by the LWF plugins, using a software provided by them called LWFS:
And here's a tutorial (provided by Gree) on how to play the (converted) SWF inside Unity:
Extra infos about the Flash animation production guidelines are also provided by Gree:
The guidelines are a bit confusing for me, so I'm just gonna write my own version below.
(New) LWF Guidelines
(Once you get a grasp on how the texture and data loading works, and how to display the SWF into the Unity scene...)
1. You can have as many MovieClips in your Flash file as you want. Despite that, I would rather prefer to categorised different animations to different Flash files, before exporting them.
For instance, a character can have an Idle, Walk and Attack animation. If you are exporting them through different Flash files, it'll probably be less messy to put all 3 of them inside a single Flash file.
2. Each of the MovieClips MUST have a Linkage name. In case you don't know how to set up a the Linkage name for a MovieClip:
- Select the "Library" tab in Flash, right click on your MovieClip and select "Properties".
- A small window will popup. Under the "ActionScript Linkage", make sure you check both "Export for ActionScript" and "Export in frame 1".
- Inside the "Class" textfield, place in any Linkage name you like, preferably the one similar to your MovieClip's name as it's easier to keep track of.
- Once you're done, click "OK" and you should be able to see your Linkage name under Library's "AS Linkage".
3. Scene need to have at least ONE MovieClip, with an instance name. It can be any MovieClip you have in your Library. If your scene is empty, drag and place ANY MovieClip in the first frame, give it an instance name (say "animation") in the "Properties" tab.
It doesn't matter what instance name you put, as long as there's at least one MovieClip in the scene which has an instance name.
(Further Note: Since the instance name don't really affect anything else in the data, I just take the liberty and name all the first frame MovieClip's instance name as "animation" for easy referral sake.)
EDITED: I've previously stated that the Flash's scene Properties' Size should be set to your game'e resolution in Unity, in order for it to be displayed correctly. That is no longer necessary as I found another way to go around, by using the width and height properties I acquired from LWF itself.
I've since updated the script, you can check out the changes yourself, it's under the Start() method's ScaleForWidth() and ScaleForHeight().
Attaching and Detaching Movies, Callback Methods, etc
(Once you had made sure your Flash files meet the 4 requirements I stated above, export it, convert into LWF data using LWFS, and you can move on to the next step)
Not sure if the attaching and detaching of Movies is mentioned anywhere in the wiki, but after reading an Issue posted by some LWF users on its GitHub site, I've come to learn about these very useful methods for playing and controlling the Flash animations using the framework.
To start with, this is the full LWF Animation manager I wrote to handle the SWF animations:
LWFAnimator (Download Link)
What each lines do:
- The name of the MovieClip that was mentioned in (New) LWF Guidelines section, where you need to add at least ONE MovieClip, with an instance name, that's the instanceName I'm talking about, which for my case, I usually put "animation". I would advice you to do the same.
- For storing the .bytes data (aka your SWF animation's) name (e.g. "character_anim"; no need to put ".bytes")
- For placing the path of the folder (in Resources folder) where you placed your LWF animation's texture and .bytes data in (e.g. "LWF/character/"; a "/" is required at the end of the string)
- For storing the information of the MovieClip, such as its name, linkage, and wrapMode
- for storing a MovieClip's info:
c. wrapMode (which was simply written by me, to simulate a similar kind of animation behaviour in Unity)
- The basic required method for loading the LWF data
2. Load(folderPath + animName, folderPath);
- The basic required method for loading the LWF data
3. ScaleForWidth(Screen.width / 2);
- Scale the (to-be-spawned) sprite to a size suitable for the screen (width)
- Remember in the (New) LWF Guidelines section, I mentioned about setting the scene's Properties > Size to your game's resolution, this is where it matters.
- As for the divide by 2 thing, I also have no idea why, it just works that way. But I would still prefer to retain the "divide by 2 part" while setting the Flash scene's size to the game's resolution, for formality sake.
4. ScaleForHeight(Screen.height / 2);
- Scale the (to-be-spawned) sprite to a size suitable for the screen (height)
- The rest is the same as ScaleForWidth
- Remember in the (New) LWF Guidelines section, I mentioned that you need at least ONE MovieClip, with an instance name in the scene?
- Basically, once you click "Play" in Unity's editor, the MovieClip's animation will start playing and looping non stop. Which is why I'm putting a stop to the animation from the start, by its instance name, since we're not gonna use it anyway (I'll explain why later)
6. SetVisibleMovie(instanceName, false);
- As we're not gonna use the MovieClip's animation, might as well set it invisible, in case if you have a visible frame in the first frame of the MovieClip
PlayClip(string _clipName) method
1. First, it'll check whether if there's any Movie (or MovieClip) by supplied "_clipName" attached to the LWFAnimator object. If there's a Movie by the name of "_clipName" to be found, it'll first detach the Movie, before attaching a new one next.
- Returns a variable of type:FlashMovieClip (Serializable), which the method can use to attach a MovieClip on the LWFAnimator
3. lwf.rootMovie.AttachMovie(linkageName, clipName, enterFrameCallbackMethod);
- For attaching a MovieClip of the clipName and linkageName, with an enterFrame callback method called "EnterFrameCallback"
4. the attached Movie was store in an array which we'll use later
PlayClip(string _clipName, bool _stopAllPrevMovies) method
1. Same as the one before, except you can decide whether to stop all previous attached movies. So that, you know, only one animation will be played per session. For instance, you don't want a character's Idle and Walk animation to play at the same time right? That's why you use this method.
1. Detach all the movies ever added to the LWFAnimator.
EnterFrameCallback(LWF.Movie _movie) method
1, Check if a particular animation reaches its final frame. You can access various information about the movie to simulate whatever behaviour you want too, but for now, I just want to simulate the WrapModes.
2. For clip with Default and Clamp (or Once) wrapMode, I would want the animation to be detached from the LWFAnimator, so that it would stop playing. I was originally planning to just Stop() and SetVisible(false) using the methods provided, but it doesn't seems to be replayable when you use its Play() nor GotoAndPlay() method later on.
3. For clip with ClampForever wrapMode, I want the animation to stop at the last frame, so I uses the Stop() method provided.
That's about all that I have for LWF for now, if I have more I'll make a part 2 of the post.
Hope the LWFAnimator can help my future self or some of you in getting started on using the framework.
Overall it's a pretty good (free) framework to use.