flash动画导入unity3d简单研究
老外实验的一个思路吧,实用性不强,只能导出简单的动画,且局限性太多,原理即是以XML为中介,进行数据的交换!
Introduction
I have created a system to get animations made in Adobe Flash into Unity. It is by no means a full Flash to Unity conversion, your animations have to be set up in a certain way, and only some things
will be exported.
Note : this is still experimental. I have only tested it with some simple animations. If it doesn't work for you, please let me know.
This should work with all versions of Unity, but it has been written with Unity iPhone 1.5 in mind, so it makes use of one single material with a texture atlas to take advantage of the dynamic batching.
If you use previous versions of Unity iPhone, it shouldn't be too difficult to make it work with SpriteManager.
Your elements (moving movieclips) in Flash have to be masked versions of one image, and they will be converted to seperate meshes with the correct uv-coordinates.
Flash
As mentioned, your Flash animation has to be set up in a specific way. Here are some guidelines, but also check out the attached demonstration (Flash CS3).
- This has only been tested with Flash CS3. I don't know if it works with Flash CS4's new timeline system. It also doesn't export the new 3D properties. But I might look into this at some point.
- The script will only export one timeline. So no sub-animations. It doesn't matter if this timeline is the root, or in a movieclip
- Every element that you which to animate should be a movieclip, and it should be on it's own layer.
- These movieclips should all have two layers. On the bottom-layer you should have your texture-atlas, and on the top-layer you should have a rectangular movieclip that masks the texture.
- Tweens are assumed between keyframes, even if you don't specify a tween yourself
- Tweens will also be linear. So no ease-in or ease-out.
- An element should be present in each keyframe of it's layer, so no "insert empty keyframe"
- If a layer doesn't have a movieclip in it's first frame, it is assumed to be empty, and only labels will be exported
- You can use Color/Advanced to change the color and alpha of your movieclips, but only the left side of this panel will be exported
- If you specify an instance name for a movieclip in the first keyframe, this will be copied to the gameobjects created in Unity.
Once your animation is ready, you just run the jsfl command, and it will trace some C# code in the output panel.
Unity
Copy the cs files to your project. Add the image with your texture atlas to the project as well, and create a new material for it. Create an empty GameObject, add the Animation2D script to this GameObject, and assign your material to it's Material-property.
EDIT : You might want to decrease the size of the gameobject or move it far away from the camera. One pixel in flash will be 1 unity unit, so it might be a bit too big. So set the scale to (0.1, 0.1, 0.1) or something.
Create a new C# script, and also add it to the GameObject. In the Start method of this new script, paste the code you exported from flash. Add Anim.Play(); at the end of the Start-method, and press play in the Unity editor.
Your animation should now be playing back like it does in flash (more or less).
There are a couple of variations on the Play-method. You can play animations looped or not, you can choose two frames between which to play (either by number or by label name), and you can specify a "fade" value (numeric, number of frames) to fade from the current position to the starting frame of the animation before the animation actually starts.
There's also a Pose-method, which is a bit like Flash's gotoAndStop.
EDIT : I have fixed a bug, and have added a dystem so you can animate any type of gameobject, not just the automatically generated uv-sprites. Just give your movieclip an instance name prefixed by an undescore (ie _foo) and it will search for a child-gameobject of your main gameobject named foo and animate that.
TODO :
- add a way to call functions from keyframes (or possibly just broadcast a message).
Enjoy!
有兴趣的朋友可以具体研究测试一下效果!
相关文件下载地址:http://forum.unity3d.com/download.php?id=8176

学习学习