Unity3d android 2d精灵放置 [英] Unity3d android 2d sprites placement

查看:140
本文介绍了Unity3d android 2d精灵放置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请看这张图片
这是从photoshop导出的游戏的最终外观
我用红色标记标记了ui精灵,并用蓝色标记标记了游戏性
我的问题是我应该如何在unity3d 2d游戏开发中正确使用这些精灵.

这是我可以想到的方式:

Please take a look at this picture
It's a final look of the game exported from photoshop
I marked the ui sprites with red marker and the gameplay sprites with blue marker
My question is how should i correctly use these sprites in unity3d 2d game development.

This is the ways i can think of:

  1. 将画布中的红色精灵用作布局组(垂直或水平,因此我可以将它们放置在角落中,并且可以在任何分辨率下使用)内的Image组件
  2. 在画布外使用蓝色精灵,显然是通过Sprite Renderer组件
  3. 通过Sprite Renderer组件在画布中使用蓝色精灵,并将画布渲染模式设置为Screen Space - Camera
  4. 通过Image组件在画布中使用蓝色精灵
  1. Use the red sprites in a canvas as Image component inside a layout group (vertical or horizontal, so i can place them in in the corner and it will work with every resolution)
  2. Use blue sprites outside of a canvas and obviously via a Sprite Renderer component
  3. Use blue sprites in canvas viaSprite Renderer component and set the canvas render mode to Screen Space - Camera
  4. Use blue sprites in canvas via Image component


这些方法可能都是错误的,但我现在能想到的都是这些.
我愿意接受您的所有建议.
我的统一版本是2017.2.0f,我希望游戏能够在所有分辨率下正常工作.


These ways all might be wrong but these are all i can think of right now.
I'm open to all of your suggestions.
My unity version is 2017.2.0f and i want the game to work with every resolution.

推荐答案

我将对所有UI元素(红色精灵)使用Image/Canvas系统.这样,您可以利用CanvasScaler组件和锚点来使UI分辨率独立. (另请参见 HOWTO-UIMultiResolution )

I would use the Image/Canvas system for all UI elements (red sprites). This way you can take advantage of the CanvasScaler component and anchoring to make the UI resolution independent. (also see HOWTO-UIMultiResolution)

使用常规的正交摄影机,游戏性精灵(蓝色)只是世界空间中的SpriteRenderer组件.与在UI画布上完成所有操作相比,这具有更好的性能.而且,(根据经验)在游戏世界中,游戏代码将比处理画布位置要容易得多,因为UI布局系统可能会增加其他转换/复杂性.

Gameplay sprites (blue) would simply be SpriteRenderer components in world space with a regular orthographic camera. This has better performance than doing it all on the UI canvas. Also, gameplay code will (from experience) be much easier in world space, than when dealing with canvas positions, because the UI layout system might add additional transformations/complexity.

最后,您可能需要通过照相机的正射影像尺寸属性来调整蓝色精灵的尺寸.没有一个万能的解决方案,因此您必须进行权衡,考虑从Screen.widthScreen.height返回的实际屏幕分辨率以及实际纵横比(横向与纵向).通常,我建议您查看CanvasScaler源代码,以查看有关如何进行不同缩放的示例. (请参见 Bitbucket上的Unity Technologies用户界面源,尤其是第134行上的方法HandleScaleWithScreenSize.

Finally, you will probably want to adjust the blue sprites' size via the camera's orthographic size property. There is no one-fits-all solution for this, so you will have to make a tradeoff, considering the actual screen resolution returned from Screen.width and Screen.height and the actual aspect (landscape vs portrait). Generally, I would advise to look at the CanvasScaler source code to see an example of how to do different scalings. (see Unity Technologies UI source on Bitbucket, especially the method HandleScaleWithScreenSize on line 134).

这篇关于Unity3d android 2d精灵放置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆