12 第1页 | 共2 页下一页
返回列表 发新帖
查看: 4306|回复: 12
打印 上一主题 下一主题

untiy3d iphone简单动画开发教程(二)

[复制链接]

5552

主题

2

听众

8万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
11

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

跳转到指定楼层
楼主
发表于 2011-12-16 17:40:24 |只看该作者 |倒序浏览
1. Create a new Project: Go to File –> New Project –> Set… and browse to where you keep your Unity projects (mine are in DocumentsUnity Projects), then in the Save As… field type “Tut1-TouchAnim” and click the Save button.
2. Create Project folders: In the Project panel, click the Create button and then select Folder from the list. This will add a new folder to your Project named New Folder. The folder is also created on the hard drive in your Tut1-TouchAnimAssets directory.
Click once on the folder name (New Folder) to edit it and type “Objects” (without the quotes).
Click anywhere in the Project panel to deselect the Objects folder then click the Create button again and select Folder from the list. Rename this 2nd folder “Scripts“.
Click anywhere in the Project panel to deselect the Scripts folder then click the Create button again and select Folder from the list. Rename this 2nd folder “Textures“.
3. Save your Scene: Go to  File –> Save Scene and name it “Tut1-TouchAnim”
4. maya Setup: In Maya go to Window –> Settings/Preferences –> Preferences and then click on Settings in the Preferences window.
– Set the Up axis to “Y” since Y is up in Unity.
– Change the Linear Working Units to “Millimeter”. Currently I find that this is the best scale for getting a good (close enough?) 1:1 size from Maya to Unity.
Note: please feel free to comment on the above Maya settings if you’ve found a better setup.
5. Create an object in Maya: I’m using Maya 2008, but the general ideas here will apply to any modeling/animation program.
Make a cube by going to Create –> Polygon Primitives –> Cube and then draw out a rough cube on the grid.
Select the cube and then in the Channel Bar under INPUTS click on polyCube1 (yours may be named slightly different). Set the Width, Height and Depth to 20 (this assumes your working units are set to millimeters).
Set the Translate X:0, Y:0 and Z:0 so the cube is centered on the grid.
Set the Rotate X:45, Rotate Y:45, and Rotate Z:45. This will make the cube kinda stand up on one corner to give the animation a little visual interest.
6. Animate the cube: We’re going to be making 2 very simple animations where the cube will rotate “forward” 180 degrees and then rotate “backward” 180 degrees to its default position.
First create the forward animation:

With the Timeline slider at Frame 1 and your Cube selected, press the “s” key to add a frame. Or go to Animate –> Set key (you’ll need to be in Animation mode).
Drag the slider on the timeline to Frame 10, change the cube’s Rotate Y:225 and press “s” to add a new keyframe at frame 10.
Next create the backward animation:

Drag the timeline slider to Frame 20, change the cube’s Rotate Y:45 and press the “s” key to add a new keyframe at frame 20.
That’s it for the animations. As far as Maya is concerned, we’ve only created 1 animation, but in Unity we’ll see how this single Maya anim can be made into 2.
7. Save the animated cube: In Maya go to File –> Save Scene As… and browse to your Tut1-TouchAnimAssetsObjects directory and save it there as cubeAnim.mb.
8. Setting up the animated object in Unity: Switch back to Unity and you’ll see that there’s now a file in the project’s Object folder named “cubeAnim”.
Select cubeAnim (top node) in the project’s Objects folder and then click on the Settings… button.  This will bring up a dialogue that allows you to adjust the objects Import settings.
Click the Add clip button which will add a default animation to the list below named “idle”. Click on the word “idle” and type in forward. Leave first frame set to 1 and change the last frame to 10.
Click the Add clip button again, click on the “idle” text, and type in backward. Leave the first frame set to 11 and change the last frame to 20.
Leave “loop frame” unchecked for both clips.
Click the Import button and after a few seconds you should see in the Project panel under cubeAnim that there are now 2 animations named backward and forward. If you select cubeAnim and look in the Inspector under Animations, you’ll see that Element 0 has the “forward” animation assigned and Element 1 has the “backward” animation assigned.
9. Adding your object to the Scene: First thing we’re going to do is add a new empty Game Object to the scene which we will Parent our cubeAnim object to. Go to Game Object –> Create Empty. You’ll see that a GameObject has been added to the Hierarchy panel.
Next select the cubeAnim object in the Projects panel and drag-and-drop it onto the GameObject in the Hierarchy panel to make the cubeAnim a child of GameObject. Your cubeAnim object should now also be visible in the Scene and in the Game panel (if you have it open).
Note: you could simply drag cubeAnim into the scene without parenting it to a GameObject, but you’ll find that when the cubeAnim’s animation plays, it’ll always reset its position in the Scene to Frame 1 as it was set in Maya. With the cube parented to a GameObject, you can move the GameObject anywhere in the scene and the animation will play at that location.
10. Adding a script: In the Project panel, select the Scripts folder, click the Create button, and select JavaScript from the drop down list. This will add a new script to the Scripts folder named NewBehaviorScript. Click on the scripts text and rename it to TouchAnim.
Double click the TouchAnim script in the Projects panel to open it up in Unitron (or whatever script editor you have set).
Download my TouchAnim.js file (right or ctrl click to save as…) and copy/paste the contents into your own script.  Save your script file and then task back to Unity. If you click on the TouchAnim script in the Project panel, you should see the contents of the file in the Inspector.
11. Attach the script to your object: Select the TouchAnim script in the Project panel and then drag-and-drop it onto the cubeAnim object in the Hierarchy panel.
To confirm that the script is attached, select the cubeAnim object in the Hierarchy panel and you should see Touch Anim (Script) component listed in the Inspector.
12. Add a Mesh Collider to your object: Select cubeAnim in the Hierarchy panel and then go to Component –> Physics –> Mesh Collider. This will add the Mesh Collider component to your object — you should see it in the Inspector. Without a Mesh Collider the script won’t be able to detect a collision with your cube.
At this point, if you press the Play button on your Game view, you can mouse-click on/off the cube and it should animate forward and backward.
13. Adjusting the Main Camera : Something that I don’t understand about the default Main Camera Position and Rotation, is that it’s set to look at the scene from the back instead of the front. Which means any objects you import from Maya will look backwards in the Game view.  We’re going to set up the Main Camera so that it’s facing (what I consider to be) forward and adjust its position so that it’ll nicely frame the background image we’ll be creating in the next step.
Select the Main Camera in the Hierarchy panel and set Position: 0,0, 8.1 and Rotation: 0, 180,0.
14. Adding a textured background: To give the scene a little nicer presentation, add a Plane by going to Game Object –> Create Other –> Plane.  This will add a Plane at 0,0,0.
Select the Plane in the Scene or from the Hierarchy and set Rotation:90,0,0.  The default position (0,0,0) and Scale (1,1,1) should be just right for the Main Camera we setup in the previous step.
Your new Plane will have the Mesh Collider component on it by default (mine does at least).  You’ll need to remove this so that the script will only collide with the cube and not with the background.  Select the Plane, then in the Inspector click the little “gear” icon next to the Mesh Collider component and select “Remove Component” from the dropdown list.
Download this default grid texture and put it in your Tut1-TouchAnimAssetsTextures directory.
In Unity, select the defGrid texture from the Project’s Textures folder and drag-and-drop it onto the Plane in the Scene view.  If you adjusted the Main Camera position and the Plane rotation correctly in the previous steps, the Grid pattern should fit perfectly in the Game view.
15. Adding a Light to the scene: To get a nice bright rendering of the scene, add a light by going to Game Object –> Create Other –> Directional Light. This will create a new Directional Light at 0,0,0. Move the light somewhere near the Main Camera and rotate it so it points at the cube. My position is set to 0,0,15 and the rotation is set to 0,180,0.
All of the default light settings for the Directional Light should work fine, except change the Render Mode to “Force vertex”.  I’m not sure yet what that does, but that’s how the iPhone-Match game has their Directional Light set.
16. Set the iPhone Bundle Identifier: I’m still a bit confused as to exactly how this works as I think it’s supposed to somehow match your App ID that you setup at the iPhone Developer Portal. But I set my Bundle Identifier to * (asterisks) so I assumed that’s what I’d enter in Unity… but that doesn’t work for me.
In Unity, go to Edit –> Project Settings –> Player to display the player settings in the Inspector. Next to iPhone Bundle Identifier, you should see “com.Company.ProductName“. I set this to com.bleepng.touchanim which works for me. You may need to play around with this on your side to get it to work properly.
17. Play it in Unity: We’re all done. If you press the Play button in your Game view, you should be able to click on and off of the cube to see the animation play forward and backward. Note that the animation should only play if you click directly on the cube, not on the background plane.
Note, if you want the animation to play when you click anywhere on the screen, simply remove the if (Physics.Raycast (ray, hit, 100)) lines from the script.  Or add a Mesh Collider component to your background Plane.
18. Build & Run it on your iPhone: Setting up Xcode and configuring your iPhone to run apps is beyond the scope of this tutorial, so I’ll assume you’ve done all of that already.
Launch Xcode and plug in your iPhone. Be sure to unlock your phone or Xcode may give you warnings when it tries to install and launch the app on your phone.
In Unity, go to File –> Build & Run and then click the Build & Run button on the Build Game screen.  At the Save Player window, type touchanim and click Save.
Once Unity finishes building the game, Xcode will compile everything, install it on your iPhone and automatically launch it (if your iPhone isn’t locked).
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

1023

主题

3

听众

359

积分

设计实习生

Rank: 2

纳金币
335582
精华
0

最佳新人

沙发
发表于 2012-1-26 23:24:39 |只看该作者
新年的风,吹散你的阴霾;新年的雨,冲刷你的无奈;新年的雾,锁定你的失败;新年的日,照耀你的期待。新年到来,幸福怀揣,新年快乐,响彻天外!
回复

使用道具 举报

1023

主题

3

听众

359

积分

设计实习生

Rank: 2

纳金币
335582
精华
0

最佳新人

板凳
发表于 2012-3-13 23:20:28 |只看该作者
你们都躲开,我来顶
回复

使用道具 举报

797

主题

1

听众

1万

积分

资深设计师

Rank: 7Rank: 7Rank: 7

纳金币
5568
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

地板
发表于 2012-3-16 19:43:10 |只看该作者

   
回复

使用道具 举报

797

主题

1

听众

1万

积分

资深设计师

Rank: 7Rank: 7Rank: 7

纳金币
5568
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

5#
发表于 2012-3-16 19:43:24 |只看该作者

   
回复

使用道具 举报

5969

主题

1

听众

39万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

6#
发表于 2012-3-19 23:27:04 |只看该作者
无聊时可以刷屏幕 灌水 也可以试试 帖子的标题究竟可以写多长
回复

使用道具 举报

1023

主题

3

听众

359

积分

设计实习生

Rank: 2

纳金币
335582
精华
0

最佳新人

7#
发表于 2012-4-20 23:19:23 |只看该作者
此地無銀。。。
回复

使用道具 举报

   

671

主题

1

听众

3247

积分

中级设计师

Rank: 5Rank: 5

纳金币
324742
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

8#
发表于 2012-4-24 08:09:35 |只看该作者
你们都躲开,我来顶
回复

使用道具 举报

tc    

5089

主题

1

听众

33万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

9#
发表于 2012-7-20 23:25:16 |只看该作者
你们都躲开,我来顶
回复

使用道具 举报

462

主题

1

听众

31万

积分

首席设计师

Rank: 8Rank: 8

纳金币
2
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

10#
发表于 2012-8-13 09:33:10 |只看该作者
我看看就走,你们聊!
回复

使用道具 举报

12 第1页 | 共2 页下一页
返回列表 发新帖
您需要登录后才可以回帖 登录 | 立即注册

关闭

站长推荐上一条 /1 下一条

手机版|纳金网 ( 闽ICP备08008928号

GMT+8, 2024-4-19 21:27 , Processed in 0.093369 second(s), 33 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部