查看: 3032|回复: 1

[实例] Unity创建2d游戏系列教程之三

[复制链接]

36

主题

17

听众

198

积分

问题学生

Rank: 1

升级   99%

发表于 2012-12-18 22:04 |显示全部楼层
资源信息 Tutorial Information
教程名称: Creating 2D Games With Unity3D Part 3(发布原创教程可获得更多积分哦!)
适用引擎:   (资源适用引擎)
教程语种: English
教程等级: 小白(等级越高教程越难,但能学到的东西越多)
教程格式: 图文(请用IE9以上浏览器访问本版块)
教程作者: 转载自互联网 (如有问题请短消息联系作者或发表回复)
点击查看原图
请先回复 --点击试用VIP 美丽分割线

My next game is going to be 2D, but the backgrounds will be forced perspective to give the scene a 3D appearance. Before the artists starts artifying the final backgrounds in Photoshop, I want to make sure the levels are properly laid out for gameplay – the last thing I want is to waste the artists time with re-dos for object position fixes. Since my background is primarily in 3D level design, I decided to blockout the levels in Maya and then render them out to 2D textures. I’m still in the early stages of working out the process, but so far there are already some noticeable advantages to this workflow. The main advantage is that I can easily make adjustments to object positions in Maya, render the scene to a .png, rebuild the sprite atlas in Unity and test out the changes.

I know what you’re thinking – since I have 3D levels blocked out in Maya already, why not use those assets in Unity? Unity is a 3D engine after all so it’s pretty easy to import the models directly into the scene. After a few tests rendering the 2D scenes from Maya and seeing how they looked in Unity, I decided to see if using full blow 3D levels would be the better way to go.

Maya Setup

Note that even tho I’m using Maya, you should be able to apply these setups to any 3D app. Before you import 3D objects from Maya, you need to confirm some Maya settings:

  • In Maya, go to Window -> Settings/Preferences and click on Settings
  • Set the Up Axis to Y since Y is up in Unity
  • Set the Linear Working Units to Centimeters. A 1x1x1 centimeter cube in Maya is the same size as a 1x1x1 unit cube in Unity.

You can test that the above settings are correct by creating a 1x1x1 cube in Maya and then importing it into your Unity scene. Create a 1x1x1 cube in Unity, position the 2 next to each other and they should be exactly the same size.

The next thing I did in Maya was to setup the perspective camera (persp) so that its positioned and angled exactly how I want the scene to be viewed in the game. Here’s a pro tip: Once you have the camera positioned exactly how you want it, select the camera, move the Cursor to frame 1 on the Time Slider, and then set a keyframe on it (Animate -> Set Key or just press ‘s’ on the keyboard). Also make sure that the “Auto keyframe toggle” (located in the lower right hand corner on the Time Slider) is off. Now you can freely rotate the camera while building out your 3D scene, and when you want to see what the scene looks like from the game camera, just move the Cursor on the Time Line from frame 1 to frame 2 and then back to frame 1 and your camera will snap back to the frame you set. Awesome!

Another cool trick is to set the Render Settings Image Size so that it’s the same size as what you expect to see in the rendered game view. Basically it’ll add a box to the perspective camera that will show you exactly the area that will be rendered. Note that I’m using Maya 2008 so your options may be different.

  • In Maya, change to the Rendering menus (drop down in the upper left hand corner)
  • Render -> Render Current Frame. This will open the Render View and render whatever is visible in the active camera.
  • In the Render View window, go to Options -> Render Settings
  • Under Image Size, change the Width and Height to match your games render view. For example, if you’re making an iPhone game you might set this to 480 by 320.
  • Now if you look back at your Maya scene, you should see a 480×320 rectangle.

With the above correctly setup, you should be able to get an accurate view in Maya of what your game will actually look like on the device. Here’s what my scene looks like (click to see the full sized image):

[/url]

Unity Setup

Once you have a level blocked out in Maya, the next thing is to bring it into Unity and set everything up so that it looks the same.

  • To import the level into Unity, all you have to do is save the Maya file into your project’s asset folder (eg. Assets/Models).
  • Drag the level from the Models folder into the Scene Hierarchy and position the model in the scene.
  • Change the Camera in your Unity scene from Orthographic to Perspective if it’s not already.
  • Adjust the Camera’s Position, Rotation and Field of View so that the scene appears exactly has it does in Maya. This will require a bit of trial and error adjustment but eventually you should be able to dial it in exactly.

Prior to this little experiment, my game had been setup to be entirely 2D with objects only moving on the X and Y axis. To make the game truly 3D, you have to bring the Z axis into play. After spending the better part of a day converting my 2D game to 3D (just to test out my theory), I decided that 2D is actually better for my particular gameplay plans. 3D can complicate things rather quickly, especially when dealing with touch events on the iPhone. But none of the above setup is wasted! Because of everything I set above, I can easily go back to my original plan of rendering the 3D scene to a 2D texture in Maya.

Conclusion

This concludes part 3 of the series. I had been planning to take you through the creation of a simple 2D platformer game in this installment, but I’ve been super busy trying to get our new game ready to show to the press at GDC. Instead part 3 went over some of the techniques I’m using to make the new game which hopefully you’ll find useful.
转自:[url=http://www.rocket5studios.com]http://www.rocket5studios.com


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

楼主热帖
已有 2 人评分鲜花 收起 理由
1287537617aa + 1
茶而甜香 + 2

总评分: 鲜花 + 3   查看全部评分

星期天 星期一 过度很痛苦

0

主题

31

听众

20

积分

问题学生

Rank: 1

升级   10%

发表于 2014-4-24 21:13 |显示全部楼层
冒个泡..............................
回复

使用道具 举报

0

主题

13

听众

191

积分

问题学生

Rank: 1

升级   95.5%

发表于 2017-2-21 13:11 |显示全部楼层
楼主是超人
回复

使用道具 举报

2

主题

13

听众

292

积分

小学生

Rank: 2

升级   30.67%

发表于 2017-2-21 13:51 |显示全部楼层
好帖就是要顶
回复

使用道具 举报

0

主题

13

听众

191

积分

问题学生

Rank: 1

升级   95.5%

发表于 2017-2-21 13:52 |显示全部楼层
真心顶
回复

使用道具 举报

0

主题

13

听众

212

积分

小学生

Rank: 2

升级   4%

发表于 2017-2-21 13:21 |显示全部楼层
难得一见的好帖
回复

使用道具 举报

1

主题

14

听众

192

积分

问题学生

Rank: 1

升级   96%

发表于 2017-2-21 13:19 |显示全部楼层
很好哦
回复

使用道具 举报

0

主题

31

听众

193

积分

问题学生

Rank: 1

升级   96.5%

发表于 2017-3-18 13:18 |显示全部楼层
很不错
回复

使用道具 举报

0

主题

31

听众

192

积分

问题学生

Rank: 1

升级   96%

发表于 2017-3-18 13:31 |显示全部楼层
真心顶
回复

使用道具 举报

0

主题

31

听众

237

积分

小学生

Rank: 2

升级   12.33%

发表于 2017-3-18 13:38 |显示全部楼层
难得一见的好帖
回复

使用道具 举报

温馨提示:求助请到“Unity技术讨论”版块中发帖,便于集中解决!
您需要登录后才可以回帖 登录 | 立即注册

Unity3D开发中国社区 -Unity3D,Unreal ( 粤ICP备20003399号 )

GMT+8, 2020-11-29 15:53 , Processed in 0.124465 second(s), 42 queries .