找回密码
 立即注册
查看: 3818|回复: 91

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

[复制链接]
发表于 2012-12-18 22:04 | 显示全部楼层 |阅读模式
资源信息 Tutorial Information
教程名称: Creating 2D Games With Unity3D Part 3(发帖教程)
适用引擎:   (适用引擎,为空默认为Unity)
教程语种: English
教程等级: 1
教程格式: 图文(请用IE9以上浏览器访问本版块)
教程作者: 转载自互联网 (如有问题请短消息联系作者或发表回复)
下载地址: (兑换积分)
点击查看原图
美丽分割线

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鲜花 +3 收起 理由
1287537617aa + 1
茶而甜香 + 2

查看全部评分

发表于 2014-4-24 21:13 | 显示全部楼层
冒个泡..............................
发表于 2017-2-21 13:11 | 显示全部楼层
楼主是超人
发表于 2017-2-21 13:51 | 显示全部楼层
好帖就是要顶
发表于 2017-2-21 13:52 | 显示全部楼层
真心顶
发表于 2017-2-21 13:21 | 显示全部楼层
难得一见的好帖
发表于 2017-2-21 13:19 | 显示全部楼层
很好哦
发表于 2017-3-18 13:18 | 显示全部楼层
很不错
发表于 2017-3-18 13:31 | 显示全部楼层
真心顶
发表于 2017-3-18 13:38 | 显示全部楼层
难得一见的好帖
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-3-29 22:46 , Processed in 0.114358 second(s), 32 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表