Unity Tiny Mode 学习笔记(二) Tiny Mode和Unity区别

发表于2019-01-06
评论3 1.58w浏览

Unity2018 Tiny Mode 学习笔记(一)

http://gad.qq.com/article/detail/288940


年底赶工太忙了,更新时间有限,不过还是不能停下来:)))


现在把第二篇学习笔记分享上来


Tiny Mode提供了一套工作流功能(workflow features)和专门的构建管线(pipeline) 


Tiny Mode是在Unity Editor中创建小巧,轻量级的HTML5游戏和应用。


例如,创建playable ads(可以玩的广告)或者Messaging Platforms游戏,比如Facebook Messenger 




(图3右下角蓝色的Play Now) 


(本文提到的workflow指的是TinyMode,Unity的workflow叫做standard or normal workflow) 


大部分Unity的workflow(standard or normal workflow)功能都可以在TinyMode下进行使用,可以方便Unity的开发人员,更快的上手。


TinyMode仅支持2D精灵的渲染,不支持3D,比如说3D Rendering, Navigation, Terrain, Multiplayer, detailed Physics等等,为了确保包体和内存足够的小,进行了大量功能上的阉割。



If you're making a game or app for consoles(xbox,ps4,Wii U,Switch), Desktop(MacOS or 


Windows), VR, or as a standalone smartphone release, Tiny Mode is probably not the best 


choice. However, if you want to create messenger games, ads, or other HTML5 projects 


with a very small file size and memory footprint, Tiny Mode is the right choice. 



官方明确指出,如果你开发的游戏是面向桌面应用,平台游戏,或是智能设备游戏或App等等,


TinyMode并不是一个好的选择。



但是,如果你想要开发包体和内存占用都很小的游戏,TinyMode会是一个非常好的选择。 


这里有一个关于Unity和TinyMode在workflows和features上的差异化列表,很值得参考 

 

https://docs.unity3d.com/Packages/com.unity.tiny@0.13/manual/compatibility.html 





(左边是Unity Features,右边是Tiny Features,空白表示不支持,可以见得,TinyMode进行了大量的功能阉割, 为了减少包体和内存)



TinyMode和Unity有什么区别? 



1.ECS is enforced 


从技术的角度来讲,最显著的差异,TinyMode是基于Entity Component System (ECS)  


Entity-Component-System Pattern 


ECS可以显著的提升性能,他不是可选的功能(optional),所以你必须遵从ECS的原则,在ECS的基础上去构建你的项目。(you must build your project according to ECS principles) 


ECS概念(wikipedia): 


https://en.wikipedia.org/wiki/Entity%E2%80%93component%E2%80%93system


2.Tiny Mode Projects


Tiny Mode在Unity是一个Asset资源文件的形式存在的( special Asset file) 


一个Unity Project可以包含多个Unity TinyMode Proejcts,通常,Unity Editor同一时间 


只能打开一个TinyMode工程。 

 


重复提下导入TinyMode Sample的2种方法: 




双击tiny-samples,可以导入所有的samples项目示例 


TinyMode项目工程是以.utproject结尾的文件(asset files) 


utproject文件,里面包含了我们使用到的Tiny Mode modules及一些配置settings信息,比如屏幕的尺寸screen size.


关于settings:

https://docs.unity3d.com/Packages/com.unity.tiny@0.13/manual/settings-main.html



打开TinyMode项目: 


Tiny->File->Open Project



打开任意的工程目录,选择*.utproject导入即可 


另外一种导入Sample的方式:  菜单栏要开Tiny > Import Samples menu item



3.The Hierarchy window 


层级视图的区别



在Hierachy中,我们看到的并不是常规的Scenes和GameObjects,而是称为Entity Group和Entities 


Entity Group对应Scenes

Entities对应GameObjects


4.Entity Components vs. GameObject Components 


Entity Components和GameObject Components功能很相似,Tiny Mode也提供了很多内建的Components, 


比如 


 Camera rendering, collision, audio, particles, UI, etc 


 在Unity当中,我们可以添加Components到任意的GamObjects下,在TinyMode下,你也可以将 


Components添加到任意的Entities下。 


所以Entity和GameObjects在功能上很相似 


TinyMode也支持自定义Components 


Entity和GameObject之间,不同的地方: 


TinyMode中Entity是纯数据容器(data containers) 


Tiny Mode components are purely data containers 


每一个Entity都是一组相关的数据集(organised, named, and related sets of data),这些数据集的类型包含 


 such as ints, floats, Vectors, Colors, Strings and enums, however they cannot contain any code.  


如上所说,他们不包含任何的代码,是纯数据的容器。 


但是Unity Component是可以同时包含数据和代码的。 


Entitiy是ECS模式的一部分,这样做的目的是为了提高性能和减小运行时消耗。 


另一点重要的区别是: 


我们不能向Entity添加多个相同type的Components.这在UnityComponents中是支持的,通常在Unity端也不建议这么做 


5.Entity Groups vs. Scenes 


TinyMode中并不会使用Unity Scenes,TinyMode使用Entity Groups


UnityScenes和Entity Groups功能很相似,他们有相同的内容层次结构,Entity Groups下只能包含Entites,不能包含GameObjects 


在层次结构(Hierarchy )中可以有多个Entity Groups,就像Unity的Hierarchy中可以有多个Scenes一样 


Entity Groups可以在运行时进行加载和卸载 (loaded and unloaded) 


Entity Groups也是以Asset资源的形式存放在项目中,和UnityScenes不同,是完全不同的文件格式(file format)和后缀(*.utdata) 


但是在功能上,Entity Groups和Scenes是一样的 


TinyMode有很多的build-in内建的组件,和许多Unity GameObject组件很相似,比如TinyMode有Sprite2DRender,Unity有SpriteRender,他们做着同样的事情,但却是不同的类实现,以及有不同的特性。相应的,其它诸如Animation,Physics,TiledMaps,Audio,他们虽然很相似,却差别很大,具体可以参考docs. 


6.The Inspector window 


When inspecting an Entity in Tiny Mode, the Inspector window displays the Tiny Mode components attached to that Entity 


在TinyMode模式下,我们在Inspector里查看Entity上都绑定了哪些组件components, 与Unity当中,查看GameObject绑定了哪些组件components的方式相似 


Tiny Mode uses a concept of Component families which is not present in regular Unity. 


区别是Tiny Mode使用一个叫Component families组件家族的概念 


Component families 


Component families are groups of related components 


一组相关的组件 


在TinyMode中,实际上是将Components进行了更细小的组件拆分,比如 


Sprite Renderer component or Camera component cover many different uses such as sorting, tiling, clipping, etc. 


包含了大量的参数,用于不同的用途, 经如camera和spriteRender中有大量的参数sorting,tiling,clipping......




上面两张图中,是Unity的GameObject,我们使用不到的参数(功能)是无法进行剥离(omit),所以 


我们不得不用更多的物理空间和虚拟空间去存储和处理它们。


但实际情况是我们只使用部分参数(功能),上面中SpriteRender中的Flip,Sorting Layer,Order in Layer等,Camera下的allow hdr ,maAA,targetTexture,depth我可能在某些需求上,都是用不到的。


但在Tiny Mode中,很多参数其实都是独立的组件: 



比如Transform包含position,rotate,scale,这三个字段并不是都是我们需要的,可能我只是在某个

位置上显示角色,不会进行角度以及size的改变,那么rotate,scale就会占用多余的存储空间,在Tiny Mode中可以进行剔除(omit)


Camera里有LayerSorting参数,如果我只有一个Camera,也就涉及不到层级sort的问题,在Tiny Mode也可以进行剔除(omit),以减少不必要的资源占用。


某些你不需要的参数(功能),你可以选择剔除它们(omit),删除不必要的参数(功能,features) 


这样可以使我们build出来的包,体积和内存占用上更小,更加合理。 


you can omit them entirely. This allows you to trim unnecessary functionality from your project resulting in the smallest possible build. 


关于component-familie的详细说明:

 

https://docs.unity3d.com/Packages/com.unity.tiny@0.13/manual/component-families.html 

进行更为详细的说明 


7.The Play button


In Tiny Mode, you cannot preview your project within the editor by pressing the Play button. Instead, pressing the play button performs the same action as exporting a build of your project. 


When you press the Play button, Tiny Mode quickly creates a build of your project and runs it in your default web browser. 



Tiny Mode在Unity Editor中编辑开发,但不会在Editor中运行游戏的实际效果,当我们点击Play, Unity会快速编译项目,并在你当前的默认浏览器中运行游戏。

 (这里游戏的开启和结束都会有编译的过程,实际上并没有对代码进行修改,希望未来Unity可以优化到)



安装的注意事项: 


Installing the package 


https://docs.unity3d.com/Packages/com.unity.tiny@0.13/manual/installing-tiny.html 


避免多版本混合用 


Sample Projects 


https://docs.unity3d.com/Packages/com.unity.tiny@0.13/manual/sample-projects.html 


本文参考地址


https://docs.unity3d.com/Packages/com.unity.tiny@0.13/manual/intro-for-unity-developers.html 


https://docs.unity3d.com/Packages/com.unity.tiny@0.13/manual/component-families.html 



感谢您的阅读, 如文中有误,欢迎指正,共同提高 


欢迎关注我的技术分享的微信公众号,Paddtoning帕丁顿熊,期待和您的交流


如社区发表内容存在侵权行为,您可以点击这里查看侵权投诉指引