UnityLearn_Beginner_UnityTips

UnityLearn_Beginner_UnityTips

Tutorial. Unity Tips

Unity官方教程_BeginnerLevel

https://learn.unity.com/tutorial/unity-tips#5c7f8528edbc2a002053b481

Snap

当移动、旋转、缩放物体时,可以按住Ctrl/ Cmd键,能够按步长进行更改。
比如每次移动1m,每次旋转15°等等
步长可以在Edit -> Snap Settings中进行设置

Preview Window:

资源文件的Inspector面板下面有一个Preview面板,一般而言是固定在Inspector下的。
可以右键Preview面板上方的bar,就能undock它

快速定位Camera位置:

在Scene中将视角调到合适位置和角度,选中需要改变的Camera,选择GameObject -> Align With View
  可将相机的位置和角度调至Scene中的视角

选中一个Camera后,选择GameObject -> Align View To Selected
  可将Scene中视角调整至与Camera相同

在Inspector中像调整Slider.value一样调整public variable:

在public variable上加上Range decoration:
  [Range(1.0f, 10.0f)] 即可

在Inspector中显示private variable:

public variable可以在Inspector面板中显示
但是,为了在Inspector面板中显示,而使用了public的话,则vialate the encapsulation principle
解决方法: [SerializeField] attribute

大型项目的注意点:

Before Starting:

Source Control:

Unity Editor集成的source control service: Collaborate

使用external source control: Git/ Svn/ Mercurial/ Perforce等工具,需要注意
1. 不要包括Library, Temp, obj,因为在另一台电脑打开工程时是不需要这些文件的
  它们会导致repository的杂乱、并占用大量存储空间
2. Version control to Visible Meta Files:
  将meta files放置在assets资源文件边上,这些meta files存储了相关属性值和设置值
  这样做的话可以在组员之间共享这些资源文件的配置设置
  否则,会将meta files存放在Library文件夹中,导致不能上传到Git共用
3. Asset Serialization to Force Text:
  make all unity files (ScriptableObjects, Scenes, Prefabs and many others) use a text representation instead of a binary one.
  这么做可以 1. 使Source control只存储对这些文件的更改,而不是一份完整的文件拷贝
  2. 可以手动merge文件更改的conflicts
  在项目初期就进行asset serialization的设置是被推荐的

Scales and Standards:

Units:

对于使用rigidbody的3D游戏: 1 unit = 1 meter,以便物理引擎准确的模拟

对于使用rigidbody的2D游戏: 定义一个"base sprite size" 以确定 1 base size = 1 unit = 1 meter
  比如设置32px = 1 meter = 1 unit.
  将所有的Sprite的Pixel Per Unit都设置为该值(32),以便物理引擎的模拟

Naming Convention:

所有资源文件的文件名都遵循相同的Naming Convention.
比如:
  appending suffixes: 比如 _N for normal map, _AO for ambient occlusion map
  prefixes: 比如 LowRes_ 和 HighRes_
方便于: 
  filter through search
  write custom importer setting value automatically

Project Structure:

Folders:

.meta文件记录了对应资源文件的导入设置(import settings)
因此在移动资源文件时,需要在Unity Editor的Project View中进行操作, 这么做Unity会take care of moving everything properly
或者在操作系统的Explorer中移动时将对应的meta文件也随着资源文件一起移动,否则会导致引用丢失(lose references)和导入设置的丢失

文件夹的创建规则
  两条遵循的方法:
  1. A folder for each type of asset, and subfolders per objects/ zones
    比如(Assets/Materials; Assets/Prefabs; Assets/Materials/Level1;)
  2. A folder per objects/ zones
    比如(Assets/Level1/Enemy/Archer; Assets/Shared/UI; Assets/Forest/Trees)
    所有有关的资源都放置在对应文件夹下
    比如(Assets/Forest/Trees/BigTree.fbx; Assets/Forest/Trees/SmallTree.mat)

如果项目用到Assets Bundles时,使用第二种方法会很方便
  可以很方便地create bundles per content themes by adding the parent folder to a specific bundle
  并splitting the related assets through different bundles.

Prototype Folders:

原文: Keep everything that is related to a prototype or placeholder in a separate folder hierarchy, and avoid cross referencing between those folders and folders which contain shippable assets/code. For example, your Character prefab in the "normal" file hierarchy should not reference a test material in your Prototype folders. Create a prototype character prefab that would reside in the Prototype folders and never use that prefab in a non prototype scenes (you could even write editor scripts that check references used by objects in the prototype folder to be sure that this rules is enforced. )

Resources:

尽可能地在Resources文件夹中存放资源。

Resources文件夹中的资源可以通过脚本Resources.Load()被动态加载,
但是Unity不会去判断该文件夹中的资源是否真的被加载/使用,因此所有资源都会被打包到Build中

使用path/ filename,会对后期项目的管理增加成本,比如文件目录变更、资源名更改等
  推荐的方法:
    1. 使用direct reference: 用拖拽到脚本变量的方式
    2. 如果真的需要使用Resources.Load,请使用Resources.LoadAsync()
      该方法will not block execution
      在某些设备上,Loading会占用很长的时间

ResourceRequest request = Resources.LoadAsync("cube");

request.completed += operation => {
    ResourceRequest op = operation as ResourceRequest;
    Instantiate(op.asset);
};

Assets:

确保资源文件是小的:
  比如对于一个texture资源,可以在import进unity时减小分辨率
  但是这样做并不会减少import资源的时间,导致第一次initial setup工程的时间变得更久

使用压缩格式
  对image和audio文件进行压缩
  Image: 使用.png/ .tga/ .tiff/ 如果图形软件支持的话,也可以使用.dds
  audio: 使用.ogg

Assembly Definition Files:
  ADF compile all scripts in a folder and its subfolders into a separate DLL.
  只需重新编译修改过的脚本属于的dll,可以有效加快编译速度
  比如修改了有关Enemy的脚本,重新编译时只需要编译Enemy对应的dll即可

Scenes Structure:

Hierarchy depth and count:

Organization:

Dynamic Objects in Editor:

 

Game Design and Features:

Create cheat function:

Use small feature test scenes:

  

猜你喜欢

转载自www.cnblogs.com/FudgeBear/p/11141001.html